Example #1
0
def mark_payment_status():
    if (request.method == 'POST'):
        data = request.form
        id = int(data['id'])
        student = StudentModel.query.filter_by(id=id).first()
        if (not student):
            return jsonify({'status': 0, 'message': 'Invalid ID'})
        printlog(f"Marking Paid : {student}")
        student.is_paid = True  #Marking Paid
        #Changing last paid to current date after payment (Used to mark 30days)
        student.utc_last_paid = datetime.datetime.utcnow()
        db.session.commit()
        return redirect(url_for('admin.mark_payment_status'))

    students = StudentModel.query.all()

    # Performing Bulk Operation to Cancell Subscription of People Who are OverDue (30+Days)
    #This is redundant as we already check it everytime the service is used from Flutter
    for s in students:
        if (s.utc_last_paid
                and (datetime.datetime.utcnow() - s.utc_last_paid).days > 30):
            s.is_paid = False
            printlog(f"{s} is OverDue. Cancelling Subscription")
            db.session.commit()

    #Get all the students who havent paid and arent expired
    students = [s for s in students if not s.is_paid and not s.is_lapsed]

    return render_template('markpaymentstatus.html',
                           title='Mark Payment Status',
                           students=students)
Example #2
0
def reallocate_student_id():
    if (request.method == 'POST'):
        data = request.form
        id = int(data['id'])
        student = StudentModel.query.filter_by(id=id).first()
        lapsed_instance = LapsedStudents.query.filter_by(sid=id).first()
        if (not student):
            return jsonify({'status': 0, 'message': 'Invalid Student ID'})
        if (not lapsed_instance):
            return jsonify({
                'status': 0,
                'message': 'Student ID has not lapsed 6 months'
            })
        printlog(f"Reallocating StudentID & Marking Paid for {student}")
        student.created_on = datetime.datetime.utcnow(
        )  #Change CreatedOn to Today
        student.is_paid = True  #Set IsPaid to True
        student.utc_last_paid = datetime.datetime.utcnow(
        )  #Set last Paid to Today
        student.student_id = generate_student_id(6)  #Generate a new Student ID
        db.session.delete(lapsed_instance)  #Remove LapsedStudent Instance
        db.session.commit()
        return redirect(url_for('admin.reallocate_student_id'))
    lapsed_students = [l.get_student for l in LapsedStudents.query.all()]
    return render_template('reallocate.html',
                           title='Reallocate Student ID',
                           lapsed_students=lapsed_students)
Example #3
0
def delete_drivers():
    if (request.method == 'POST'):
        data = request.form
        id = int(data['id'])
        driver = DriverModel.query.filter_by(id=id).first()
        if (not driver): return jsonify({'status': 0, 'message': 'Invalid ID'})
        printlog(f"Deleteing {driver}")
        db.session.delete(driver)
        db.session.commit()
        return redirect(url_for('admin.delete_drivers'))
    drivers = DriverModel.query.all()
    return render_template('delete_drivers.html',
                           title='Delete Drivers',
                           drivers=drivers)
Example #4
0
def verify_drivers():
    if (request.method == 'POST'):
        data = request.form
        driver = DriverModel.query.filter_by(id=int(data['id'])).first()
        if (not driver):
            return jsonify({'status': 0, 'message': 'No Driver with that ID'})
        driver.is_verified = True  #Verifying Drivers
        db.session.commit()
        printlog(f"Successfully Verified {driver}")
        return redirect(url_for('admin.verify_drivers'))
    drivers = [d for d in DriverModel.query.all() if not d.is_verified]
    return render_template('verify_drivers.html',
                           title='Verify Driver',
                           drivers=drivers)
Example #5
0
def delete_students():
    if (request.method == 'POST'):
        data = request.form
        id = int(data['id'])
        student = StudentModel.query.filter_by(id=id).first()
        if (not student):
            return jsonify({'status': 0, 'message': 'Invalid ID'})
        printlog(f"Deleteing {student}")
        db.session.delete(student)
        db.session.commit()
        return redirect(url_for('admin.delete_students'))
    students = StudentModel.query.all()
    return render_template('delete_students.html',
                           title='Delete Students',
                           students=students)
Example #6
0
def allow_student():
    data = request.get_json()
    sid = data['student_id']
    license_number = data['license_number']
    student = StudentModel.query.filter_by(student_id=sid).first()
    driver = DriverModel.query.filter_by(license_number=license_number).first()
    if (not verify_session_key(request, driver.phone)):
        printlog("session fault")
        return jsonify({'status': 0, 'message': 'SessionFault'})
    if (not driver):
        printlog("LicenseFault")
        return jsonify({'status': 0, 'message': 'Invalid License Number'})
    if (not student):
        printlog("Student IDFault")
        return jsonify({
            'status': 0,
            'message': 'Invalid Student Phone Number'
        })
    if (not student.is_paid):
        printlog("Student Not Paid")
        return jsonify({'status': 0, 'message': 'Student Has not Paid'})
    # printlog(f"DriverLocation: {driver.location}    ---->   StudentLocation: {student.location}")
    if (not student.location == driver.location):
        printlog("Locations dont match")
        return jsonify({'status': 0, 'message': 'Locations do not match'})
    journey = JourneyModel(driver=driver, student=student)
    db.session.add(journey)
    db.session.commit()
    printlog(f"{driver} Allowed {student}")
    return jsonify({'status': 200, 'message': 'OK'})