Ejemplo n.º 1
0
def add_linkedin(student):
    try:
        url = request.get_json()["url"]
    except KeyError:
        return APIErrorValue('Invalid url').json(500)

    if not student.linkedin_url:
        StudentsHandler.add_points(student, int(Config.REWARD_LINKEDIN))
    StudentsHandler.update_student(student, linkedin_url=url)

    return StudentsValue(student, details=True).json(200)
Ejemplo n.º 2
0
def today_login(student):
    now = datetime.utcnow()
    date = now.strftime('%d %b %Y, %a')
    event = EventsFinder.get_default_event()
    dates = EventsHandler.get_event_dates(event)

    if date in dates:
        student_login = StudentsFinder.get_student_login(student, date)
        if student_login is None:
            StudentsHandler.add_student_login(student, date)
            StudentsHandler.add_points(student, int(Config.REWARD_LOGIN))
        else:
            return APIErrorValue("Already loggedin today").json(409)
    else:
        return APIErrorValue("Date out of event").json(409)

    return StudentsValue(student, details=True).json(200)
Ejemplo n.º 3
0
def add_cv(student):
    if 'cv' not in request.files:
        return APIErrorValue('No cv found').json(500)

    file = request.files['cv']
    if file.filename == '':
        return APIErrorValue('No cv found').json(500)

    if file and FileHandler.allowed_file(file.filename):
        filename = 'cv-' + student.user.username + '.pdf'

        if not FileHandler.upload_file(file, filename):
            return APIErrorValue('Error uploading file').json(500)

        if not student.uploaded_cv:
            StudentsHandler.update_student(student, uploaded_cv=True)
            StudentsHandler.add_points(student, int(Config.REWARD_CV))

    else:
        return APIErrorValue('Wrong file extension').json(500)

    return StudentsValue(student, details=True).json(200)
Ejemplo n.º 4
0
    def redeem_activity_code(cls, student, code):
        activity_code = ActivityCodesFinder.get_from_code(code)
        if (activity_code is None):
            return "Code not found", student

        if (activity_code.activity in student.activities):
            return "Already participated", student

        ActivitiesHandler.add_student_activity(student, activity_code.activity)

        now = datetime.utcnow()
        today = now.strftime('%d %b %Y, %a')
        if activity_code.activity.day != today:
            return "Code expired", student

        points = activity_code.activity.points

        if activity_code.activity.activity_type.name not in [
                "Speaker", "Discussion Panel", "Ceremony"
        ]:
            cls.delete_activity_code(activity_code)

        return None, StudentsHandler.add_points(student, points)