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, })
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, })
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, })
def add_subgroup(request, group_id): group = get_object_or_404(Releaser, is_group=True, id=group_id) if request.method == 'POST': form = GroupSubgroupForm(request.POST) if form.is_valid(): member = form.cleaned_data['subgroup_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 subgroup of %s" % (member.name, group.name) Edit.objects.create(action_type='add_subgroup', focus=member, focus2=group, description=description, user=request.user) return HttpResponseRedirect(group.get_absolute_edit_url() + "?editing=subgroups") else: form = GroupSubgroupForm() return render(request, 'groups/add_subgroup.html', { 'group': group, 'form': form, })