Exemplo n.º 1
0
def backstage_role_add(request, project):
    project = get_project(request, project, 'manage_roles')

    if request.POST:
        form_role = RoleForm(request.POST)
        form_picture = RolePictureForm(request.POST, request.FILES)
        if form_role.is_valid():
            role = form_role.save(commit=False)
            if form_picture.is_valid():
                picture = form_picture.save(commit=False)
                if role.actor:
                    picture.title = _(u'%s als %s' % (role.actor, role.name))
                else:
                    picture.title = role.name
                picture.save()
                role.picture = picture

            role.project = project
            role.save()
            message_object_created(request, role)
            return redirect('bs-role-list', project=project.pk)
    else:
        form_role = RoleForm()
        form_picture = RolePictureForm()

    return render(request, 'project/role-form.html',
                  get_context_backstage_project(request, project, 'bs-role-form',
                                                {'project': project, 'form_role': form_role,
                                                 'form_picture': form_picture}))
Exemplo n.º 2
0
def backstage_role_form(request, project, role):
    project = get_project(request, project, 'manage_roles')
    role = get_object_or_404(Role, pk=role, project=project)

    if request.POST:
        if request.POST.get('delete'):
            message_object_deleted(request, role)
            role.delete()
            message_object_deleted(request, role)
            return redirect('bs-role-list', project=project.pk)

        form_role = RoleForm(request.POST, instance=role)
        form_picture = RolePictureForm(request.POST, request.FILES, instance=role.picture)
        if form_role.is_valid():
            role = form_role.save(commit=False)

            if form_picture.is_valid():
                picture = form_picture.save(commit=False)
                if role.actor:
                    picture.title = _(u'%s als %s' % (role.actor, role.name))
                else:
                    picture.title = role.name
                picture.save()
                role.picture = picture

            role.save()
            message_object_updated(request, role)
            return redirect('bs-role-list', project=project.pk)

    else:
        form_role = RoleForm(instance=role)
        form_picture = RolePictureForm(instance=role.picture)

    return render(request, 'project/role-form.html',
                  get_context_backstage_project(request, project, 'bs-role-form',
                                                {'project': project, 'role': role, 'form_role': form_role,
                                                 'form_picture': form_picture}))