Example #1
0
def edit_action_group(request, slug, *args, **kwargs):
    data = request.POST or None
    mdata = request.FILES or None
    try:
        ag = ActionGroup.objects.get(slug=slug)
        if ag.leader != request.user.member:
            messages.add_message(request, messages.ERROR,
                _("You do not have permission to edit %(ag)s.") % {
                    "ag": ag.title,
                }
            )
            return HttpResponse(status=403)
    except ActionGroup.DoesNotExist:
        return HttpResponse(status=404)
    avform = AvatarForm(data, mdata, instance=ag.portrait)
    agform = ActionGroupForm(data, instance=ag)
    ret = dict(form=agform, avform=avform)
    if agform.is_valid() and avform.is_valid():
        agform.save(commit=False)
        av = avform.save()
        agform.portrait = av
        ag = agform.save()
        messages.add_message(request, messages.SUCCESS,
                _("Successfully edited %(ag)s.") % {
                    "ag": ag.title,
                }
            )
        return redirect(ag.get_absolute_url())
    return render(request, "verbena/act_group/actiongroup_form.html", ret)
Example #2
0
def add_actiongroup(request, *args, **kwargs):
    """
    Create an action group and set up logged-in user as the leader
    """
    data = request.POST or None
    agform = ActionGroupForm(data=data)
    mdata = request.FILES or None
    avatar_form = AvatarForm(data, mdata)
    if agform.is_valid() and avatar_form.is_valid():
        new_ag = agform.save(commit=False)
        user = request.user.member
        try:
            new_ag.leader = user
##            import pdb; pdb.set_trace()
            portrait = avatar_form.save()
            new_ag.portrait = portrait
            try:
                new_ag.save()
                messages.add_message(request, messages.SUCCESS,
                    _("Successfully added %(ag)s to action groups.") % {
                        "ag": new_ag.title
                    }
                )
                return HttpResponseRedirect(new_ag.get_absolute_url())
            except:
                return HttpResponse(status=500)
        except Member.DoesNotExist:
            return HttpResponse(status=404)
        return HttpResponseRedirect(new_ag.get_absolute_url())
    ret = dict(form=agform, avform=avatar_form)
    return render(request, 'verbena/act_group/actiongroup_form.html', ret)