Esempio n. 1
0
def university_rankings_page():
    global scored
    if request.method == 'GET':
        from database import universitiesTable, universityPhotosTable
        universities_table = universitiesTable()
        theListOfUniversityTuples = universities_table.getUniversitiesAndScoresOrderedByScore(
        )
        university_photos_table = universityPhotosTable()
        photo_exists_list = university_photos_table.fetchAllPhotos(
            theListOfUniversityTuples)
        university_names = universities_table.getUniversityNames()

        oldScored = scored
        scored = False
        return render_template('pages/university_rankings.html',
                               theList=theListOfUniversityTuples,
                               university_names=university_names,
                               photo_exists_list=photo_exists_list,
                               scored=oldScored)

    else:
        from database import universitiesTable
        universities_table = universitiesTable()
        scored = universities_table.addScore(request.form)
        return redirect(url_for('university_rankings'))
Esempio n. 2
0
def upload_university_photo_page():
    if request.method == 'GET':
        from database import universitiesTable
        universities_table = universitiesTable()
        university_names = universities_table.getUniversityNames()
        return render_template('pages/upload_university_photo.html',
                               university_names=university_names)
    elif request.method == 'POST' and 'photo' in request.files:
        from database import universitiesTable
        universities_table = universitiesTable()
        universities_table.uploadAndSetPhoto(request.files, request.form)
        return redirect(url_for('upload_university_photo'))
Esempio n. 3
0
def profile_page():
    if request.method == 'GET':

        from database import universitiesTable, clubsTable, usersTable
        users_table = usersTable()
        users_table.getAvatar(current_user.id)
        universities_table = universitiesTable()
        clubs_table = clubsTable()
        university_names = universities_table.getUniversityNames()
        club_names = clubs_table.getClubNames()
        return render_template('pages/profile.html',
                               university_names=university_names,
                               club_names=club_names)

    else:
        if 'editProfileInfoForm' in request.form:
            form_result_map = request.form.to_dict()
            from database import usersTable
            users_table = usersTable()
            changes_are_made = users_table.editUserProfileInfo(form_result_map)
            #return render_template('pages/profile.html', profile_edited=changes_are_made)
        elif 'changeProfilePhotoForm' in request.form and 'photo' in request.files:
            from database import usersTable
            users_table = usersTable()
            avatar_changed = users_table.changeAvatar(request.files)
            #return render_template('pages/profile.html', avatar_changed=avatar_changed)
        elif 'addEventForm' in request.form:
            from database import eventsTable
            events_table = eventsTable()
            event_added = events_table.addEvent(request.form)
            #return render_template('pages/profile.html', event_added=event_added)
        return redirect(url_for('profile'))
Esempio n. 4
0
def register_page():

    if request.method == 'GET':
        from database import universitiesTable
        universities_table = universitiesTable()
        university_names = universities_table.getUniversityNames()
        return render_template("pages/register.html",
                               university_names=university_names)
    else:
        from form import formValidation
        form_validation = formValidation()

        form_result_map = request.form.to_dict()
        email = form_result_map['email']
        email_validation_result = form_validation.validateEmail(email)
        #if not email_validation_result:
        #return "Email should be in the form of '*****@*****.**'"

        from database import usersTable
        users_table = usersTable()
        #to get the form result as a whole (best approach) (form names are unknown)
        form_result_map = request.form.to_dict()
        users_table.addUser(form_result_map)
        global after_registration
        after_registration = True
        if current_user.is_authenticated():
            return redirect(url_for("index"))
        else:
            return redirect(url_for("login"))
Esempio n. 5
0
def clubs_page(club_id=None):
    if request.method == 'GET':
        if club_id == None:
            from database import clubsTable
            clubs_table = clubsTable()
            clubs_tuple = clubs_table.getAllClubs()

            from database import universitiesTable
            universities_table = universitiesTable()
            university_tuple = universities_table.getAllUniversityNamesAndIds()
            return render_template('pages/clubs.html',
                                   clubs=clubs_tuple,
                                   universities=university_tuple)

        else:
            from database import clubsTable
            clubs_table = clubsTable()
            club = clubs_table.getClubById(club_id)

            from database import eventsTable
            events_table = eventsTable()
            events_tuple = events_table.getEventsByClubId(club_id)

            from database import commentsTable
            comments_table = commentsTable()

            list_of_comment_tuples = []

            for each_event in events_tuple:
                comments_tuple = comments_table.getCommentsByEventId(
                    each_event[0])
                list_of_comment_tuples.append(comments_tuple)

            return render_template('pages/club_single.html',
                                   club=club,
                                   events=events_tuple,
                                   comments=list_of_comment_tuples)
    else:
        if (club_id):
            if 'addEventForm' in request.form:
                form_result_map = request.form.to_dict()
                from database import eventsTable
                events_table = eventsTable()
                events_table.addEventByClubId(form_result_map, club_id)
            elif 'commentForm' in request.form:
                form_result_map = request.form.to_dict()
                if form_result_map['eventScore'] != 'None':
                    from database import eventsTable
                    events_table = eventsTable()
                    events_table.addScore(form_result_map)
                if form_result_map['commentBody']:
                    from database import commentsTable
                    comments_table = commentsTable()
                    comments_table.addComment(form_result_map)
        elif 'upvote' in request.form:
            form_result_map = request.form.to_dict()
            from database import commentsTable
            comments_table = commentsTable()
            comment_id = form_result_map['commentId']
            comments_table.updateUpvote(comment_id)
        elif 'downvote' in request.form:
            form_result_map = request.form.to_dict()
            from database import commentsTable
            comments_table = commentsTable()
            comment_id = form_result_map['commentId']
            comments_table.updateDownvote(comment_id)
        elif 'deleteComment' in request.form:
            form_result_map = request.form.to_dict()
            from database import commentsTable
            comments_table = commentsTable()
            comment_id = form_result_map['commentId']
            comments_table.deleteCommentById(comment_id)

        return redirect(url_for('clubs'))