Exemplo n.º 1
0
def menus_add_item_form_browse(request):
    if user_has_access_to_menus(request.user):
        if request.method == 'POST':
            form = ZornaMenuItemFormsForm(request.POST, request.FILES)
            if form.is_valid():
                item = save_form(request, form)
                item.content_object = form.cleaned_data['form']
                item.extra_info = 'browse'
                item.save()
                return HttpResponseRedirect(reverse('menus_home_view'))
            else:
                form = ZornaMenuItemFormsForm(request.POST)
        else:
            form = ZornaMenuItemFormsForm()

        context = RequestContext(request)
        extra_context = {'form':
                         form, 'curitem': False, 'title': _(u'Add a link to form list')}
        return render_to_response('menus/edit_menu_item.html', extra_context, context_instance=context)
    else:
        return HttpResponseRedirect('/')
Exemplo n.º 2
0
def menus_edit_item_form(request, item):
    if request.method == 'POST':
        form = ZornaMenuItemFormsForm(
            request.POST, request.FILES, instance=item, initial={'form': item.object_id})
        if form.is_valid():
            item = form.save(commit=False)
            item.content_object = form.cleaned_data['form']
            item.save()
            return HttpResponseRedirect(reverse('menus_home_view'))
        else:
            form = ZornaMenuItemFormsForm(
                request.POST, instance=item, initial={'form': item.object_id})
    else:
        form = ZornaMenuItemFormsForm(instance=item, initial={
                                      'form': item.object_id})
    if item.extra_info == 'submission':
        form.fields['form'].label = _(u"Form submission")
    else:
        form.fields['form'].label = _(u"Form browse")

    context = RequestContext(request)
    extra_context = {'form': form, 'curitem': item}
    return render_to_response('menus/edit_menu_item.html', extra_context, context_instance=context)