def menus_edit_item_url(request, item): if request.method == 'POST': form = ZornaMenuItemUrlForm( request.POST, request.FILES, instance=item, initial={'url': item.url}) if form.is_valid(): item = form.save(commit=False) item.url = form.cleaned_data['url'] item.save() return HttpResponseRedirect(reverse('menus_home_view')) else: form = ZornaMenuItemUrlForm( request.POST, instance=item, initial={'url': item.url}) else: form = ZornaMenuItemUrlForm(instance=item, initial={'url': item.url}) context = RequestContext(request) extra_context = {'form': form, 'curitem': item} return render_to_response('menus/edit_menu_item.html', extra_context, context_instance=context)
def menus_add_item_url(request): if user_has_access_to_menus(request.user): if request.method == 'POST': form = ZornaMenuItemUrlForm(request.POST, request.FILES) if form.is_valid(): item = save_form(request, form) item.url = form.cleaned_data['url'] item.save() return HttpResponseRedirect(reverse('menus_home_view')) else: form = ZornaMenuItemUrlForm(request.POST) else: form = ZornaMenuItemUrlForm() context = RequestContext(request) extra_context = {'form': form, 'curitem': False, 'title': _(u'Add a link')} return render_to_response('menus/edit_menu_item.html', extra_context, context_instance=context) else: return HttpResponseRedirect('/')