Beispiel #1
0
def actioncluster_add(request):
    """View for adding an ``Application``."""
    if request.method == "POST":
        form = ActionClusterForm(request.POST, request.FILES)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.owner = request.user
            instance.save()
            form.save_m2m()
            mailer.notify_request(instance)
            messages.success(request, 'The action cluster "%s" has been added.' % instance.name)
            return redirect(instance.get_absolute_url())
    else:
        form = ActionClusterForm()
    context = {"form": form}
    return TemplateResponse(request, "actionclusters/object_add.html", context)
Beispiel #2
0
def actioncluster_edit(request, slug):
    actioncluster = get_object_or_404(ActionCluster.active, slug__exact=slug)
    if not actioncluster.is_editable_by(request.user):
        raise Http404
    if request.method == "POST":
        form = ActionClusterForm(request.POST, request.FILES, instance=actioncluster)
        link_formset = ActionClusterLinkFormSet(request.POST, instance=actioncluster)
        image_formset = ActionClusterMediaFormSet(request.POST, request.FILES, instance=actioncluster)
        if form.is_valid() and link_formset.is_valid() and image_formset.is_valid():
            instance = form.save()
            link_formset.save()
            image_formset.save()
            messages.success(request, 'The action cluster "%s" has been updated.' % instance.name)
            return redirect(instance.get_absolute_url())
    else:
        form = ActionClusterForm(instance=actioncluster)
        link_formset = ActionClusterLinkFormSet(instance=actioncluster)
        image_formset = ActionClusterMediaFormSet(instance=actioncluster)
    context = {"object": actioncluster, "form": form, "link_formset": link_formset, "image_formset": image_formset}
    return TemplateResponse(request, "actionclusters/object_edit.html", context)