def initiative_members(request, slug): group = get_object_or_404(GroupProfile, slug=slug) ctx = {} if not group.can_view(request.user): raise Http404() if group.access in [ "public-invite", "private"] and group.user_is_role( request.user, "manager"): ctx["invite_form"] = GroupInviteForm() if group.user_is_role(request.user, "manager"): ctx["member_form"] = GroupMemberForm() ctx.update({ "group": group, "members": group.member_queryset(), "is_member": group.user_is_member(request.user), "is_manager": group.user_is_role(request.user, "manager"), }) ctx = RequestContext(request, ctx) return render_to_response("groups/initiative_members.html", ctx)
def initiative_members(request, slug): group = get_object_or_404(GroupProfile, slug=slug) ctx = {} if not group.can_view(request.user): raise Http404() if group.access in [ "public-invite", "private"] and group.user_is_role( request.user, "manager"): ctx["invite_form"] = GroupInviteForm() if group.user_is_role(request.user, "manager"): ctx["member_form"] = GroupMemberForm() ctx.update({ "group": group, "members": group.member_queryset(), "is_member": group.user_is_member(request.user), "is_manager": group.user_is_role(request.user, "manager"), }) ctx = RequestContext(request, ctx) return render_to_response("mapstory/initiative_members.html", ctx)
def initiative_edit(request, slug): group = GroupProfile.objects.get(slug=slug) if not group.profile_type == 'ini': return HttpResponse(status=404) # Can use this function to toggle manager view if not group.user_is_role(request.user, role="manager"): return HttpResponseForbidden() if request.method == "POST": form = GroupUpdateForm(request.POST, request.FILES, instance=group) if form.is_valid(): group = form.save(commit=False) group.save() form.save_m2m() return HttpResponseRedirect( reverse( "organization_detail", args=[ group.slug])) else: form = GroupForm(instance=group) return render_to_response("groups/group_update.html", { "form": form, "group": group, }, context_instance=RequestContext(request))
def initiative_member_remove(request, slug, username): group = get_object_or_404(GroupProfile, slug=slug) user = get_object_or_404(get_user_model(), username=username) if not group.user_is_role(request.user, role="manager"): return HttpResponseForbidden() else: GroupMember.objects.get(group=group, user=user).delete() user.groups.remove(group.group) return redirect("initiative_detail", slug=group.slug)
def initiative_members_add(request, slug): group = get_object_or_404(GroupProfile, slug=slug) if not group.user_is_role(request.user, role="manager"): return HttpResponseForbidden() form = GroupMemberForm(request.POST) if form.is_valid(): role = form.cleaned_data["role"] for user in form.cleaned_data["user_identifiers"]: group.join(user, role=role) return redirect("initiative_detail", slug=group.slug)