Пример #1
0
def initiative_create(request):
    if request.method == "POST":
        form = GroupForm(request.POST, request.FILES)
        if form.is_valid():
            group = form.save(commit=False)
            group.profile_type = 'ini'
            group.save()
            form.save_m2m()
            group.join(request.user, role="manager")
            # Create the collection corresponding to this initiative
            collection = Collection()
            collection.name = group.title
            collection.slug = group.slug
            collection.group = group
            collection.save()
            return HttpResponseRedirect(
                reverse(
                    "initiative_detail",
                    args=[
                        group.slug]))
    else:
        form = GroupForm(initial={'profile_type': 'ini'})

    if request.user.is_superuser:
        return render_to_response("groups/group_create.html", {
            "form": form,
            }, context_instance=RequestContext(request))
    else:
        return HttpResponse(status=403)
Пример #2
0
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))
Пример #3
0
def group_update(request, slug):
    group = GroupProfile.objects.get(slug=slug)
    if not group.user_is_role(request.user, role="manager") and not request.user.is_superuser:
        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()
            if request.POST['admin']:
                user = Profile.objects.get(id=request.POST['admin'])
                group.join(user, role="manager")
            return HttpResponseRedirect(
                reverse(
                    "group_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))
Пример #4
0
def group_create(request):
    if request.method == "POST":
        form = GroupForm(request.POST, request.FILES)
        if form.is_valid():
            group = form.save(commit=False)
            group.save()
            group.join(request.user, role="manager")
            if group.access != "private":
                action.send(request.user, verb="created", target=group)
            return redirect("group_detail", group.slug)
    else:
        form = GroupForm()
    
    return render_to_response("groups/group_create.html", {
        "form": form,
    }, context_instance=RequestContext(request))
Пример #5
0
def initiative_create(request):
    if request.method == "POST":
        form = GroupForm(request.POST, request.FILES)
        if form.is_valid():
            group = form.save(commit=False)
            group.profile_type = 'ini'
            group.save()
            form.save_m2m()
            group.join(request.user, role="manager")
            # Create the collection corresponding to this initiative
            collection = Collection()
            collection.name = group.title
            collection.slug = group.slug
            collection.group = group
            collection.save()
            return HttpResponseRedirect(
                reverse(
                    "initiative_detail",
                    args=[
                        group.slug]))
    else:
        form = GroupForm(initial={'profile_type': 'ini'})

    if request.user.is_superuser:
        return render_to_response("groups/group_create.html", {
            "form": form,
            }, context_instance=RequestContext(request))
    else:
        return HttpResponse(status=403)
Пример #6
0
def group_create(request):
    if request.method == "POST":
        form = GroupForm(request.POST, request.FILES)
        if form.is_valid():
            group = form.save(commit=False)
            group.save()
            form.save_m2m()
            group.join(request.user, role="manager")
            return HttpResponseRedirect(
                reverse("group_detail", args=[group.slug]))
    else:
        form = GroupForm()

    return render_to_response("groups/group_create.html", {
        "form": form,
    },
                              context_instance=RequestContext(request))
Пример #7
0
def group_create(request):
    if request.method == "POST":
        form = GroupForm(request.POST, request.FILES)
        if form.is_valid():
            group = form.save(commit=False)
            group.save()
            form.save_m2m()
            group.join(request.user, role="manager")
            return HttpResponseRedirect(reverse("group_detail", args=[group.slug]))
    else:
        form = GroupForm()
    
    return render_to_response("groups/group_create.html", {
        "form": form,
    }, context_instance=RequestContext(request))