Esempio n. 1
0
def add_member(request, group_id):
    group = get_object_or_404(Releaser, is_group=True, id=group_id)
    if request.method == 'POST':
        form = GroupMembershipForm(request.POST)
        if form.is_valid():
            member = form.cleaned_data['scener_nick'].commit().releaser
            if not group.member_memberships.filter(member=member).count():
                membership = Membership(
                    member=member,
                    group=group,
                    is_current=form.cleaned_data['is_current'])
                membership.save()
                group.updated_at = datetime.datetime.now()
                group.save()
                description = u"Added %s as a member of %s" % (member.name,
                                                               group.name)
                Edit.objects.create(action_type='add_membership',
                                    focus=member,
                                    focus2=group,
                                    description=description,
                                    user=request.user)
            return HttpResponseRedirect(group.get_absolute_edit_url() +
                                        "?editing=members")
    else:
        form = GroupMembershipForm()
    return render(request, 'groups/add_member.html', {
        'group': group,
        'form': form,
    })
Esempio n. 2
0
def edit_membership(request, group_id, membership_id):
	group = get_object_or_404(Releaser, is_group=True, id=group_id)
	membership = get_object_or_404(Membership, group=group, id=membership_id)
	if request.method == 'POST':
		form = GroupMembershipForm(request.POST, initial={
			'scener_nick': membership.member.primary_nick,
			'is_current': membership.is_current,
		})
		if form.is_valid():
			member = form.cleaned_data['scener_nick'].commit().releaser
			# skip saving if the value of the member (scener) field duplicates an existing one on this group
			if not group.member_memberships.exclude(id=membership_id).filter(member=member).count():
				membership.member = member
				membership.is_current = form.cleaned_data['is_current']
				membership.save()
				group.updated_at = datetime.datetime.now()
				group.save()
				form.log_edit(request.user, member, group)

			return HttpResponseRedirect(group.get_absolute_edit_url() + "?editing=members")
	else:
		form = GroupMembershipForm(initial={
			'scener_nick': membership.member.primary_nick,
			'is_current': membership.is_current,
		})
	return render(request, 'groups/edit_membership.html', {
		'group': group,
		'membership': membership,
		'form': form,
	})
Esempio n. 3
0
def edit_membership(request, group_id, membership_id):
    group = get_object_or_404(Releaser, is_group=True, id=group_id)
    membership = get_object_or_404(Membership, group=group, id=membership_id)
    if request.method == 'POST':
        form = GroupMembershipForm(request.POST,
                                   initial={
                                       'scener_nick':
                                       membership.member.primary_nick,
                                       'is_current': membership.is_current,
                                   })
        if form.is_valid():
            member = form.cleaned_data['scener_nick'].commit().releaser
            # skip saving if the value of the member (scener) field duplicates an existing one on this group
            if not group.member_memberships.exclude(id=membership_id).filter(
                    member=member).count():
                membership.member = member
                membership.is_current = form.cleaned_data['is_current']
                membership.save()
                group.updated_at = datetime.datetime.now()
                group.save()
                form.log_edit(request.user, member, group)

            return HttpResponseRedirect(group.get_absolute_edit_url() +
                                        "?editing=members")
    else:
        form = GroupMembershipForm(
            initial={
                'scener_nick': membership.member.primary_nick,
                'is_current': membership.is_current,
            })
    return render(request, 'groups/edit_membership.html', {
        'group': group,
        'membership': membership,
        'form': form,
    })
Esempio n. 4
0
def add_member(request, group_id):
	group = get_object_or_404(Releaser, is_group=True, id=group_id)
	if request.method == 'POST':
		form = GroupMembershipForm(request.POST)
		if form.is_valid():
			member = form.cleaned_data['scener_nick'].commit().releaser
			if not group.member_memberships.filter(member=member).count():
				membership = Membership(
					member=member,
					group=group,
					is_current=form.cleaned_data['is_current'])
				membership.save()
				group.updated_at = datetime.datetime.now()
				group.save()
				description = u"Added %s as a member of %s" % (member.name, group.name)
				Edit.objects.create(action_type='add_membership', focus=member, focus2=group,
					description=description, user=request.user)
			return HttpResponseRedirect(group.get_absolute_edit_url() + "?editing=members")
	else:
		form = GroupMembershipForm()
	return render(request, 'groups/add_member.html', {
		'group': group,
		'form': form,
	})