Beispiel #1
0
def change_name(request, course_slug, group_slug):
    "Change the group's name"
    course = get_object_or_404(CourseOffering, slug=course_slug)
    group = get_object_or_404(Group, courseoffering=course, slug=group_slug)
    oldname = group.name  #used for log information
    if request.method == "POST":
        groupForm = GroupNameForm(request.POST, instance=group)
        if groupForm.is_valid():
            groupForm.save()
            #LOG EVENT#
            l = LogEntry(
                userid=request.user.username,
                description="changed name of group %s to %s for course %s." %
                (oldname, group.name, group.courseoffering),
                related_object=group)
            l.save()
            return HttpResponseRedirect(
                reverse('offering:groups:view_group',
                        kwargs={
                            'course_slug': course_slug,
                            'group_slug': group.slug
                        }))

    else:
        groupForm = GroupNameForm(instance=group)

    return render(request, "groups/change_name.html", \
                                  {'groupForm': groupForm, 'course': course, 'group': group})
Beispiel #2
0
def change_name(request, course_slug, group_slug):
    "Change the group's name"
    course = get_object_or_404(CourseOffering, slug=course_slug)
    group = get_object_or_404(Group, courseoffering=course, slug=group_slug)
    oldname = group.name #used for log information
    if request.method == "POST":
        groupForm = GroupNameForm(request.POST, instance=group)
        if groupForm.is_valid():
            groupForm.save()
            #LOG EVENT#
            l = LogEntry(userid=request.user.username,
            description="changed name of group %s to %s for course %s." % (oldname, group.name, group.courseoffering),
            related_object=group)
            l.save()
            return HttpResponseRedirect(reverse('offering:groups:view_group', kwargs={'course_slug': course_slug, 'group_slug': group.slug}))

    else:
        groupForm = GroupNameForm(instance=group)

    return render(request, "groups/change_name.html", \
                                  {'groupForm': groupForm, 'course': course, 'group': group})
Beispiel #3
0
def createGroup(request):
    # Gets the persons friends
    friends = baseFriendQuery(request)

    # Makes the group name form so it can set the title late if one is submitted
    group_name = GroupNameForm()

    # the message variable for the info to the user
    messages = ""

    # If there is a form that  is submitted
    if request.method == "POST":
        # Gets all the info from the request
        name = GroupNameForm(request.POST)
        members = GroupMemberFrom(request.POST.getlist('selectedFriends'))

        # Sets the name of the name field to what the user submitted
        group_name.fillData(str(request.POST.get('name')))

        # checks the the user doesn't have any same named groups that cloud cause a problem
        if name.checkForSameName(request.user.id, ''):

            # Cleans ut all the users username form the submitted form
            # Checks that it's a friend of yours
            # Returns False if there is any problem
            selectedFriends = members.myClean(friends.values('username'))

            # If everything is ok if will create the group and add all of the members
            if selectedFriends:
                group = Friendgroup(groupname=name.cleaned_data['name'], owner=request.user)
                group.save()
                for member in selectedFriends:
                    Groupmembers(friendgroup=group, member=User.objects.get(username=member)).save()

                # Then take you to the group
                return redirect('seeGroup', day=0, group_name=str(request.POST.get('name')))

            else:
                # If pepole have not selected any friends
                messages = ['No friends!', ["You have not selected any friends"]]
        else:
            # If the user already have a group with that name
            messages = ['Sorry!', ['You already have a group with that name']]

    # If you have no friends you will be redirected to my friends
    # Where there is more info for how to get friends
    if len(friends) == 0:
        return redirect('listfriends')

    # Makes the friend form
    Group_member_from = GroupMemberFrom()
    Group_member_from.fillData(friends)

    tohtml = {
        'changeNameForm': group_name,
        'MembersForm': Group_member_from,
        'title': 'Create group',
        'submitText': 'Create the group',
        'messagesToUser': messages
    }

    return render(request, 'groupsComponents/changeGroups.html', tohtml)
Beispiel #4
0
def removeGroupMember(request, group_name):
    # Gets all of the persons friends that are not in the group
    friends = baseQuery(request).filter(id__in=[
        i.member.id for i in Groupmembers.objects.filter(
            friendgroup_id=Friendgroup.objects.get(
                Q(owner_id=request.user.id) &
                Q(groupname=group_name)
            ).id
        )
    ])

    # Creates the group name form and sets the value of the input field to what the name is now
    group_name_form = GroupNameForm()
    group_name_form.fillData(str(group_name))

    # Sets the title of the page
    messages = ['Remember!', ["If you remove all group members", "the group will get deleted!"]]
    title = 'Remove friends'

    # if a form is submitted
    if request.method == "POST":
        # Makes the forms with the data submitted form the form
        name = GroupNameForm(request.POST)

        # NEEDS TO BE getlist so that all members that are selected will be added
        members = GroupMemberFrom(request.POST.getlist('selectedFriends'))

        # Sets the value of the input field to what the new name is
        new_group_name = str(request.POST.get('name'))
        group_name_form.fillData(new_group_name)

        # checks the the user doesn't have any same named groups that cloud cause a problem
        if name.checkForSameName(request.user.id, group_name):

            group = Friendgroup.objects.get(Q(groupname=group_name) & Q(owner=request.user))
            group.groupname = new_group_name
            group.save()

            # Cleans ut all the users usernames form the submitted form
            # Checks that they are friends
            # Returns False if there is any problem
            selectedFriends = members.myClean(friends.values('username'))

            # If there are no friends selected it will just return you to the groups schedule
            if not selectedFriends:
                return redirect('seeGroup', day=0, group_name=new_group_name)

            # If everything is okej if will creat the group
            if len(selectedFriends) < len(friends):
                for member in selectedFriends:
                    Groupmembers.objects.get(
                        friendgroup=group,
                        member=User.objects.get(username=member)
                    ).delete()

                # After all friends that have been removed and there are still members
                # It returns you to the groups schedule
                return redirect('seeGroup', day=0, group_name=new_group_name)
            else:
                # If all friends are deleted from the group the group will be deleted
                group.delete()
                return redirect('listgroups')
        else:
            # If you have another group with the same name
            messages = ['Typo?', ['You already have a group with that name']]

    if len(friends) > 0:
        # Fills in the members that you can remove
        Group_member_from = GroupMemberFrom()
        Group_member_from.fillData(friends)
        Group_member_from.setLabel('Select the friends you want to remove')
    else:
        # This should never run but if you have no friends in the group and want to remove them
        Group_member_from = ''
        messages = ['No friends', ['All of your friends', 'are in this group already']]
        title = 'Change group name'

    tohtml = {
        'changeNameForm': group_name_form,
        'MembersForm': Group_member_from,
        'title': title,
        'submitText': 'Make changes',
        'messagesToUser': messages
    }
    return render(request, 'groupsComponents/changeGroups.html', tohtml)
Beispiel #5
0
def addGroupMember(request, group_name):
    # Gets all of the persons friends that are not in the group
    friends = baseFriendQuery(request).exclude(
        id__in=[i.member.id for i in Groupmembers.objects.filter(
            friendgroup_id=Friendgroup.objects.get(Q(owner_id=request.user.id) &
                                                   Q(groupname=group_name)).id
            )
        ]
    )

    # Creates the group name form and sets the input value to what it is right now
    group_name_form = GroupNameForm()
    group_name_form.fillData(str(group_name))

    # Sets the title of the page
    messages = ''
    title = 'Add friends'

    # If the is a form that is submitted
    if request.method == "POST":
        # Makes the forms with the data submitted form the form
        name = GroupNameForm(request.POST)

        # NEEDS TO BE getlist so that all members that are selected will be added
        members = GroupMemberFrom(request.POST.getlist('selectedFriends'))

        # Gets the new group name from the request
        # It can be the same as the old on
        new_group_name = str(request.POST.get('name'))
        group_name_form.fillData(new_group_name)

        # checks the the user doesn't have any same named groups that cloud cause a problem
        if name.checkForSameName(request.user.id, group_name):

            # Sets the group name the the new group name this
            # If they are the same nothing happens
            group = Friendgroup.objects.get(Q(groupname=group_name) & Q(owner=request.user))
            group.groupname = new_group_name
            group.save()

            # Cleans ut all the users username form the submitted form
            # Checks that they are friends with you
            # Returns False if there is any problem
            selectedFriends = members.myClean(friends.values('username'))

            # If everything is ok if will create the group
            if selectedFriends:

                # Every member selected gets added to the group
                for member in selectedFriends:
                    Groupmembers(friendgroup=group, member=User.objects.get(username=member)).save()

                # Returns you to the groups schedule
                return redirect('seeGroup', day=0, group_name=new_group_name)
            else:
                # Returns you to the groups schedule
                return redirect('seeGroup', day=0, group_name=new_group_name)
        else:
            # If the person already has a group with that name
            messages = ['Sorry!', ['You already have a group with that name']]

    if len(friends) > 0:
        # If you have friends that are not in the group they will be added
        Group_member_from = GroupMemberFrom()
        Group_member_from.fillData(friends)
    else:
        # If all of your friends are in the group already
        Group_member_from = ''
        messages = ['No friends', ['All of your friends', 'are in this group already']]
        title = 'Change group name'

    tohtml = {
        'changeNameForm': group_name_form,
        'MembersForm': Group_member_from,
        'title': title,
        'submitText': 'Make changes',
        'messagesToUser': messages
    }
    return render(request, 'groupsComponents/changeGroups.html', tohtml)