Back to index

freevial  1.2
Classes | Functions | Variables
questions Namespace Reference

Classes

class  LoadDatabase

Functions

def GetDatabase
def shuffle_databases
def get_databases

Variables

tuple parser = etree.XMLParser(remove_blank_text = True)
list alldatabases = []
tuple database_files = LoadDatabase(Global.database)
tuple cat = GetDatabase( num + 1, os.path.join(Global.database, database_files[num]) )

Function Documentation

def questions.get_databases (   database = None)

Definition at line 184 of file questions.py.

00184 
00185 def get_databases( database = None ):
00186        
00187        if database is not None:
00188               return alldatabases[database]
00189        else:
00190               return alldatabases

Here is the caller graph for this function:

def questions.GetDatabase (   num,
  xmlFile 
)
Returns a Database instance loaded with the questions from a XML file. 

Definition at line 110 of file questions.py.

00110 
00111 def GetDatabase( num, xmlFile ):
00112        """ Returns a Database instance loaded with the questions from a XML file. """
00113        
00114        root = etree.parse(xmlFile, parser).getroot()
00115        
00116        if float(root.get('version')) != 1.0:
00117               print >> sys.stderr, _('Warning: «%»: Database\'s version is %s, which is not supported by the installed version of Freevial. It might not work as expected.') % (xmlFile, root.get('version'))
00118        
00119        database = Database(
00120               num,
00121               root.information.name.text,
00122               root.get('language'),
00123               root.information.description.text,
00124               root.information.destination.text,
00125               ', '.join(["%s" % author.text.split(',')[0] for author in root.information.authors.getchildren()]),
00126               (int(root.information.timestamp_creation.text), int(root.information.timestamp_modification.text)),
00127               root.appearance.image.text,
00128               root.appearance.sound.text,
00129        )
00130        
00131        for question in root.questions.getchildren():
00132               
00133               if question.answers.countchildren() != 3:
00134                      print >> sys.stderr, _('Warning: «%»: Found question with an incorrect number of answers; ignoring it.') % xmlFile
00135                      continue
00136               
00137               answers = []
00138               has_correct_answer = False
00139               
00140               # Process answers
00141               for answer in question.answers.getchildren():
00142                      if answer.get('correct') is not None:
00143                             if has_correct_answer:
00144                                    print >> sys.stderr, _('Warning: «%»: Found question with two correct answers; ignoring it.') % xmlFile
00145                                    continue
00146                             answers.insert(0, answer.text)
00147                             has_correct_answer = True
00148                      else:
00149                             answers.append(answer.text)
00150               
00151               if not has_correct_answer:
00152                      print >> sys.stderr, _('Warning: «%»: Found question without any correct answer; ignoring it.') % xmlFile
00153                      continue
00154               
00155               if hasattr(question, 'comments') and question.comments.text is not None:
00156                      comment = question.comments.text
00157               else:
00158                      comment = u''
00159               
00160               database.addQuestion(
00161                      question = question.sentence.text,
00162                      answ1 = answers[0],
00163                      answ2 = answers[1],
00164                      answ3 = answers[2],
00165                      author = question.author.text,
00166                      comment = comment,
00167               )
00168        
00169        return database
00170 

Definition at line 181 of file questions.py.

00181 
00182 def shuffle_databases():
00183        random.shuffle(alldatabases)

Here is the caller graph for this function:


Variable Documentation

Definition at line 171 of file questions.py.

tuple questions.cat = GetDatabase( num + 1, os.path.join(Global.database, database_files[num]) )

Definition at line 176 of file questions.py.

tuple questions.database_files = LoadDatabase(Global.database)

Definition at line 172 of file questions.py.

tuple questions.parser = etree.XMLParser(remove_blank_text = True)

Definition at line 107 of file questions.py.