Login

Tag "clean"

Snippet List

Safe template decorator

A decorator that restricts the tags and filters available to template loading and parsing within a function. This is mainly meant to be used when granting users the power of the DTL. You obviously don't want users to be able to do things that could be potentially malicious. The {% ssi %} tag, for example, could be used to display sensitive data if improperly configured. {% load %} gives them access to all the unlimited python code you wrote in your templatetags. {% load sudo %}{% sudo rm -rf / %} o_0 Note that the "load" tag (among others) is not listed in the default tag whitelist. If you parse a template (however indirectly) in a function decorated with this, unlisted builtin tags will behave like undefined tags (ie, they will result in a TemplateSyntaxError). Since {% load %} is not whitelisted, you may want to include some custom tags or filters as "builtins" for convenience. Simply put the module paths to the libraries to include in the `extra` kwarg or the `extra_libraries` list. Generally, this is not recommended, as these libraries need to be carefully and defensively programmed. **NOTE**: This **does not** do anything about cleaning your rendering context! That's completely up to you! This merely restricts what tags and filters are allowed in the templates. Examples: from django.template.loader import get_template safe_get_template = use_safe_templates(get_template) tmpl = safe_get_template('myapp/some_template.html') from django.template import Template use_safe_templates(Template)('{% load sudo %}') # TemplateSyntaxError: Invalid block tag 'load'

  • template
  • clean
  • safe
  • restrict
Read More

Run model validation before saving a model instance

How to validate your model at save using the pre_save signal. from http://groups.google.com/group/django-developers/browse_thread/thread/eb2f760e4c8d7911/482d8fd36fba4596?hl=en&lnk=gst&q=problem+with+Model.objects.create#482d8fd36fba4596

  • save
  • clean
  • pre_save
  • signals
  • validate
  • full-clean
  • full_clean
Read More

AgreementField

Creating new field to handle checkbox validation in situations where the checkbox must be checked, as in check to agree to terms and such. Thanks to Daniel Pope for the [suggestion](http://code.djangoproject.com/ticket/5957#comment:7) on Django Trac Ticket #[5957](http://code.djangoproject.com/ticket/5957)

  • newforms
  • checkbox
  • forms
  • validation
  • clean
  • booleanfield
  • agreement
Read More

newforms: Add field-specific error in form.clean()

This is a bit of a hack, but as far as I can see currently the only way to specify a validation error that is specific to a field in form.clean(). I am aware of clean_<fieldname>, but those are difficult to use when the validation process for a field involves other fields as well, because the necessary data might at that point not be yet available in form.cleaned_data.

  • newforms
  • forms
  • validation
  • clean
Read More

New forms signup validation

This snippets provide username availability, double email and password validation. You can use it this way : f = SignupForm(request.POST) f.is_valid()

  • newforms
  • email
  • clean
  • signup
  • password
Read More

Digg Style URL String Parser

Does a digg url effect to a string, can be useful for using an item's title in the url, from this: .hi's., is (a) $ [test], will it "work"/ \ to this: his_is_a_test_will_it_work I understand this isn't a very well made script, I am not very good at string manipulation. But I would be happy if someone would recode it in a faster, more managable way. I recomend saving the rendering.

  • url
  • clean
  • simatic
Read More

7 snippets posted so far.