コード例 #1
0
ファイル: app.py プロジェクト: shreyansb/massivelyoffline
def post_sole(course_id):
    """Create a new sole.
    """
    # authenticate the user
    user, err = auth.get_user_from_request(db, request)
    if err:
        return json_error(err)

    # validate and format the POST data
    user_id = str(user.get('id'))
    data = json.loads(request.data)
    s = Sole.format_params_for_create(user_id, data)
    err = Sole.validate_params_for_create(s)
    if err:
        return json_error(err)

    # create the sole
    sole_id = Sole.create_new_sole(db, s)

    # format response
    s = Sole.find_by_id(db, sole_id)
    ss = User.update_sole_with_students(db, s)

    # enqueue an email to be sent to the creator
    resq.enqueue(EmailCreator, str(sole_id))

    return json.dumps(ss)
コード例 #2
0
ファイル: app.py プロジェクト: shreyansb/massivelyoffline
def get_home():
    loc = geo.loc_from_ip(get_ip())
    user, err = auth.get_user_from_request(db, request)
    formatted_user = User.filter_user_attrs(user)
    params = {
        'loc': json.dumps(loc),
        'user': json.dumps(formatted_user),
        'times': json.dumps(possible_sole_times),
        'stage': settings.STAGE
    }
    return render_template("index.html", **params)
コード例 #3
0
ファイル: app.py プロジェクト: shreyansb/massivelyoffline
def patch_sole(course_id, sole_id):
    """ Join or leave a sole
    """
    user, err = auth.get_user_from_request(db, request)

    if not user:
        return json_error("User not found")

    sole = Sole.find_by_id(db, sole_id)
    if not sole:
        return json_error("that study group doesn't exist")

    # if the new set of student ids makes sense, use them
    data = json.loads(request.data)
    current_sids = sole.get(Sole.A_STUDENT_IDS)
    new_sids = data.get(Sole.A_STUDENT_IDS)
    user_id = user.get('id')
    resp = None
    action = None
    if (set(current_sids) - set(new_sids)) == set([user_id]):
        resp = Sole.leave_sole_by_id(db, sole_id, user_id)
        action = 'left'
    elif (set(new_sids) - set(current_sids)) == set([user_id]):
        resp = Sole.join_sole_by_id(db, sole_id, user_id)
        action = 'joined'
    else:
        return json_error("Invalid new student_ids")

    # return the new model
    if resp:
        s = Sole.find_by_id(db, sole_id)
        ns = User.update_sole_with_students(db, s)
        resq.enqueue(EmailGroup, action, sole_id, user_id)
        return json.dumps(ns)
    else:
        return json_error("Some other error")