def _(request): preview_form = None pagelet_preview = None if request.POST: form = PageletForm(request.POST, instance=pagelet) if form.is_valid(): if 'save_btn' in request.POST: form.save(user=request.user) return HttpResponseRedirect(redirect_to) else: preview_form = PageletForm( request.POST, instance=pagelet, preview=True, ) pagelet_preview = form.save(commit=False, user=request.user) else: form = PageletForm(instance=pagelet) context = { 'form': form, 'pagelet': pagelet, 'preview_form': preview_form, 'pagelet_preview': pagelet_preview, } return render( request, template, context, )
def _(request): pagelet = get_object_or_404(Pagelet, pk=pagelet_id) preview_form = None pagelet_preview = None if request.POST: form = PageletForm(request.POST, instance=pagelet) if form.is_valid(): if 'save_btn' in request.REQUEST: form.save(user=request.user) return HttpResponseRedirect(redirect_to) else: preview_form = PageletForm( request.POST, instance=pagelet, preview=True, ) pagelet_preview = form.save(commit=False, user=request.user) else: # For non-Inline non-Shared pagelets they can be of a type that can't be edited in the # front-end. Look for the form, if one is provided. If not, redirect to the admin change # url for that object. # Look at all the extension related names # if present on this object, find the model # look at the settings did it define a form? # use that form if it is there # otherwise, redirec to the change URL for pagelet_type in conf.PAGELET_TYPES: pagelet_model = get_model(pagelet_type) try: pagelet = pagelet_model.objects.get(pk=pagelet.pk) except pagelet_model.DoesNotExist: continue else: redirect( "admin:%s_change" % (pagelet_type.replace('.').lower(), ), (pagelet.pk, )) form = PageletForm(instance=pagelet) context = { 'form': form, 'pagelet': pagelet, 'preview_form': preview_form, 'pagelet_preview': pagelet_preview, } return render_to_response( template, context, context_instance=RequestContext(request), )
def _(request): preview_form = None pagelet_preview = None if request.POST: form = PageletForm(request.POST, instance=pagelet) if form.is_valid(): if 'save_btn' in request.REQUEST: form.save(user=request.user) return HttpResponseRedirect(redirect_to) else: preview_form = PageletForm( request.POST, instance=pagelet, preview=True, ) pagelet_preview = form.save(commit=False, user=request.user) else: form = PageletForm(instance=pagelet) context = { 'form': form, 'pagelet': pagelet, 'preview_form': preview_form, 'pagelet_preview': pagelet_preview, } return render_to_response( template, context, context_instance=RequestContext(request), )
def edit_pagelet( request, pagelet_id, template='pagelets/edit_pagelet.html', redirect_field_name=REDIRECT_FIELD_NAME, redirect_to=None, ): redirect_to = request.REQUEST.get(redirect_field_name, redirect_to) if not redirect_to: redirect_to = '/' pagelet = get_object_or_404(Pagelet, pk=pagelet_id) preview_form = None pagelet_preview = None if request.POST: form = PageletForm(request.POST, instance=pagelet) if form.is_valid(): if request.REQUEST.has_key('save_btn'): form.save(user=request.user) return HttpResponseRedirect(redirect_to) else: preview_form = PageletForm( request.POST, instance=pagelet, preview=True, ) pagelet_preview = form.save(commit=False, user=request.user) else: form = PageletForm(instance=pagelet) context = { 'form': form, 'pagelet': pagelet, 'preview_form': preview_form, 'pagelet_preview': pagelet_preview, } return render_to_response( template, context, context_instance=RequestContext(request), )