示例#1
0
def update(request, multiview_id):
    M = get_object_or_404(Multiview.objects.filter(pk=multiview_id))
    F = Multiview_Form(data=request.POST, instance=M, user=request.user)
    data = {}
    if F.is_valid():
        F.save()
        messages.success(request, _("Multiview updated with success."))
        data.update({
            'response': 'ok',
            'callback-url': M.get_absolute_url(),
            'id': M.id,
        })
    else:
        for field, error in F.errors.items():
            messages.error(request, '<b>%s</b>: %s' % (field, error))
        data['response'] = 'error'
    return render_HTML_JSON(request, data, 'base/messages.html', {})
示例#2
0
def add(request):
    if request.method == 'POST':
        F = Multiview_Form(data=request.POST, user=request.user)
        data = {}
        if F.is_valid():
            M = F.save()
            messages.success(request, _("Multiview added with success."))
            data.update({
                'response': 'ok',
                'callback-url': M.get_absolute_url(),
                'id': M.pk,
            })
        else:
            for field, error in F.errors.items():
                messages.error(request, '<b>%s</b>: %s' % (field, error))
            data['response'] = 'error'
        return render_HTML_JSON(request, data, 'base/messages.html', {})
    else:
        return render(request, 'forms/multiview.html', {
            'Multiview_Form': Multiview_Form(user=request.user),
        })