Exemple #1
0
def getTutors():
    # tutorID = request.form['tutor_id']
    studentID = request.form['student_id']
    transactions_iter = db.collection(u'transactions').where(
        'student_id', '==', studentID).stream()
    transactions = []
    for t in transactions_iter:
        tdict = t.to_dict()
        cdict = db.collection('courses').document(str(
            tdict['course_id'])).get().to_dict()
        sdict = db.collection('subjects').document(str(
            cdict['subject_id'])).get().to_dict()
        # student_dict = db.collection('users').document(str(tdict['student_id'])).get().to_dict()
        tutor_dict = db.collection('users').document(str(
            tdict['tutor_id'])).get().to_dict()

        tdict['transaction_id'] = t.id
        tdict['appointment'] = tdict['appointment'].astimezone(
            pytz.timezone('US/Pacific')).isoformat()
        cdict['subject'] = sdict
        tdict['course'] = cdict
        # tdict['student'] = student_dict
        tdict['tutor'] = tutor_dict
        # print(tdict)
        transactions.append(tdict)
    return {'transactions': transactions}
Exemple #2
0
def getAllCourses():
    courses_iter = db.collection(u'courses').stream()
    courses = []
    for c in courses_iter:
        cdict = c.to_dict()
        cdict['course_id'] = c.id
        cdict['subject'] = db.collection('subjects').document(
            str(cdict['subject_id'])).get().to_dict()
        courses.append(cdict)
    return {'courses': courses}
Exemple #3
0
def registerForTutor():
    transaction = {
        'appointment': datetime.fromisoformat(request.form['appointment']),
        'course_id': request.form['course_id'],
        'reason': '',
        'status': -1,
        'student_id': "-1",
        'tutor_id': request.form['tutor_id']
    }
    # print(transaction)
    db.collection('transactions').add(transaction)
    return {'success': True}
Exemple #4
0
def getAllStudents():
    transactions_iter = db.collection(u'transactions').stream()
    transactions = []
    for t in transactions_iter:
        tdict = t.to_dict()
        tdict['transaction_id'] = t.id
        tdict['student'] = db.collection('users').document(
            str(tdict['student_id'])).get().to_dict()
        tdict['appointment'] = tdict['appointment'].astimezone(
            pytz.timezone('US/Pacific')).isoformat()
        transactions.append(tdict)
    return {'transactions': transactions}
Exemple #5
0
def getAllUsers():
    user_iter = db.collection(u'users').stream()
    users = []
    for u in user_iter:
        udict = u.to_dict()
        udict['user_id'] = u.id
        users.append(udict)
    return {'users': users}
Exemple #6
0
def getUser():
    username = request.form['username']
    user_iter = db.collection('users').where('username', '==',
                                             username).stream()
    for u in user_iter:
        udict = u.to_dict()
        udict['user_id'] = u.id
        return udict
Exemple #7
0
def changeTrStatus():
    tid = request.form['transaction_id']
    status = int(request.form['status'])
    if 'reason' not in request.form:
        reason = 'None given'
    else:
        reason = request.form['reason']

    trans_ref = db.collection('transactions')
    tdict = trans_ref.document(tid).get().to_dict()
    student_dict = db.collection('users').document(
        tdict['student_id']).get().to_dict()
    tutor_dict = db.collection('users').document(
        tdict['tutor_id']).get().to_dict()
    course_dict = db.collection('courses').document(
        tdict['course_id']).get().to_dict()

    trans_ref.document(tid).set({
        'status': status,
        'reason': reason
    },
                                merge=True)

    tdict['status'] = -1
    tdict['reason'] = ''
    tdict['student_id'] = "-1"

    msg_body = ""
    if status == 1:
        msg_body = ''.join([
            "Congratulations, you have been accepted for the session held by ",
            tutor_dict['name'], " for ", course_dict['name'], " on ",
            tdict['appointment'].strftime("%b %d, %Y at %H:%M")
        ])
        send_msg(msg_body, student_dict['phone'])
    if status == 2:
        msg_body = ''.join([
            "Sorry, you were not selected for the session held by ",
            tutor_dict['name'], " for ", course_dict['name'], " on ",
            tdict['appointment'].strftime("%b %d, %Y at %H:%M"),
            ". Reason given: ", reason
        ])
        trans_ref.add(tdict)
        send_msg(msg_body, student_dict['phone'])

    return {'outcome': msg_body}
Exemple #8
0
def registerForCourse():
    data = json.loads(request.data)
    print(data)
    trans_ref = db.collection('transactions')
    for tid in data['transactions']:
        trans_ref.document(tid).set(
            {
                'status': 0,
                'student_id': data['student_id']
            }, merge=True)
    return {'success': True}
Exemple #9
0
def getAllSubjects():
    courses_iter = db.collection(u'courses').stream()
    subjects = []
    subject_dict = {}
    for c in courses_iter:
        cdict = c.to_dict()
        cdict['course_id'] = c.id

        if cdict['subject_id'] not in subject_dict:
            subject_dict[cdict['subject_id']] = []
        subject_dict[cdict['subject_id']].append(cdict)

    for sid, cdicts in subject_dict.items():
        sdict = db.collection('subjects').document(sid).get().to_dict()
        sdict['subject_id'] = sid
        sdict['courses'] = cdicts
        subjects.append(sdict)

    # print(subjects)
    return {'subjects': subjects}