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


Python Test.query方法代码示例

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


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

示例1: get

# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import query [as 别名]
    def get(self, in_test_id=None):
        template_values = get_template_values( self )
        user = users.get_current_user()
        try:
            entity = Entity.query( Entity.id == user.user_id() ).get()
            if not entity.display_name: # It's only slightly possible to have a user with no display_name
                self.redirect('/login')
        except:
            self.redirect('/login')
        else:
            test_query = Test.query( ancestor = ndb.Key('Entity', user.user_id() ) )
            if len(test_query.fetch()) > 0:
                if in_test_id:
                    in_query = test_query.filter( Test.id == in_test_id ).fetch(1)
                    try: # The test exists
                        template_values = add_test_to_template( template_values, in_query[0] )
                    except IndexError: # The test does not exist
                        self.redirect("/")

            potential_groups = set(
                itertools.chain( entity.test_groups, default_groups )
            )
            print potential_groups
            grouped_marks = get_grouped_marks( entity.id )

            # Add groups with levels for level dropdown
            template_values['user_levels'] = json.dumps( grouped_marks )

            # Add list of groups for group dropdown
            template_values['user_groups'] = []
            for group in grouped_marks:
                group_test_query = Test.query( Test.group == group['group'] ).order(-Test.level).fetch()
                try:
                    threshold = group_test_query[0]
                except:
                    threshold = 0
                print threshold
                for mark in grouped_marks:
                    potential_groups = potential_groups - set(group['group'])
                    if mark['group'] == group and mark["level"] >= threshold:
                        template_values['user_groups'].append( group )
            for group in potential_groups:
                template_values['user_groups'].append( group )

            if template_values["user_groups"] == []:
                template_values['error'] = "You may only create a test in a new category."

            path = os.path.join( os.path.dirname(__file__), os.path.join( template_dir, 'create.html' ) )
            self.response.out.write( template.render( path, template_values ))
        return
开发者ID:pierce403,项目名称:densando,代码行数:52,代码来源:views.py

示例2: post

# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import query [as 别名]
    def post( self, in_test_id ):
        path = urlparse.urlsplit(self.request.referrer).path
        author_id = self.request.get("author_id")
        test_id = self.request.get("test_id")
        mark_id = self.request.get("mark_id")
        address = self.request.get("mark_address")
        comment = self.request.get("comment")
        mark = self.request.get("mark")

        author_entity = Entity.query( Entity.id == author_id ).get()
        test_entity = Test.query( Test.id == test_id ).get()
        mark_entity = Mark.query( ancestor = ndb.Key("Entity", mark_id) )
        mark_entity = mark_entity.filter( Mark.test.id == test_id ).get()

        mark_entity.marker_entity = author_entity
        mark_entity.test = test_entity
        mark_entity.comment = comment
        mark_entity.mark = int(mark)
        test_entity.total_score += mark_entity.mark
        test_entity.num_marked += 1
        mark_entity.modified = datetime.datetime.now()
        mark_entity.complete = True
        mark_entity.put()
        send_email( address, test_entity, "Answer-Response")
        test_entity.put()
        self.redirect( path )
        return
开发者ID:pierce403,项目名称:densando,代码行数:29,代码来源:views.py

示例3: get_tests

# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import query [as 别名]
def get_tests( num=None, start_cursor=None, ancestor_key=None, open=None ):
    """Retrieves the num most recent tests, starting at start_cursor, and only for the ancestor if provided"""
    if ancestor_key:
        # This checks for only tests created by this entity
        test_query = Test.query( ancestor = ancestor_key ).order( -Test.created )
    else:
        test_query = Test.query().order( -Test.created )
    if open is not None:
        # filter open or closed tests as needed
        test_query = test_query.filter( Test.open == open )
    if start_cursor:
        # Set the query start to the cursor location if provided
        tests, next_cursor, more = test_query.fetch_page(num, start_cursor=start_cursor)
        try:
            return { 'tests':tests, 'next':next_cursor.urlsafe(), 'more':more }
        except:
            return { 'tests':tests, 'next':None, 'more':False }
    elif num:
        # Otherwise return the number of requested results
        return test_query.fetch( num )
    # Or all if no num was specified
    return test_query.fetch()
开发者ID:pierce403,项目名称:densando,代码行数:24,代码来源:helpers.py

示例4: add_mark_to_template

# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import query [as 别名]
def add_mark_to_template( template_values, in_mark ):
    """Combines Mark object properties into template_values"""
    template_values = add_entity_to_template( template_values, in_mark.marker_entity )
    # the updated_test value is required here or else the Test that is returned is the Test taken, not the current test
    updated_test = Test.query( Test.id == in_mark.test.id ).fetch(1)[0]
    template_values = add_test_to_template( template_values, updated_test )
    template_values['complete'] = in_mark.complete
    template_values['response'] = in_mark.response
    template_values['comment'] = in_mark.comment
    template_values['mark'] = in_mark.mark
    template_values['mark_id'] = in_mark.id
    template_values['mark_created'] = in_mark.created
    template_values['mark_modified'] = in_mark.modified
    template_values['rating'] = in_mark.rating
    template_values['rated'] = in_mark.rated
    return template_values
开发者ID:pierce403,项目名称:densando,代码行数:18,代码来源:helpers.py

示例5: save_average_rating

# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import query [as 别名]
def save_average_rating( test_id, avg ):
    test = Test.query( Test.id == test_id ).fetch(1)[0]
    test.average_rating = avg
    test.put()
    # Add/Alter this test's Document in the search index
    doc = search.Document( doc_id = test.id, fields = [
        search.AtomField( name="group", value=test.group ),
        search.TextField( name="title", value=test.title ),
        search.NumberField( name="times_taken", value=test.times_taken ),
        search.DateField( name="date", value=test.created ),
        search.NumberField( name="level", value=test.level ),
        search.NumberField( name="rating", value=test.average_rating ),
    ])
    try:
        index = search.Index(name="tests")
        index.put( doc )
    except search.Error:
        logging.warning("Average rating failed to properly update.")
    return
开发者ID:pierce403,项目名称:densando,代码行数:21,代码来源:helpers.py

示例6: list_tests

# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import query [as 别名]
def list_tests():
    """List examples"""
    tests = Test.query(Test.added_by == session['email']).order(-Test.timestamp)
    form = TestForm()
    return render_template('list_tests.html', tests=tests, form=form)
开发者ID:nbcesar,项目名称:sabered,代码行数:7,代码来源:views.py

示例7: cached_tests

# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import query [as 别名]
def cached_tests():
    """This view should be cached for 60 sec"""
    tests = Test.query()
    return render_template('list_tests_cached.html', tests=tests)
开发者ID:nbcesar,项目名称:sabered,代码行数:6,代码来源:views.py


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