Exemplo n.º 1
0
def add_organization(request, *args, **kwargs):
    if request.POST:
        data = request.POST
        userform = UserForm(data=data)
        orgform = OrganizationForm(data=data)
        location = {}
        if orgform.is_valid():
            new_organization = orgform.save(commit=False)
            if not request.user == AnonymousUser:
                if userform.is_valid():
                    if userform.cleaned_data['password'] == userform.cleaned_data['passconf']:
                        new_user = User.objects.create_user(
                            userform.cleaned_data['username'],
                            userform.cleaned_data['email'],
                            userform.cleaned_data['password'])
            else:
                new_user = request.user
                try:
                    del_member_class(new_user.member)
                except:
                    pass
            new_organization.leader = new_user.member
            new_organization.save()
            new_organization.save()
            messages.add_message(request, messages.SUCCESS,
                _("Successfully added %(org)s as organization.") % {
                    "org": new_organization.leader.user.username
                }
            )
            return HttpResponseRedirect(new_organization.get_absolute_url())
    else:
        userform = UserForm()
        orgform = OrganizationForm()
    ret = dict(userform=userform, orgform=orgform)
    return render(request, 'verbena/organization/organization_form.html', ret)
Exemplo n.º 2
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)