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


Python utls.display_tables函数代码示例

本文整理汇总了Python中utls.display_tables函数的典型用法代码示例。如果您正苦于以下问题:Python display_tables函数的具体用法?Python display_tables怎么用?Python display_tables使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: get

    def get(self, qzid):
        """Get result for taker of this  quiz"""
        logs.debug_ ("_________________________________________________")
        logs.debug_ ("UsrQuizRtAPI get fn: %s" %(request))

        userid, username = utls.get_user_from_hdr()
        if 'username' not in session:
            response = handle_invalid_usage(InvalidUsageException
                        ('Error: No active session for this user found', 
                         status_code=404))
            return response

        # Find quiz result for session
        query_obj = models.User.query.filter_by(userid=userid).first()
        result = query_obj.qzscore

        # Return response
        logs.debug_ ("Json response")
        logs.debug_ ("=============\n")
        logs.debug_ ("{\'result\':%s}\n" %(result))
        response = jsonify (result=result)
        response.status_code = 200
        utls.display_tables()
        logs.info_(response)
        return response
开发者ID:archanabahuguna,项目名称:quizngn,代码行数:25,代码来源:views.py

示例2: patch

    def patch(self, qzid):
        '''Edit quiz details'''
        print "_________________________________________________"
        print "QuizAPI patch fn: %s \nJson Request\n=============\n %s" %(request, request.json) 

        '''Get values from req'''
        args = self.reqparse.parse_args()
        cols = {}
        no_data = True
        for key, value in args.iteritems():
            if value != None:
                no_data = False
                cols[key] = request.json[key]

        '''If no input in patch request, return 400'''
        if no_data:
            response = handle_invalid_usage(InvalidUsage('Error: No input data provided in Patch req',status_code=400))
            return response

        '''Update tables'''
        qzdb.Quiz.query.filter_by(qzid = qzid).update(cols)
        qzdb.db.session.commit()

        '''Return response'''
        Query_obj = qzdb.Quiz.query.filter_by(qzid=qzid).all()
        resp_fields = ['qzid','title', 'difficulty_level', 'text','no_ques']
        relnshp_flag = 0
        quiz = utls.serialize_to_json(resp_fields, Query_obj, relnshp_flag)
        print "Json response"
        print "=============\n"
        print '{\'quiz\':%s\n}' %(quiz)
        response = jsonify(quiz=quiz)
        response.status_code = 200
        utls.display_tables()
        return response
开发者ID:lchircus,项目名称:projects,代码行数:35,代码来源:rstflapi.py

示例3: get

    def get(self, qzid, qid):
        '''Get question qid for quiz'''
        print "_________________________________________________"
        print "QuestionAPI get fn: %s" %(request)

        '''Query Question table'''
        Query_obj = qzdb.Question.query.join(qzdb.Anschoice).filter(qzdb.Question.qid == qid,qzdb.Question.qzid == qzid).all()
        if not Query_obj:
            response = handle_invalid_usage(InvalidUsage('Error: Question not found',status_code=404))
            return response

        '''Return response'''
        response_fields = [{'name':'qid',  'relnshp':False, 'subfields':None}, 
                           {'name':'ques_text',  'relnshp':False, 'subfields':None}, 
                           {'name':'ans_text','relnshp':False, 'subfields':None},  
                           {'name':'qzid','relnshp':False, 'subfields':None},  
                           {'name':'anschoices','relnshp':True, 
                               'subfields':[{'name':'ans_choice','relnshp':False,'subfields':None},
                                            {'name':'correct', 'relnshp':False, 'subfields':None}]} 
                          ] 
        question = utls.serialize_to_json(response_fields, Query_obj)
        print "Json response"
        print "=============\n"
        print '{\'question\':%s}\n' %(question)
        response = jsonify(question = question)
        response.status_code = 200
        utls.display_tables()
        return response
开发者ID:annapy,项目名称:projects,代码行数:28,代码来源:rstflapi.py

示例4: login

def login():

    # POST
    if request.method == 'POST':
        error = None
        """Post """
        logs.debug_ ("_______________________________________________")
        logs.debug_ ("login get fn: %s" %(request))

        username = request.form["username"]
        pwd = request.form["password"]
        encrypted_pwd = bcrypt.generate_password_hash(pwd)

        user_obj=models.User.query.filter_by(username=username).all()

        if (not user_obj):
            user_obj = models.User(username,bcrypt.\
                                          generate_password_hash(pwd))
            models.db.session.add(user_obj)
            models.db.session.commit()

        # Create Flask session
        if 'username' not in session:
            session['username'] = username

        # Return response
        utls.display_tables()
        location = "/quizzes"
        response = make_response(render_template('login.html', error=error),
                                 303)
        response.location=location
        return response
开发者ID:archanabahuguna,项目名称:qzwebapp,代码行数:32,代码来源:views.py

示例5: db_init

def db_init():
    db.drop_all()
    db.create_all()

    qz1 = Quiz( "Python Basics  ", "Simple  ", "Explanation", 2)
    qz2 = Quiz( "Python Advanced", "Moderate", "No text    ")
    db.session.add(qz1)
    db.session.add(qz2)
    db.session.commit()

    ques1 = Question("What does 'def foo(): pass do", 
                      "A fn which does nothing",1)
    ques2 = Question("Is python an OOP l           ", 
                      "Yes python is an OOP l",1)
    db.session.add(ques1)
    db.session.add(ques2)
    db.session.commit()

    ans1  = Anschoice(1, 1, "a. This function does nothing      ", True)
    ans2  = Anschoice(1, 1, "b. This function returns a fn pass ", False)
    ans3  = Anschoice(1, 1, "c. This function is not yet defined", False)
    ans4  = Anschoice(1, 2, "a. Yes Python is object oriented   ", True)
    ans5  = Anschoice(1, 2, "b. No Python is not object oriented", False)
    ans6  = Anschoice(1, 2, "c. Python may not be used as OOP l ", True)
    db.session.add(ans1)
    db.session.add(ans2)
    db.session.add(ans3)
    db.session.add(ans4)
    db.session.add(ans5)
    db.session.add(ans6)
    db.session.commit()

    utls.display_tables()

    return None
开发者ID:annapy,项目名称:projects,代码行数:35,代码来源:qzdb.py

示例6: db_init

def db_init():
    db.drop_all()
    db.create_all()

    qz1 = Quiz( "Python Basics", "Simple", "This quiz tests you on various fundamentals", 2)
    qz2 = Quiz( "Python Advanced", "Moderate", "No text")
    db.session.add(qz1)
    db.session.add(qz2)
    db.session.commit()

    ques1 = Question("What does the following code do? def foo(): pass", 
                      "You can define a function in python which does nothing",1)
    ques2 = Question("Is python an Object oriented programming language?", 
                      "Yes python is an OOP language",1)
    db.session.add(ques1)
    db.session.add(ques2)
    db.session.commit()

    ans1  = Anschoice(1, 1, "a. This function does nothing", True)
    ans2  = Anschoice(1, 1, "b. This function returns a function called pass", False)
    ans3  = Anschoice(1, 1, "c. This function is not yet defined. It will give error", False)
    ans4  = Anschoice(1, 2, "a. Yes Python is object oriented", True)
    ans5  = Anschoice(1, 2, "b. No Python is not object oriented", False)
    ans6  = Anschoice(1, 2, "c. Python may or may not be used as an object oriented language", True)
    db.session.add(ans1)
    db.session.add(ans2)
    db.session.add(ans3)
    db.session.add(ans4)
    db.session.add(ans5)
    db.session.add(ans6)
    db.session.commit()

    utls.display_tables()

    return None
开发者ID:lchircus,项目名称:projects,代码行数:35,代码来源:qzdb.py

示例7: quiz_result

def quiz_result(qzid, userid):

    # GET /user/quizzes/{qzid}/result
    if ((request.method == 'GET') or (request.method == 'POST')):
        error = None
        """Get result for taker of this  quiz"""
        logs.debug_ ("_________________________________________________")
        logs.debug_ ("UsrQuizRtAPI get fn: %s" %(request))

        # get user id for user - in this case just create default?
        userid = 1
        qzid = 1

        # Find quiz result for session
        query_obj = models.User.query.filter_by(userid=userid).first()
        score = query_obj.qzscore
        utls.display_tables()

        # Return response
        location = "/quizzes/%d/%d/result" % (qzid , userid)
        response = make_response(render_template('result.html', 
                                                 userid=userid,
                                                 qzid=qzid,
                                                 score=score,
                                                 error=error),
                                                 200)
        response.location=location
        return response
开发者ID:lchircus,项目名称:projects,代码行数:28,代码来源:views.py

示例8: api

def api():

    # GET /
    if request.method == 'GET':
        app.logger.info(request)
        err=""
        utls.display_tables()
        return render_template('api.html',err=err)
开发者ID:archanabahuguna,项目名称:orm,代码行数:8,代码来源:views.py

示例9: patch

    def patch(self, qzid):
        """Edit quiz details"""
        logs.debug_ ("_________________________________________________")
        logs.debug_ ("QuizAPI patch fn: %s \nJson Request\n=============\n %s" 
                 %(request, request.json)) 
        userid, username = utls.get_user_from_hdr()
        if 'username' not in session:
            response = handle_invalid_usage(InvalidUsageException
                       ('Error: No active session for this user found', 
                        status_code=404))
            
            return response

        # Get values from req
        args = self.reqparse.parse_args()
        cols = {}
        no_data = True
        for key, value in args.iteritems():
            if value is not None:
                no_data = False
                cols[key] = request.json[key]

        # Check if user is auth to update this quiz
        query_obj = models.Quiz.query.filter_by(qzid=qzid).first()
        if  (query_obj.userid != userid):
            response = handle_invalid_usage(InvalidUsageException
                        ('Error: Unauthorized Username for this quiz', \
                         status_code=401))
            
            return response

        # If no input in patch request, return 400
        if no_data:
            response = handle_invalid_usage(InvalidUsageException
                        ('Error: No input data provided in Patch req', 
                         status_code=400))
            return response

        # Update tables
        models.Quiz.query.filter_by(qzid=qzid).update(cols)
        models.db.session.commit()

        # Return response
        query_obj = models.Quiz.query.filter_by(qzid=qzid).all()
        resource_fields =  {'qzid':fields.Integer, 
                           'title':fields.String,
                           'difficulty_level':fields.String,
                           'text':fields.String,
                           'no_ques':fields.Integer
                          }
                            
        quiz = marshal(query_obj, resource_fields)
        response = jsonify(quiz=quiz)
        response.status_code = 200
        logs.info_(response)
        utls.display_tables()
        return response
开发者ID:archanabahuguna,项目名称:quizngn,代码行数:57,代码来源:views.py

示例10: post

    def post(self, qzid):
        '''Add question to quiz'''
        print "_________________________________________________"
        print "QuestionsAPI post fn: %s \nJson Request\n=============\n %s" %(request, request.json)

        '''Get data from req'''
        args = self.reqparse.parse_args()
        for key, value in args.iteritems():
            if value != None:
                if (key == 'ques_text'):
                    ques_text = request.json['ques_text']
                if (key == 'ans_text'):
                    ans_text = request.json['ans_text']
                if (key == 'anschoices'):
                    anschoices = request.json['anschoices']

        '''Post new data to table'''
        qn_obj = qzdb.Question(ques_text, ans_text, qzid)
        qzdb.db.session.add(qn_obj)

        '''Update correspnoding relationship tables '''
        #Quiz table
        L = qzdb.Quiz.query.filter_by(qzid = qzid).first()
        qzdb.Quiz.query.filter_by(qzid = qzid).update(dict(no_ques= (L.no_ques+1)))

        #Ans choices table 
        ansidL = []
        for i in range(len(anschoices)):
            ans_obj = qzdb.Anschoice(qzid,
                                     qn_obj.qid,
                                     anschoices[i]["answer"], 
                                     anschoices[i]["correct"]
                                    )
            qzdb.db.session.add(ans_obj)
        qzdb.db.session.commit()

        '''Return response'''
        location = "/api/quizzes/"+str(qzid)+"/questions/"+str(qn_obj.qid)
        Query_obj = qzdb.Question.query.join(qzdb.Anschoice).filter(qzdb.Question.qid == qn_obj.qid).all()
        response_fields = [{'name':'ques_text',  'relnshp':False, 'subfields':None}, 
                           {'name':'ans_text','relnshp':False, 'subfields':None},  
                           {'name':'qzid','relnshp':False, 'subfields':None},  
                           {'name':'anschoices','relnshp':True, 
                               'subfields':[{'name':'ans_choice','relnshp':False,'subfields':None},
                                            {'name':'correct', 'relnshp':False, 'subfields':None}]} 
                          ] 
        question = utls.serialize_to_json(response_fields, Query_obj, 0)

        print "Json response"
        print "=============\n"
        print '{\'question\':%s}\n' %(question)
        response = jsonify(question = question)
        response.location = location
        response.status_code = 201
        utls.display_tables()
        return response
开发者ID:annapy,项目名称:projects,代码行数:56,代码来源:rstflapi.py

示例11: users

def users():

    # GET
    if request.method == 'GET':
        app.logger.info(request)
        err=""

        user_obj = models.User.query.all()
        if not user_obj:
            err="No user"

        utls.display_tables()
        response = render_template('list_of_users.html',
                                   user_obj=user_obj,
                                   err=err
                                   )
        return response

    # POST
    if request.method == 'POST':
        app.logger.info(request)
        err=""
        username = request.form["username"]
        email = request.form["email"]
        address = request.form["address"]
        podcast1 = request.form["podcast1"]
        podcast2 = request.form["podcast2"]
        podcast3 = request.form["podcast3"]

        user_obj = models.User.query.filter_by(username=username).all()
        if (not user_obj):
            user_obj = models.User(username,email,address)
            models.db.session.add(user_obj)

            query_obj = models.User.query.filter_by(username=username).first()
            userid = query_obj.userid
            if (podcast1):
                pod_obj1 = models.Podcast(podcast1,userid)
                models.db.session.add(pod_obj1)
            if (podcast2):
                pod_obj2 = models.Podcast(podcast2, userid)
                models.db.session.add(pod_obj2)
            if (podcast3):
                pod_obj3 = models.Podcast(podcast3, userid)
                models.db.session.add(pod_obj3)
            models.db.session.commit()

        else:
            err = "User already exists"

        utls.display_tables()
        response = render_template('api.html', 
                                   user_obj=user_obj, 
                                   err=err)
        return response
开发者ID:archanabahuguna,项目名称:orm,代码行数:55,代码来源:views.py

示例12: patch

    def patch(self, qzid, qid):
        '''Add question to quiz'''
        print "_________________________________________________"
        print "QuestionAPI patch fn: %s \nJson Request\n=============\n %s" %(request, request.json)

        '''Check if question qid exists for qzid, raise error'''
        Query_obj = qzdb.Question.query.filter(qzdb.Question.qid == qid,qzdb.Question.qzid == qzid).all()
        if not Query_obj:
            response = handle_invalid_usage(InvalidUsage('Error: Question to edit not found for quiz',status_code=400))
            return response

        args = self.reqparse.parse_args()
        for key, value in args.iteritems():
            if value != None:
                if (key == 'ques_text'):
                    ques_text = request.json['ques_text']
                if (key == 'ans_text'):
                    ans_text = request.json['ans_text']
                if (key == 'anschoices'):
                    anschoices = request.json['anschoices']

        '''Update all table entries with input data'''
        qzdb.Question.query.filter_by(qid = qid).update(dict(ques_text=ques_text, ans_text=ans_text))

        '''Updating correspnoding relationship tables '''
        #Ans choices table 
        Q_obj = qzdb.Anschoice.query.filter_by(qid = qid)
        index = 0
        for i in Q_obj:
            ansid = Q_obj[index].ansid
            ans_choice = anschoices[index]["answer"]
            correct    = anschoices[index]["correct"]
            qzdb.Anschoice.query.filter_by(ansid = ansid).update(dict(ans_choice = ans_choice, correct = correct))  
            index += 1
        qzdb.db.session.commit()

        '''Return response'''
        Query_obj = qzdb.Question.query.join(qzdb.Anschoice).filter(qzdb.Question.qid == qid).all()
        response_fields = [{'name':'qid',  'relnshp':False, 'subfields':None}, 
                           {'name':'ques_text',  'relnshp':False, 'subfields':None}, 
                           {'name':'ans_text','relnshp':False, 'subfields':None},  
                           {'name':'qzid','relnshp':False, 'subfields':None},  
                           {'name':'anschoices','relnshp':True, 
                               'subfields':[{'name':'ans_choice','relnshp':False,'subfields':None},
                                            {'name':'correct', 'relnshp':False, 'subfields':None}]} 
                          ] 
        question = utls.serialize_to_json(response_fields, Query_obj)
        print "Json response"
        print "=============\n"
        print '{\'question\':%s\n}' %(question)
        response = jsonify(question=question)
        response.status_code = 200
        utls.display_tables()
        return response
开发者ID:annapy,项目名称:projects,代码行数:54,代码来源:rstflapi.py

示例13: logout

def logout():

    # GET /
    error = None
    logs.debug_ ("_______________________________________________")
    logs.debug_ ("QuizzesAPI post fn: %s" %(request))

    session.pop('username',None)

    # Return response
    utls.display_tables()
    return render_template('logout.html', error=error)
开发者ID:archanabahuguna,项目名称:qzwebapp,代码行数:12,代码来源:views.py

示例14: index

def index():

    # GET /
    if request.method == 'GET':
        error = None
        """Get index.html"""
        logs.debug_ ("_______________________________________________")
        logs.debug_ ("index.html get fn: %s" %(request))

        # Return response
        utls.display_tables()
        return render_template('login.html', error=error)
开发者ID:archanabahuguna,项目名称:qzwebapp,代码行数:12,代码来源:views.py

示例15: delete

    def delete(self):
        """Delete session"""
        logs.debug_ ("_________________________________________________")
        logs.debug_ ("SessionAPI del fn: %s" %(request.url))

        # Pop user from session
        userid, username = utls.get_user_from_hdr()
        if 'username' not in session:
            logs.debug_("User already not in session")
        else:
            session.pop('username', None)

        # Return response
        utls.display_tables()
        return 204
开发者ID:archanabahuguna,项目名称:quizngn,代码行数:15,代码来源:views.py


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