当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.flush方法代码示例

本文整理汇总了Python中quizsmith.app.models.DBSession.flush方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.flush方法的具体用法?Python DBSession.flush怎么用?Python DBSession.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在quizsmith.app.models.DBSession的用法示例。


在下文中一共展示了DBSession.flush方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: edit_home

# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import flush [as 别名]
    def edit_home(self):
        if 'form.submit' in self.request.params:
            for k,v in self.request.params.iteritems():
                if k.isdigit():
                    c = Categories.by(k).first()
                    c.position = v;
                    DBSession.flush()
            transaction.commit()
            self.notify('Changes saved!')
            return HTTPFound(location=self.request.application_url + '/edit')
        return self.template('/edit-home.pt', theme='AdminPanel')
        
        

        
        
        
        
        
        
        
        
        
        
        
开发者ID:polklibrary,项目名称:quizsmith,代码行数:13,代码来源:edit_landing.py

示例2: _generate_test

# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import flush [as 别名]
 def _generate_test(self):
     category = Categories.by(self.category_id).first()
     last_test = Tests.by({'category':category.name, 'alias':self.alias},sort='id desc').first()
     
     # Create New Test
     test = Tests(alias=self.alias, category=category.name, d2l_folder=category.d2l_folder, used_accessibility_view=self.used_accessibility_view)
     # Copy values at time of generation, this in case values change in the future, personal results aren't effected.
     test.wrong_answer_time_penalty = category.wrong_answer_time_penalty
     test.max_wrong_answer_allowed = category.max_wrong_answer_allowed
     test.question_time_allowed = category.question_time_allowed
     DBSession.add(test)
     DBSession.flush()
     
     # Get and Randomize Questions
     questionsets = QuestionSets.by({'category_id':self.category_id}).all()
     random.shuffle(questionsets) # randomize first to guarentee all questions
     questionsets = questionsets[0:category.playable_questions] # limit randomized
     
     # Setup Unfinished Questions
     for questionset in questionsets:
         question = self._get_question_variation(questionset, last_test)
         
         result = TestsResults(tests_id=test.id, 
                               question_sets_id=questionset.id, 
                               question=question,
                               answer_choices=TestManager.get_answers(questionset.id)
                               )
         DBSession.add(result)
         
     
     # okay below
     DBSession.flush()
     user = Users.by({'alias':self.alias}).first()
     user.current_test = test.id
     transaction.commit()
开发者ID:hietpasd,项目名称:quizsmith,代码行数:37,代码来源:test.py

示例3: edit_question

# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import flush [as 别名]
 def edit_question(self):
     self.response['category'] = self.request.matchdict['category']
     Categories.by(self.response['category'], user=self.request.user, permission=ACL.EDIT, strict=True).first() # security
     question = self.request.matchdict['id']
     self.response['option'] = question
     
     if question == 'new':
         if 'form.submit' in self.request.params or 'form.submit.next' in self.request.params:
             qs = QuestionSets(category_id=int(self.response['category']))
             DBSession.add(qs)
             DBSession.flush()
             qs = QuestionSets.by(None, sort='id desc').first()
             id = qs.id
             self._transaction(qs, self.request.params)
             if 'form.submit.next' in self.request.params:
                 return HTTPFound(location=self.request.application_url + self.request.path)
             return HTTPFound(location=self.request.application_url + self.request.path + '/../' + str(id))
     else:
         qs = QuestionSets.by(question).first()
         q = Questions.by({'question_sets_id':qs.id}).all()
         wa = Answers.by({'question_sets_id':qs.id,'is_correct':False}, sort='position asc').all()
         ca = Answers.by({'question_sets_id':qs.id,'is_correct':True}).first()
         self.response['question_sets'] = qs
         self.response['questions'] = q
         self.response['wrong_answers'] = wa
         self.response['correct_answer'] = ca
         if 'form.submit' in self.request.params or 'form.submit.next' in self.request.params:
             self.notify('Changes saved!')
             self._transaction(qs, self.request.params)
             if 'form.submit.next' in self.request.params:
                 return HTTPFound(location=self.request.application_url + self.request.path + '/../new')
             return HTTPFound(location=self.request.application_url + self.request.path)
     
     return self.template('/edit-question.pt', theme='AdminPanel')
开发者ID:polklibrary,项目名称:quizsmith,代码行数:36,代码来源:edit_question.py

示例4: tearDown

# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import flush [as 别名]
 def tearDown(self):
     user = Users.by({'email':'[email protected]'}).first()
     DBSession.delete(user)
     DBSession.flush()
     DBSession.execute("ALTER TABLE users AUTO_INCREMENT = " + str(self.auto_increment_reset) + ";")
     transaction.commit()
     super(NoGroupPermissionTests,self).tearDown()
开发者ID:hietpasd,项目名称:quizsmith,代码行数:9,代码来源:testing.py

示例5: edit_delete

# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import flush [as 别名]
 def edit_delete(self):
     id = self.request.matchdict['id']
     classname = str(self.request.matchdict['type'])
     back = self.request.params.get('back',None)
     if back == None or not back.startswith(self.request.application_url):
         return HTTPFound(location=self.request.application_url) 
     
     type = Import('quizsmith.app.models',str(classname))
     obj = DBSession.query(type).filter(type.id==id).first()
     if obj:
         DBSession.delete(obj)
         DBSession.flush()
     
     transaction.commit() # make it so number one
     return HTTPFound(location=self.request.params['back'])
开发者ID:hietpasd,项目名称:quizsmith,代码行数:17,代码来源:edit_delete.py

示例6: _transaction

# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import flush [as 别名]
    def _transaction(self, question_set, fields):
         
        for key,v in fields.iteritems():
            if Validate.sanatize(v) != '':
               
                parts = key.split('_')
            
                if parts[0] == 'answerhelp':
                    question_set.answer_help = v

                if parts[0] == 'correctanswer' and not key.endswith('_index'):
                    if parts[1] == 'old':
                        a = Answers.by(parts[2]).first()
                        a.answer = v
                        a.position=fields[key + '_index']
                    else:
                        a = Answers(question_sets_id=question_set.id, answer=v, is_correct=True, position=fields[key + '_index'])
                        DBSession.add(a)
                
                if parts[0] == 'wronganswer' and not key.endswith('_index'):
                    if parts[1] == 'old':
                        a = Answers.by(parts[2]).first()
                        a.answer = v
                        a.position = fields[key + '_index']
                    else:
                        a = Answers(question_sets_id=question_set.id, answer=v, is_correct=False, position=fields[key + '_index'])
                        DBSession.add(a)
                        
                if parts[0] == 'question':
                    if parts[1] == 'old':
                        a = Questions.by(parts[2]).first()
                        a.question = v
                    else:
                        a = Questions(question=v, question_sets_id=question_set.id)
                        DBSession.add(a)
        
            DBSession.flush()
        transaction.commit()
        
        
        
        
        
        
        
        
        
        
开发者ID:polklibrary,项目名称:quizsmith,代码行数:40,代码来源:edit_question.py

示例7: _test_calculator

# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import flush [as 别名]
 def _test_calculator(self,test,results,result):
     percentage = TestManager.score_percentage(result.correctly_answered,
                                                 result.wrong_attempts,
                                                 test.max_wrong_answer_allowed,
                                                 len(results),
                                                 result.duration,
                                                 test.question_time_allowed
                                                 )
     competitive = TestManager.score_competitive(result.correctly_answered,
                                                 result.wrong_attempts,
                                                 test.max_wrong_answer_allowed,
                                                 len(results),
                                                 result.duration,
                                                 test.question_time_allowed
                                                 )
     
     test.total_percentage += percentage
     test.base_competitive += competitive['score']
     test.bonus_competitive += competitive['bonus']
     test.total_competitive += competitive['combined']
     test.time_remaining += result.duration
     test.time_spent += (test.question_time_allowed - result.duration)
     DBSession.flush()
     return { 'competitive': competitive, 'percentage': percentage }
开发者ID:hietpasd,项目名称:quizsmith,代码行数:26,代码来源:playing.py

示例8: import_category

# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import flush [as 别名]
 def import_category(self):        
 
     if 'form.submit' in self.request.params:
         content = self.request.params.get('form.import')
         data = self._import_zip(content)
         if not data:
             self.response['message'] = 'This export was made for a different version of this application.\
                                         You can rename the .zip filename to match your systems version, however this will most likely result in consequences and is not recommended.'
         else:
             category  = data['category']
             new_category = Categories(name=category['name'],
                        category_intro=category['category_intro'],
                        playable_questions=category['playable_questions'],
                        wrong_answer_time_penalty=category['wrong_answer_time_penalty'],
                        max_wrong_answer_allowed=category['max_wrong_answer_allowed'],
                        question_time_allowed=category['question_time_allowed'],
                        transition_in=category['transition_in'],
                        transition_out=category['transition_out'],
                        )
             
             new_category.set_groups([],[str(group.id) for group in Groups.by({'edit':True}).all()],[str(group.id) for group in Groups.by({'review':True}).all()]) #anyone with group edit permission are allowed to edit.
             DBSession.add(new_category)
             DBSession.flush()
             
             for qs in data['question_sets']:
                 new_qs = QuestionSets(category_id=new_category.id,
                                       answer_help=qs['answer_help']
                                      )
                 DBSession.add(new_qs)
                 DBSession.flush()
                 for q in qs['questions']:
                     new_q = Questions(question_sets_id=new_qs.id,
                                       question=q['question']
                                       ) 
                     DBSession.add(new_q)
                 for a in qs['answers']:
                     new_a = Answers(question_sets_id=new_qs.id,
                                     answer=a['answer'],
                                     position=a['position'],
                                     is_correct = a['is_correct']
                                     ) 
                     DBSession.add(new_a)
             DBSession.flush()
             transaction.commit()
             self.response['message'] = 'Imported!'
             self.response['message_class'] = 'info'
         
     return self.template('/import-category.pt', theme='AdminPanel')
开发者ID:hietpasd,项目名称:quizsmith,代码行数:50,代码来源:import_export.py

示例9: import_category

# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import flush [as 别名]
 def import_category(self):        
 
     if 'form.submit' in self.request.params:
         content = self.request.params.get('form.import')
         data = self._import_zip(content)
         if not data:
             self.notify('This export was made for a different version of this application.',warn=True)
         else:
             category  = data['category']
             new_category = Categories(name=category['name'],
                        category_intro=category['category_intro'],
                        playable_questions=category['playable_questions'],
                        wrong_answer_time_penalty=category['wrong_answer_time_penalty'],
                        max_wrong_answer_allowed=category['max_wrong_answer_allowed'],
                        question_time_allowed=category['question_time_allowed'],
                        transition_in=category['transition_in'],
                        transition_out=category['transition_out'],
                        )
             
             new_category.set_groups([],[str(group.id) for group in Groups.by({'edit':True}).all()],[str(group.id) for group in Groups.by({'review':True}).all()]) #anyone with group edit permission are allowed to edit.
             DBSession.add(new_category)
             DBSession.flush()
             
             for qs in data['question_sets']:
                 new_qs = QuestionSets(category_id=new_category.id,
                                       answer_help=qs['answer_help']
                                      )
                 DBSession.add(new_qs)
                 DBSession.flush()
                 for q in qs['questions']:
                     new_q = Questions(question_sets_id=new_qs.id,
                                       question=q['question']
                                       ) 
                     DBSession.add(new_q)
                 for a in qs['answers']:
                     new_a = Answers(question_sets_id=new_qs.id,
                                     answer=a['answer'],
                                     position=a['position'],
                                     is_correct = a['is_correct']
                                     ) 
                     DBSession.add(new_a)
             DBSession.flush()
             transaction.commit()
             self.notify('Successfully imported!')
         
     return self.template('/import-category.pt', theme='AdminPanel')
开发者ID:polklibrary,项目名称:quizsmith,代码行数:48,代码来源:import_export.py

示例10: add_groups

# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import flush [as 别名]
 def add_groups(cls, user, groups):
     id = user.id
     user.groups = list(set( (user.groups + groups) ))
     DBSession.flush()
     transaction.commit()
     return Users.by(id).first()
开发者ID:hietpasd,项目名称:quizsmith,代码行数:8,代码来源:users.py

示例11: login_updates

# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import flush [as 别名]
 def login_updates(cls, user):
     id = user.id
     user.last_active = datetime.datetime.now() # update last login
     DBSession.flush()
     transaction.commit()
     return Users.by(id).first()
开发者ID:hietpasd,项目名称:quizsmith,代码行数:8,代码来源:users.py

示例12: edit_category

# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import flush [as 别名]
    def edit_category(self):
        category_id = self.request.matchdict['category']
        self.response['category_id'] = category_id
        self.response['version'] = Addons.get_version('QuizSmith Core')
        self.response['d2l_on'] = Validate.bool(self.settings('d2l_on'))
        
        if 'form.submit' in self.request.params or 'form.submit.questions' in self.request.params:
            active = None
            if category_id == 'add':
                active = Categories(name='New Category')
                editors = []
                for group in self.request.user.get_groups():
                    editors.append(str(group.id))
                reviewers = []
                for group in self.request.user.get_groups():
                    reviewers.append(str(group.id))
                active.set_groups([], editors, reviewers)
                DBSession.add(active)
                DBSession.flush()
                category_id = str(active.id)
            else:
                active = Categories.by(category_id, sort='position asc', user=self.request.user, permission=ACL.EDIT).first()
            
            active.name = self.request.params.get('category.name','')
            active.category_intro = self.request.params.get('category.intro','')
            active.playable_questions = self.request.params.get('category.playable_questions',10)
            active.wrong_answer_time_penalty = self.request.params.get('category.wrong_answer_time_penalty',5)
            active.max_wrong_answer_allowed = self.request.params.get('category.max_wrong_answer_allowed',2)
            active.question_time_allowed = self.request.params.get('category.question_time_allowed',30)
            active.transition_in = self.request.params.get('category.transition_in','Random')
            active.transition_out = self.request.params.get('category.transition_out','Random')
            active.d2l_folder = self.request.params.get('category.d2l_folder','')
            
            assesment_data = []
            for key,v in self.request.params.iteritems():
                if key.startswith('assessment'):
                    field_data = key.split('.')
                    row = {}
                    if not any(a['id'] == field_data[-1] for a in assesment_data):
                        assesment_data.append(row)
                    else:
                        row = filter(lambda x: x['id'] == field_data[-1], assesment_data)[0]
                    row['id'] = field_data[-1]
                    if v.isdigit():
                        row[field_data[1]] = int(v)
                    else:  
                        row[field_data[1]] = str(v)
            active.set_assessments(assesment_data)
            
            editors = []
            if  self.request.params.getall('category.editable'):
                editors = self.request.params.getall('category.editable')
            else:
                for g in active.groups:
                    if g.edit:
                        editors.append(str(g.groups_id))
                        
            reviewers = []
            if  self.request.params.getall('category.reviewable'):
                reviewers = self.request.params.getall('category.reviewable')
            else:
                for g in active.groups:
                    if g.edit:
                        editors.append(str(g.groups_id))
            
            active.set_groups(self.request.params.getall('category.playable'), editors, reviewers)
            DBSession.flush()
            transaction.commit()
            self.notify('Changes saved!')
            if 'form.submit.questions' in self.request.params:
                return HTTPFound(location=self.request.application_url + '/edit/category/' + category_id + '/questions')
            return HTTPFound(location=self.request.application_url + '/edit/category/' + category_id)
        elif category_id == 'add':
            self.response['active_category'] = Categories(name='New Category')
        else:
            self.response['active_category'] = Categories.by(category_id, sort='position asc', user=self.request.user, permission=ACL.EDIT, strict=True).first()

        self.response['transitions_in'] = self.response['active_category'].transition_in
        self.response['transitions_out'] = self.response['active_category'].transition_out
        self.response['transitions'] = Transitions.all()
        
        
        self.response['questions'] = QuestionSets.by({'category_id':category_id}).count()
        self.response['all_edit_groups'] = Groups.by({'edit':True}).all()
        self.response['all_play_groups'] = Groups.by({'play':True}).all()
        self.response['all_review_groups'] = Groups.by({'review':True}).all()
        self.response['play_groups'] =  []
        self.response['edit_groups'] =  []
        self.response['review_groups'] =  []
        
        if self.response['active_category'].groups:
            for categorygroup in self.response['active_category'].groups:
                group = Groups.by(categorygroup.groups_id).first()
                if categorygroup.edit:
                    self.response['edit_groups'].append(group.name) 
                if categorygroup.play:
                    self.response['play_groups'].append(group.name) 
                if categorygroup.review:
                    self.response['review_groups'].append(group.name) 
            
#.........这里部分代码省略.........
开发者ID:polklibrary,项目名称:quizsmith,代码行数:103,代码来源:edit_category.py


注:本文中的quizsmith.app.models.DBSession.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。