Login

Tag "preview"

Snippet List

ClearableFileInput with image preview

This widget allows you to display preview images with adjustable width and length of the link: [example](http://img526.imageshack.us/img526/6588/screenshotat20111026215.png) AdvancedFileInput(preview=True, image_width=200) For other files, you can adjust the length of the link without preview: [example](http://img845.imageshack.us/img845/6588/screenshotat20111026215.png) AdvancedFileInput(preview=False, url_length=30) by default, parameters are: preview = True url_length = 30 image_width = 200

  • imagefield
  • preview
  • imagepreview
  • previews-on-imagefield
Read More

Complex Form Preview

Problem ======= The FormPreview class provided by contrib.formtools helps automate a common workflow. You display a form, then force a preview, then finally allow a submit. If the form gets tampered with, the original form gets redisplayed. Unfortunately, this class can only be used when you have an html form that is backed by exactly one Django form. No formsets, no html forms backed by more than one Django form. Solution ======== I was asked to create exactly this sort of workflow for a highly complex form + formset. The ComplexFormPreview class provides a base class to help with this problem. As with FormPreview, you must override a few functions. Code ==== The abstract ComplexFormPreview class can live anywhere on your python path. Import it and subclass is exactly like you would contrib.formtools FormPreview. The self.state dictionary is passed to all response calls as the context for your templates. Add any objects you need in your template to this dictionary. This includes all forms, formsets, and any additional variables you want in your template context. Override the parse_params if you need to get any args/kwargs from your url. Save these values in self.state if you want them in your template context. Override the init_forms method to do setup for all of your forms and formsets. Save all your forms in self.state. You should provide a unique prefix for all forms and formsets on the page to avoid id collisions in html. *VERY IMPORTANT NOTE*: init_forms is called with a kwargs dictionary. You need to pass **kwargs to all of your form definations in init_forms. This is how the POST data is going to be passed to your forms and formsets. *VERY IMPORTANT NOTE No. 2*: all of the validation is handled inside the class - all forms will be found and validated, and we will only proceed when everything is found to be valid. This means that you can use the class as a view directly, or provide a thin wrapper function around it if you want. Override the done method to handle what should be done once your user has successfully previewed and submitted the form. Usually, this will involve calling one or more save() calls to your various forms and formsets. Because you now have multiple forms, the default contrib.formtools templates don't work. You must make custom templates that reference all of your various forms. The stage_field, hash_field, and hash_value fields are used exactly like the formtools examples. Follow the basic layout demonstrated in the example templates, and substitute your custom forms for the default form. Example views.py ================ The views.py demonstrated here has many hooks into my project, including using some [complex formset classes](http://www.djangosnippets.org/snippets/1290/). It won't work for you without being customized, but it will demonstrate how to override the default ComplexFormPreview.

  • form
  • preview
  • formset
  • formtools
Read More

Preview tag for fields with choices

django.contrib.formtools in preview displaying only field.data by default. Its not convenient to see integer value for fields with radio buttons or select choices. This custom tag trying to show string value from choices if available.

  • template
  • tag
  • newforms
  • preview
Read More

4 snippets posted so far.