Esempio n. 1
0
def assign_comprehensive_teams_view(request, spaceurl):
    space = Space.objects.get(url=spaceurl)
    preferences = Preferences.objects.filter(space=space)
    teams = list(Team.objects.filter(space=space))
    projects = Project.objects.filter(space=space)

    random.shuffle(teams)

    current_assignments = TeamProject.objects.filter(space=space)
    current_assignments.delete()

    for team in teams:
        team_rank = {}
        for project in projects:
            team_rank[project.name] = 0

        members = list(Member.objects.filter(teams=team))

        for member in members:
            if preferences.filter(member=member).exists():
                member_preferences = preferences.get(member=member,
                                                     space=space)
                member_rankings = member_preferences.project_preferences_as_names(
                )
                for project in member_rankings:
                    team_rank[project] = team_rank[project] + member_rankings[
                        project]

        max_value = -1
        max_project = ""
        for name in team_rank:
            test_project = Project.objects.get(name=name)
            if team_rank[name] > max_value and not TeamProject.objects.filter(
                    space=space, project=test_project):
                max_value = team_rank[name]
                max_project = name

        if Project.objects.filter(space=space, name=max_project).exists():
            team_project = Project.objects.get(name=max_project)
            new_project_team = TeamProject(space=space,
                                           team=team,
                                           project=team_project,
                                           assigned=True,
                                           representative=None)

        else:
            new_project_team = TeamProject(space=space,
                                           team=team,
                                           assigned=False,
                                           representative=None)

        new_project_team.save()

    return render(
        request, 'view_assignments.html', {
            'member': get_user(request),
            'list': TeamProject.objects.filter(space=space),
            'space': space,
            'teams': teams
        })
Esempio n. 2
0
def home_view(request):
    msg = ""
    if request.user.is_active:
        member = get_user(request)
    else:
        member = None
    return render(request, 'home.html', {'member': member, 'msg': msg})
Esempio n. 3
0
def delete_project_view(request, space_url, project_url):
    member = get_user(request)
    space = Space.objects.get(url=space_url)
    if space.teacher == member.username:
        project_name = project_url.replace('_', ' ')
        project = Project.objects.get(name=project_name, space=space)
        project.delete()
    return redirect("/space/" + space_url)
Esempio n. 4
0
def view_assignments(request, spaceurl):
    space = Space.objects.get(url=spaceurl)
    teams = Team.objects.filter(space=space)
    return render(
        request, 'view_assignments.html', {
            'member': get_user(request),
            'list': TeamProject.objects.filter(space=space),
            'space': space,
            'teams': teams
        })
Esempio n. 5
0
def compare_teams_view(request, space_url):
    space = Space.objects.get(url=space_url)
    member = get_user(request)
    if space.teacher != member.username:
        return redirect('/profile_redirect/')
    if request.method == 'POST':
        master_teams = MasterTeam.objects.filter(space=space)
        was_finalized = False
        finalized_team = None
        for master_team in master_teams:
            finalized_team_id = request.POST.get(str(master_team.id), False)
            if finalized_team_id:
                finalized_team = master_team
                was_finalized = True
        if was_finalized:
            for master_team in master_teams:
                if master_team != finalized_team:
                    master_team.delete()
            space.teams_decided = True
            space.save()

            # tell all the members about their new team
            master_teams = MasterTeam.objects.get(space=space)
            send_owner_spreadsheet(master_teams, space)
            participants = space.member_set.exclude(name='Account in Progress')
            for participant in participants:
                if member.teams.filter(space=space).exists():
                    team = member.teams.get(space=space)
                    subject = "You have been added to a Team in " + space.name
                    message = participant.name + ",\n\nCongratulations, you have been added to a team in " + space.name
                    message += ". Your team consists of " + str(team) + ". "
                    message += "\n\nBest,\nThe Team Formation Team"
                    sender_email = '*****@*****.**'
                    recipient_email = participant.email
                    send_mail(subject, message, sender_email,
                              [recipient_email])
                else:
                    subject = "You have been added to a Team in " + space.name
                    message = participant.name + ",\n\nCongratulations, you have been added to a team in " + space.name
                    message += ". Check out the team at https://vandy-tfx.herokuapp.com/" + participant.username + "/teams/"
                    message += "\n\nBest,\nThe Team Formation Team"
                    sender_email = '*****@*****.**'
                    recipient_email = participant.email
                    send_mail(subject, message, sender_email,
                              [recipient_email])

    master_teams = MasterTeam.objects.filter(space=space)
    return render(request, "choose_teams.html", {
        'member': member,
        'space': space,
        'master_teams': master_teams
    })
Esempio n. 6
0
def change_password_view(request, username):
    msg = ""
    if request.user.is_active:
        member = get_user(request)
        msg = "Your security code is " + str(member.security_code)
    error_msg = ""
    if not Member.objects.filter(username=username).exists():
        return redirect('/')

    if request.method == 'POST':
        security_code = int(request.POST['security_code'])
        password1 = request.POST['password1']
        password2 = request.POST['password2']
        member = Member.objects.get(username=username)
        if security_code == member.security_code:
            if password1 == password2:
                user = User.objects.get(username=username)
                user.set_password(password1)
                user.save()
                msg = "Your password has been changed."
            else:
                error_msg = "Passwords were not the same."
                form = ChangePasswordForm()
                return render(
                    request, "change_password.html", {
                        'form': form,
                        'error_msg': error_msg,
                        'member': member,
                        'msg': msg
                    })
        else:
            error_msg = "Invalid security code."
            form = ChangePasswordForm()
            return render(request, "change_password.html", {
                'form': form,
                'error_msg': error_msg,
                'member': member,
                'msg': msg
            })
        return render(request, "home.html", {'msg': msg})
    form = ChangePasswordForm()
    member = Member.objects.get(username=username)
    return render(request, "change_password.html", {
        'form': form,
        'error_msg': error_msg,
        'member': member,
        'msg': msg
    })
Esempio n. 7
0
def send_reminders_view(request, space_url):
    space = Space.objects.get(url=space_url)
    member = get_user(request)
    if member.username != space.teacher:
        return redirect('/profile_redirect/')
    emails = []
    non_registered_members = space.member_set.filter(
        name='Account in Progress')
    for non_registered_member in non_registered_members:
        receiver_email = non_registered_member.email
        send_new_space_email(member, space, receiver_email, False)
        emails.append(receiver_email)
    return render(request, 'send_reminders.html', {
        'member': member,
        'emails': emails,
        'space': space
    })
Esempio n. 8
0
def remove_member_view(request, space_url, username):
    space = Space.objects.get(url=space_url)
    member = get_user(request)
    removed_member = Member.objects.get(username=username)
    if member.username != space.teacher:
        return redirect("/space/" + space_url)
    if request.POST:
        removed_member.spaces.remove(space)
        if Preferences.objects.filter(member=removed_member,
                                      space=space).exists():
            preferences = Preferences.objects.get(member=removed_member,
                                                  space=space)
            preferences.delete()
        return redirect("/space/" + space_url)
    return render(request, 'remove_member.html', {
        'space': space,
        'member': member,
        'removed_member': removed_member
    })
Esempio n. 9
0
def all_teams_view(request, spaceurl):
    member = get_user(request)
    if Space.objects.filter(url=spaceurl).exists():
        space = Space.objects.get(url=spaceurl)
    else:
        return redirect('/profile_redirect/')
    if not member.owner:
        return redirect('/profile_redirect/')
    no_teams = not space.teams_decided
    if space.teams_decided:
        master_team = MasterTeam.objects.get(space=space)
        teams = Team.objects.filter(space=space, master=master_team)
    else:
        teams = None
    return render(request, "ViewTeams.html", {
        'member': member,
        'teams': teams,
        'noteams': no_teams,
        'space': space
    })
Esempio n. 10
0
def delete_space_view(request, spaceurl):
    msg = ""
    deleted = False
    member = get_user(request)
    space = Space.objects.get(url=spaceurl)
    if space.teacher != member.username:
        return redirect('/profile_redirect/')
    if request.method == 'POST':
        if space.teacher == member.username:
            space.delete()
            return redirect("/profile/" + member.username)
        else:
            msg = "You do not have the ability to delete this space"

    return render(request, "deletespace.html", {
        'msg': msg,
        'spaceurl': spaceurl,
        'member': member,
        'deleted': deleted
    })
Esempio n. 11
0
def space_view(request, url):
    msg = ""
    space = Space.objects.get(url=url)
    teamsformed = Team.objects.filter(space=space).exists()
    member = get_user(request)
    if member.spaces.filter(url=url).exists(
    ) or member.username == space.teacher:  # makes sure user is in the space
        projects = Project.objects.filter(space__url__exact=url)
        ordered_projects = projects.order_by('name')
        participants = space.member_set.exclude(name='Account in Progress')
        ordered_participants = participants.order_by('name')
        participants_prefs = []
        for participant in ordered_participants:
            if Preferences.objects.filter(member=participant,
                                          space=space).exists():
                preference = Preferences.objects.get(member=participant,
                                                     space=space)
                prefs = preference.preferences_as_names()
            else:
                prefs = "No partner preferences submitted"
            participants_prefs.append(prefs)

        non_registered_members = space.member_set.filter(
            name='Account in Progress')
        non_registered_members = non_registered_members.order_by('email')
        if request.method == 'POST':
            msg = "The password for this space is " + space.password
        zipped = zip(ordered_participants, participants_prefs)
        return render(
            request, 'space.html', {
                'projects': ordered_projects,
                'space': space,
                'member': member,
                'zipped_students': zipped,
                'msg': msg,
                'teamsformed': teamsformed,
                'non_registered_members': non_registered_members,
                'total_students': participants.count()
            })
    else:
        return redirect('/profile_redirect/')
Esempio n. 12
0
def teams_view(request, username):
    member = get_user(request)
    if member.owner:
        spaces = Space.objects.filter(teacher=member.username)
        return render(request, "ownerviewteams.html", {
            'member': member,
            'spaces': spaces
        })
    else:
        teams = []
        no_teams = True
        for space in member.spaces.all():
            if space.teams_decided:
                if member.teams.filter(space=space).exists():
                    team = member.teams.get(space=space)
                    teams.append(team)
                    no_teams = False
        return render(request, "ViewTeams.html", {
            'member': member,
            'teams': teams,
            'noteams': no_teams
        })
Esempio n. 13
0
def create_project_view(request, space_url):
    errormsg = ""
    member = get_user(request)
    owning_space = Space.objects.get(url=space_url)
    if member.username != owning_space.teacher:
        return redirect('/profile_redirect/')

    if request.method == 'POST':
        name = request.POST['Project']
        description = request.POST['Description']
        qualifications = request.POST['Qualifications']
        url = name.replace(' ', '_')
        if Project.objects.filter(name=name).exists():
            errormsg = "That project name has already been used."
            return render(request, 'createproject.html', {
                'member': member,
                'errormsg': errormsg
            })

        if len(url) > 30 or len(description) > 500 or len(
                qualifications) > 300:
            errormsg = "Too long. The project's name cannot be more than 30 characters"
            return render(request, 'createproject.html', {
                'member': member,
                'errormsg': errormsg
            })

        new_project = Project(name=name,
                              url=url,
                              description=description,
                              qualifications=qualifications,
                              space=owning_space)
        new_project.save()
        return redirect('/space/' + space_url)
    return render(request, 'createproject.html', {
        'member': member,
        'errormsg': errormsg
    })
Esempio n. 14
0
def form_teams_view(request, spaceurl):
    member = get_user(request)
    space = Space.objects.get(url=spaceurl)
    msg = ""
    user_preferences = ""
    if member.username != space.teacher:
        return redirect('/profile_redirect/')
    setup_data = ""
    if request.method == 'POST':
        group_size_raw = request.POST.get('Group_Options', None)
        iterative_soulmates_raw = '1'
        algorithm_index_raw = request.POST.get('optradio', None)
        alpha_raw = request.POST.get('alpha')
        alpha_adjusted = float(alpha_raw) * 1000000
        alpha_adjusted = int(alpha_adjusted)
        theta_raw = request.POST.get('theta')
        theta_adjusted = float(theta_raw) * 100
        theta_adjusted = int(theta_adjusted)
        members = space.member_set.exclude(name='Account in Progress')
        number_members = members.count()

        setup_data = str(number_members) + " " + group_size_raw + " " + iterative_soulmates_raw + " " \
                     + algorithm_index_raw + " " + str(alpha_adjusted) + " " + str(theta_adjusted)

        # get input in format to store in team model
        algorithm_index = int(algorithm_index_raw)
        iterative_soulmates = iterative_soulmates_raw == "1"
        group_size = int(group_size_raw)

        # Assigns each member a rank and sets up easy lookup between usernames and rankings
        rank_to_user_dict = {}
        user_to_rank_dict = {}
        random_array = random.sample(range(0, members.count()),
                                     members.count())
        count = 0
        for member in members:
            rank = random_array[count]
            rank_to_user_dict[rank] = member.username
            user_to_rank_dict[member.username] = rank
            count += 1

        # Gets member preferences ready for the java program
        user_preferences = ""
        for member in members:
            member_data = member.username + " " + str(
                user_to_rank_dict[member.username]) + " "
            wants_any_team = False
            if Preferences.objects.filter(member=member, space=space).exists():
                finished = False
                pref_data = ""
                preferences = Preferences.objects.get(member=member,
                                                      space=space)
                preferenceArray = preferences.members_ranking.split(' ')
                for preference in preferenceArray:
                    if preference == "@myself@":
                        finished = True
                    elif preferences == "@team@":
                        wants_any_team = True
                    if preference in user_to_rank_dict and not finished:
                        pref_data += str(user_to_rank_dict[preference]) + " "
                if wants_any_team:
                    pref_data = "team " + pref_data
                else:
                    pref_data = "alone " + pref_data
                member_data += " " + pref_data
            else:
                member_data += "alone "
            user_preferences += member_data

        # Runs the team formation algorithms by passing in setup data and preference data to the Java executable
        p = Popen([
            'java', '-jar', 'JavaCode/TeamFormationAlgorithms.jar', setup_data,
            user_preferences
        ],
                  stdout=PIPE,
                  stderr=STDOUT)

        # Adds teams to the database by parsing the console output of the Java executable
        master_team = MasterTeam(space=space,
                                 iterative_soulmates=iterative_soulmates,
                                 number_of_members=group_size,
                                 algorithm_index=algorithm_index)
        master_team.save()
        space.teams_decided = False
        space.save()

        for raw_line in p.stdout:
            line = raw_line.decode("utf-8")
            if line[0:2] == 'T:':
                teammates = line[3:]
                user_list = teammates.split(" ")
                team = Team(space=space, master=master_team)
                team.save()
                for username in user_list:
                    if Member.objects.filter(username=username).exists():
                        user = Member.objects.get(username=username)
                        user.teams.add(team)
                        user.save()
                team.save()
            if line[0:2] == 'S:':
                solo_names = line[3:]
                solo_list = solo_names.split(" ")
                for username in solo_list:
                    if not username == '':
                        user = Member.objects.get(username=username)
                        team = Team(space=space, master=master_team)
                        team.save()
                        user.teams.add(team)
        master_team.save()

        return redirect("/choose_teams/" + space.url + "/")

    return render(
        request, "TeamFormation.html", {
            'member': member,
            'msg': "\"" + setup_data + "\" \"" + user_preferences + "\""
        })
Esempio n. 15
0
def add_members_view(request, spaceurl):
    were_reg_adds = were_unreg_adds = were_dup_adds = False
    counter = 0
    non_registered_adds = []
    registered_adds = []
    already_added = []
    total_added = 0
    were_adds = False
    member = get_user(request)
    space = Space.objects.get(url=spaceurl)
    msg = ""
    if request.FILES and request.method == 'POST':
        were_adds = True
        file = request.FILES['csv_file']
        file_data = file.read().decode("utf-8")
        lines = file_data.split("\n")
        for i, entry in enumerate(lines):
            lines[i] = lines[i].replace('\r', '')
            if lines[i] == '':
                counter += 1
        lines = list(filter(None, lines))
        if counter == len(lines):
            msg = "Error, no file submitted."
            return render(request, "addmembers.html", {
                'space': space,
                'msg': msg,
                'member': member
            })
        for line_input in lines:
            email = line_input
            already_member = Member.objects.filter(
                email__iexact=email).exists()
            if already_member:
                already_invited_to_space = False
                added_member = Member.objects.get(email__iexact=email)
                if space.member_set.filter(email__iexact=email).exists():
                    already_invited_to_space = True
                    were_dup_adds = True
                    already_added.append(added_member.email)
                if not already_invited_to_space:
                    were_reg_adds = True
                    added_member.spaces.add(space)
                    added_member.save()
                    registered_adds.append(added_member.name)
                    #send_new_space_email(member, space, email, already_member)
            else:
                new_member = Member(email=email)
                new_member.save()
                new_member.spaces.add(space)
                new_member.save()
                non_registered_adds.append(new_member.email)
                were_unreg_adds = True
                #send_new_space_email(member, space, email, already_member)
        total_added = non_registered_adds.__len__() + registered_adds.__len__(
        ) + already_added.__len__()
    elif request.method == 'POST':
        email = request.POST['Email']
        if email == "":
            msg = "Error, no file submitted."
            return render(request, "addmembers.html", {
                'space': space,
                'msg': msg,
                'member': member
            })
        already_member = Member.objects.filter(email__iexact=email).exists()
        if already_member:
            already_invited_to_space = False
            added_member = Member.objects.get(email__iexact=email)
            if space.member_set.filter(email__iexact=email).exists():
                already_invited_to_space = True
            if not already_invited_to_space:
                added_member.spaces.add(space)
                added_member.save()
                msg = added_member.name + " has been successfully added to " + space.name \
                     + ". Enter another email to add another member to the space."
                #send_new_space_email(member, space, email, already_member)
        else:
            new_member = Member(email=email)
            new_member.save()
            new_member.spaces.add(space)
            new_member.save()
            msg = email + " has been successfully added to " + space.name \
                   + ". Enter another email to add another member to the space."
            #send_new_space_email(member, space, email, already_member)
    return render(
        request, "addmembers.html", {
            'space': space,
            'msg': msg,
            'member': member,
            'non_registered_adds': non_registered_adds,
            'registered_adds': registered_adds,
            'were_adds': were_adds,
            'total_added': total_added,
            'already_added': already_added,
            'ra': were_reg_adds,
            'ura': were_unreg_adds,
            'aa': were_dup_adds
        })
Esempio n. 16
0
def profile_redirect_view(request):
    member = get_user(request)
    string = '/profile/' + member.username
    return redirect(string)