示例#1
0
def edit_membership(request, scener_id, membership_id):
	scener = get_object_or_404(Releaser, is_group=False, id=scener_id)
	membership = get_object_or_404(Membership, member=scener, id=membership_id)
	if request.method == 'POST':
		form = ScenerMembershipForm(request.POST)
		if form.is_valid():
			group = form.cleaned_data['group_nick'].commit().releaser
			if not scener.group_memberships.exclude(id=membership_id).filter(group=group).count():
				membership.group = group
				membership.is_current = form.cleaned_data['is_current']
				membership.save()
				scener.updated_at = datetime.datetime.now()
				scener.save()
				form.log_edit(request.user, scener, group)
			return HttpResponseRedirect(scener.get_absolute_edit_url() + "?editing=groups")
	else:
		form = ScenerMembershipForm(initial={
			'group_nick': membership.group.primary_nick,
			'is_current': membership.is_current,
		})
	return render(request, 'sceners/edit_membership.html', {
		'scener': scener,
		'membership': membership,
		'form': form,
	})
示例#2
0
def add_group(request, scener_id):
    scener = get_object_or_404(Releaser, is_group=False, id=scener_id)

    if not scener.editable_by_user(request.user):
        raise PermissionDenied

    if request.method == 'POST':
        form = ScenerMembershipForm(request.POST)
        if form.is_valid():
            group = form.cleaned_data['group_nick'].commit().releaser
            if not scener.group_memberships.filter(group=group).count():
                membership = Membership(
                    member=scener,
                    group=form.cleaned_data['group_nick'].commit().releaser,
                    is_current=form.cleaned_data['is_current'])
                membership.save()
                scener.updated_at = datetime.datetime.now()
                scener.save()
                description = u"Added %s as a member of %s" % (scener.name, group.name)
                Edit.objects.create(action_type='add_membership', focus=scener, focus2=group,
                    description=description, user=request.user)
            return HttpResponseRedirect(scener.get_absolute_edit_url() + "?editing=groups")
    else:
        form = ScenerMembershipForm()

    return render(request, 'sceners/add_group.html', {
        'scener': scener,
        'form': form,
    })
示例#3
0
def add_group(request, scener_id):
	scener = get_object_or_404(Releaser, is_group=False, id=scener_id)
	if request.method == 'POST':
		form = ScenerMembershipForm(request.POST)
		if form.is_valid():
			group = form.cleaned_data['group_nick'].commit().releaser
			if not scener.group_memberships.filter(group=group).count():
				membership = Membership(
					member=scener,
					group=form.cleaned_data['group_nick'].commit().releaser,
					is_current=form.cleaned_data['is_current'])
				membership.save()
				scener.updated_at = datetime.datetime.now()
				scener.save()
				description = u"Added %s as a member of %s" % (scener.name, group.name)
				Edit.objects.create(action_type='add_membership', focus=scener, focus2=group,
					description=description, user=request.user)
			return HttpResponseRedirect(scener.get_absolute_edit_url() + "?editing=groups")
	else:
		form = ScenerMembershipForm()

	return render(request, 'sceners/add_group.html', {
		'scener': scener,
		'form': form,
	})
示例#4
0
def edit_membership(request, scener_id, membership_id):
    scener = get_object_or_404(Releaser, is_group=False, id=scener_id)
    membership = get_object_or_404(Membership, member=scener, id=membership_id)

    if not scener.editable_by_user(request.user):
        raise PermissionDenied

    if request.method == 'POST':
        form = ScenerMembershipForm(request.POST, initial={
            'group_nick': membership.group.primary_nick,
            'is_current': membership.is_current,
        })
        if form.is_valid():
            group = form.cleaned_data['group_nick'].commit().releaser
            if not scener.group_memberships.exclude(id=membership_id).filter(group=group).count():
                membership.group = group
                membership.is_current = form.cleaned_data['is_current']
                membership.save()
                scener.updated_at = datetime.datetime.now()
                scener.save()
                form.log_edit(request.user, scener, group)
            return HttpResponseRedirect(scener.get_absolute_edit_url() + "?editing=groups")
    else:
        form = ScenerMembershipForm(initial={
            'group_nick': membership.group.primary_nick,
            'is_current': membership.is_current,
        })
    return render(request, 'sceners/edit_membership.html', {
        'scener': scener,
        'membership': membership,
        'form': form,
    })