Exemple #1
0
def actor_init_form(request):
    try:
        actor = request.user.actor
        return redirect('backstage')
    except Actor.DoesNotExist:
        actor = Actor(user=request.user, status=Configuration.objects.current().default_status)

    if request.POST:
        form_public = ActorPublicForm(request.POST, instance=actor)
        form_data = ActorDataForm(request.POST, instance=actor)
        form_group = UserGroupForm(request.POST)
        if form_public.is_valid() and form_data.is_valid() and form_group.is_valid():
            form_public.save()
            form_data.save()
            request.user.groups.add(form_group.cleaned_data['group'])
            messages.success(request, _(
                u'Vielen Dank! Damit hast du nun dein Profil angelegt. Bitte melde dich nun noch mal an.'))
            return redirect('logout')
    else:
        form_public = ActorPublicForm(instance=actor)
        form_data = ActorDataForm(instance=actor)
        form_group = UserGroupForm()

    forms = ((_(u'Öffentliches Profil'), form_public),
             (_('Stammdaten'), form_data),
             (_(u'Gruppenzugehörigkeit'), form_group))

    return render(request, 'backstage/actor-init-form.html',
                  get_context_backstage(request, 'actor-init-form', {'forms': forms}))
Exemple #2
0
def actor_public_form(request):
    try:
        actor = request.user.actor
    except:
        actor = Actor(user=request.user)

    success_messages = []

    if request.POST and actor:
        form = ActorPublicForm(request.POST, instance=actor)
        if form.is_valid():
            form.save()
            success_messages.append(u'Dein öffentliches Profil wurde aktualisiert.')

        form_picture = PicturePublicForm(request.POST, request.FILES, instance=actor.picture_public)
        if form_picture.is_valid():
            form_picture.title = actor.__unicode__()
            actor.picture_public = form_picture.save()
            actor.save()
            success_messages.append(u'Dein öffentliches Profilbild wurde aktualisiert.')

    else:
        form = ActorPublicForm(instance=actor)
        form_picture = PicturePublicForm(instance=actor.picture_public)

    if success_messages:
        messages.success(request, ' '.join(success_messages))

    c = {
        'form': form,
        'form_picture': form_picture,
        'actor_slug': actor.slug,
    }

    return render(request, 'backstage/actor-public-form.html', get_context_backstage(request, 'actor-public-form',
                                                                                     c))