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)
Example #3
0
def member_signup(request, *args, **kwargs):
    """
    Signup a new member
    Add the member to a group-type if necessary
    """
    data = request.POST or None
    form = UserForm(data=data)
    mdata = request.FILES or None
    avatar_form = AvatarForm(data, mdata)
    if avatar_form.is_valid() and form.is_valid():
        user = form.save()
        avatar = avatar_form.save()
        user.member.avatar = avatar
        try:
            user.member.save()
            form.login(request, user)
            messages.add_message(request, messages.SUCCESS,
                    _("Successfully added %(member)s as a member.") % {
                        "member": user.username
                    }
                )
            return redirect(user.member.get_absolute_url())
        except:
            return redirect("member_signup")
    ret = dict(form=form,avform=avatar_form)
    return render(request, 'verbena/members/signup.html', ret)
Example #4
0
def member_avatar_edit(request, *args, **kwargs):
    """
    edit or add an avatar to the member
    """
    data = request.POST or None
    file_data = request.FILES
    form = AvatarForm(data, file_data)
    if form.is_valid():
        member = request.user.member
        member.avatar = form.save()
        try:
            member.save()
            messages.add_message(request, messages.SUCCESS,
                    _("Successfully added an avatar")
                )
            return redirect(member.get_absolute_url())
        except:
            return HttpResponse(status=404)
    ret = dict(form=form)
    return render(request, 'verbena/members/avatar_edit.html', ret)