Exemplo n.º 1
0
def module_add():
    if request.method == 'POST':
        q = request.form['ques']
        a = request.form['ans']
        k = request.form['keywords']
        data = {"Q": q, "A": a, "K": k}
        db.child("Paper").push(data)
        return redirect(url_for('admin'))
    return render_template('new_module.html')
Exemplo n.º 2
0
def module_update(module_id):
    li = get_QnA(module_id)
    question = li[2]
    answer = li[0]
    keywords = li[1]
    if request.method == 'POST':
        q = request.form['ques']
        a = request.form['ans']
        k = request.form['keywords']
        db.child("Paper").child(module_id).update({"Q": q, "A": a, "K": k})
        return redirect(url_for('admin'))

    return render_template('new_module.html',
                           question=question,
                           answer=answer,
                           keywords=keywords)
Exemplo n.º 3
0
def get_keywords():  #getting all answers in a list
    keywords = []
    all_users = db.child("Paper").get()
    for user in all_users.each():
        keyword = user.val()
        for key, value in keyword.items():
            if key.startswith("K"):
                keywords.append(value)
    return keywords
Exemplo n.º 4
0
def get_answers():  #getting all answers in a list
    answers = []
    all_users = db.child("Paper").get()
    for user in all_users.each():
        answer = user.val()
        for key, value in answer.items():
            if key.startswith("A"):
                answers.append(value)
    return answers
Exemplo n.º 5
0
def get_questions():  #getting all questions in a list
    questions = []
    all_users = db.child("Paper").get()
    for user in all_users.each():
        question = user.val()
        for key, value in question.items():
            if key.startswith("Q"):
                questions.append(value)
    return questions
Exemplo n.º 6
0
def get_QnA(module_id):  #finding question and answer and keyword based on id
    qna = []
    all_users = db.child("Paper").get()
    for user in all_users.each():
        if user.key() == module_id:
            x = user.val()
            for key, value in x.items():
                if key.startswith("Q"):
                    qna.append(value)
                if key.startswith("A"):
                    qna.append(value)
                if key.startswith("K"):
                    qna.append(value)
    return qna
Exemplo n.º 7
0
def admin():
    token = session.get('token', None)
    if (token == 'wBrCxmN5qzZkoUI48eh2y9g3Hi83'):
        question = []
        question = get_questions()
        keys = []
        all_users = db.child("Paper").get()
        for user in all_users.each():
            key_of = user.key()
            keys.append(key_of)
        return render_template('admin.html',
                               title='admin',
                               question=question,
                               keys=keys)
    elif (not token):
        return redirect(url_for('login'))
    else:
        return redirect(url_for('exam'))
Exemplo n.º 8
0
def delete_module(module_id):
    if request.method == "POST":
        db.child("Paper").child(module_id).remove()
        return redirect(url_for('admin'))
Exemplo n.º 9
0
 def post(self):
     # args = parser.parse_args()
     # if request.headers['Content-Type'] == 'application/json':
         # print(request.json)
         db.child('donors').push(request.json)
         return request.json, 201
Exemplo n.º 10
0
 def get(self):
     donors = db.child('donors').get().val()
     data = [donors[i] for i in donors]
     # print(data)
     return data, 200