Exemplo n.º 1
0
def format_edit(request, slug=None):
    if slug:
        format = get_object_or_404(fprmodels.Format, slug=slug)
        group = format.group
        title = _("Edit format %(name)s") % {'name': format.description}
    else:
        title = _("Create format")
        format = None
        group = None
    form = fprforms.FormatForm(request.POST or None,
                               instance=format,
                               prefix='f')
    format_group_form = fprforms.FormatGroupForm(request.POST or None,
                                                 instance=group,
                                                 prefix='fg')
    if form.is_valid():
        if form.cleaned_data['group'] == 'new' and format_group_form.is_valid(
        ):
            format = form.save(commit=False)
            group = format_group_form.save()
            format.group = group
            format.save()
            messages.info(request, _('Saved.'))
            return redirect('format_detail', format.slug)
        elif form.cleaned_data['group'] != 'new':
            format = form.save(commit=False)
            group = fprmodels.FormatGroup.objects.get(
                uuid=form.cleaned_data['group'])
            format.group = group
            format = form.save()
            messages.info(request, _('Saved.'))
            return redirect('format_detail', format.slug)

    return render(request, 'fpr/format/form.html', context(locals()))
Exemplo n.º 2
0
def format_edit(request, slug=None):
    if slug:
        format = get_object_or_404(fprmodels.Format, slug=slug)
        group = format.group
        title = _("Edit format %(name)s") % {"name": format.description}
    else:
        title = _("Create format")
        format = None
        group = None
    form = fprforms.FormatForm(request.POST or None, instance=format, prefix="f")
    format_group_form = fprforms.FormatGroupForm(
        request.POST or None, instance=group, prefix="fg"
    )
    if form.is_valid():
        if form.cleaned_data["group"] == "new" and format_group_form.is_valid():
            format = form.save(commit=False)
            group = format_group_form.save()
            format.group = group
            format.save()
            messages.info(request, _("Saved."))
            return redirect("format_detail", format.slug)
        elif form.cleaned_data["group"] != "new":
            format = form.save(commit=False)
            group = fprmodels.FormatGroup.objects.get(uuid=form.cleaned_data["group"])
            format.group = group
            format = form.save()
            messages.info(request, _("Saved."))
            return redirect("format_detail", format.slug)

    return render(request, "fpr/format/form.html", context(locals()))