Beispiel #1
0
def notification():
    error = None
    if request.method == "GET":  # check whether there is upcoming events
        gtID = session['username']
        events = get_notification(db_handler, gtID)
        key_pairs = {}
        for row in db_handler.get_all_records(db_handler.user_tb):
            key_pairs[row[0]] = row[1:]
        user = key_pairs[long(gtID)]
        pendingEvents = []
        for e in events:
            minutes = calculateTimeLeft(e)
            if minutes < 120:
                pushNotification(user, e, minutes)
                delete_notification(db_handler, e[0], gtID)
                d = {
                    'ActivityId': e[0],
                    'Name': e[1],
                    'CreatorId': e[2],
                    'Location': e[3],
                    'Date': str(e[4]),
                    'Time': e[5],
                    'LeftTime': minutes
                }
                pendingEvents.append(d)
        if len(pendingEvents) > 0:
            return jsonify(events=pendingEvents)
        return "OK"
    elif request.method == "POST":  # subscribe an event
        activityID = request.json['activityID']
        gtID = session['username']

        # some input checking
        if len(gtID) == 0:
            return "Not authorized", 403
        try:
            int(gtID)
        except:
            return "Bad request", 400
        add_notification(db_handler, gtID, activityID)
        return "OK"
Beispiel #2
0
def notification():
    error = None
    if request.method == "GET": # check whether there is upcoming events
        gtID = session['username']
        events = get_notification(db_handler, gtID)
        key_pairs = {}
        for row in db_handler.get_all_records(db_handler.user_tb):
            key_pairs[row[0]] = row[1:]
        user = key_pairs[long(gtID)]
        pendingEvents = []
        for e in events:
            minutes = calculateTimeLeft(e)
            if minutes < 120:
                pushNotification(user, e, minutes)
                delete_notification(db_handler, e[0], gtID)
                d = {
                    'ActivityId': e[0],
                    'Name': e[1],
                    'CreatorId': e[2],
                    'Location': e[3],
                    'Date': str(e[4]),
                    'Time': e[5],
                    'LeftTime': minutes
                }
                pendingEvents.append(d)
        if len(pendingEvents) > 0:
            return jsonify(events=pendingEvents)
        return "OK"
    elif request.method == "POST": # subscribe an event
        activityID = request.json['activityID']
        gtID = session['username']

        # some input checking
        if len(gtID) == 0:
            return "Not authorized", 403
        try:
            int(gtID)
        except:
            return "Bad request", 400
        add_notification(db_handler, gtID, activityID)
        return "OK"
Beispiel #3
0
def profile():
    if not session.has_key('user'):
        return redirect(url_for('about'))
    username=session['user']
    name=database.get_name(username)
    osis=database.get_osis(username)
    digits=database.get_id(username)
    email=database.get_email(username)
    schedule=database.get_schedule(username)
    notif=database.get_notification(username)
    if request.method=='GET':        
        return render_template("profile.html"
                               ,name=name
                               ,osis=osis
                               ,digits=digits
                               ,schedule=schedule
                               ,email=email
                               ,accept=notif["accept"]
                               ,accepted=notif["accepted"]
                               )
    elif request.method=="POST":
        value=request.form["button"]
        value=value.split(" ")
        index=int(value[1])-1
        if str(value[0])=="drop":
            schedule=database.get_schedule(username)
            clas=schedule[index]
            if not (clas[1]=="free" or clas[1]=="Cafe"):
                database.drop_period(username,clas[0])
                schedule=database.get_schedule(username)
        return render_template("profile.html"
                               ,name=name
                               ,osis=osis
                               ,digits=digits
                               ,schedule=schedule
                               ,email=email
                               ,accept=notif["accept"]
                               ,accepted=notif["accepted"]
                               )
Beispiel #4
0
def visit(username=""):
    if not session.has_key('user'):
        return redirect(url_for('about'))
    me=session['user']
    if str(username)==str(me):
        return redirect(url_for('profile'))
    name=database.get_name(username)
    osis=database.get_osis(username)
    digits=database.get_id(username)
    email=database.get_email(username)
    schedule=database.get_schedule(username)
    notif=database.get_notification(username)
    if request.method=='GET':        
        return render_template("visit.html"
                               ,name=name
                               ,osis=osis
                               ,digits=digits
                               ,schedule=schedule
                               ,email=email
                               ,accept=notif["accept"]
                               ,accepted=notif["accepted"]
                               )