def menu_add(request, parent_menu_entry_id=None): #check_permissions(request.user, [PERMISSION_USER_CREATE]) if parent_menu_entry_id: parent_menu_entry = get_object_or_404(MenuEntry, pk=parent_menu_entry_id) title = _(u'create new menu entry for: %s') % parent_menu_entry else: parent_menu_entry = None title = _(u'create new root menu entry') if request.method == 'POST': form = MenuEntryForm(request.POST) if form.is_valid(): menu_entry = form.save(commit=False) menu_entry.parent = parent_menu_entry menu_entry.content_object = form.cleaned_data['destination'] menu_entry.save() messages.success(request, _(u'Menu entry "%s" created successfully.') % menu_entry) if parent_menu_entry: return HttpResponseRedirect(reverse('menu_details', args=[parent_menu_entry.pk])) else: return HttpResponseRedirect(reverse('menu_list')) else: form = MenuEntryForm() return render_to_response('generic_form.html', { 'template_id': u'menu_add', 'title': title, 'form': form, 'object': parent_menu_entry, 'object_name': _(u'menu entry'), }, context_instance=RequestContext(request))
def menu_edit(request, menu_entry_id): #check_permissions(request.user, [PERMISSION_USER_EDIT]) menu_entry = get_object_or_404(MenuEntry, pk=menu_entry_id) if request.method == 'POST': form = MenuEntryForm(instance=menu_entry, data=request.POST) if form.is_valid(): menu_entry = form.save(commit=False) menu_entry.content_object = form.cleaned_data['destination'] menu_entry.save() messages.success(request, _(u'Menu entry "%s" updated successfully.') % menu_entry) if menu_entry.parent: return HttpResponseRedirect(reverse('menu_details', args=[menu_entry.parent.pk])) else: return HttpResponseRedirect(reverse('menu_list')) else: form = MenuEntryForm(instance=menu_entry) return render_to_response('generic_form.html', { 'template_id': u'menu_edit', 'title': _(u'edit menu entry: %s') % menu_entry, 'form': form, 'object': menu_entry, 'object_name': _(u'menu entry'), }, context_instance=RequestContext(request))