Generate a CSV file for a model
This code generates a CSV file for a model. The URL is http://example.com/spreadsheets/app_label/model_name/ (replace spreadsheets for admin, from the URL for the model's admin page.)
- csv
This code generates a CSV file for a model. The URL is http://example.com/spreadsheets/app_label/model_name/ (replace spreadsheets for admin, from the URL for the model's admin page.)
Based upon (i.e., mostly lifted from) the built-in "linebreaks" and "linebreaksbr" filters, this one works as they do: `{{ object.text|paragraphs }}`
This code gives you the ability to authenticate a user by their email address instead of the username. I've also added the ability to authenticate via LDAP. Some code used from this [snippet](http://www.djangosnippets.org/snippets/74/)
This code works with Django-registration app found here: http://code.google.com/p/django-registration/ If you plan to use this django-registrtion code in your website to allow user registration but do not run your own email server,this snippet can be handy. It uses gmail server to send out email. You have to install libgmail module first. Add two lines to your `settings.py` GMAIL_USERNAME = '[email protected]' GMAIL_PASSWORD = 'your_password' Change models.py - create_inactive_user(...) as given above
template tag for producing tag clouds for a given model, using django-tagging application: http://code.google.com/p/django-tagging/ Sample: http://skam.webfactional.com/tags/ Usage: {% tags_cloud_for_model articles.Article as object_list %} {% tags_cloud_for_model articles.Article as object_list step 6 %}
This is a copy paste job of mediawiki's syntax parser built in Python. You'll probably have to edit it to fit your needs MediaWiki-style markup parse(text) -- returns safe-html from wiki markup code based off of mediawiki
The newforms fields are more capable than the django models fields. In this snippet, we subclass models.IntegerField, and add min_value and max_value. e.g. age = MMIntegerField('How old are you?', min_value=13, max_value=120)
I use these helper methods in my unit tests. They turn many simple getting-and-posting tests into one-liners. Definitely a work in progress, and I can't be the only person who has done this sort of thing -- comments are more than welcome.
Middleware that locks down an entire site, requiring the user to login to view any page. Great for development/beta-testing.
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.
Basically a clone of the default "wrap" filter. I use it to generate plaintext e-mail that has to be broken at 75 characters. {% wordwrap 80 %} Some text here, including other template tags, includes, etc. {% endwordwrap %} I prefer this over the {% filter wordwrap:80 %} as my template (e-mail) writers keep screwing it up.
I'm finding this much more efficient (from a coding perspective) than using the `render_to_response` shortcut. It looks complex, but it's simple to use: just look at the example in the docstring. Call this script `renderer.py` and chuck it in your project root.
Add a value to the context (inside of this block) for easy access. Provides a way to stay DRYer in your templates. **NOTE:** This tag is now in Django core, so if you have Django >0.96 (or SVN) then you do NOT need this.
Simple anti-spam field which will cause the form to raise a `ValidationError` if the value in this field changes. Displays as a CSS hidden `<input type="text" />` field. If you specify a `class` in the `attrs` of the widget, the default `style="display:none;"` won't be rendered with the widget so that you can use a predefined CSS style to do your hiding instead. You can also cause the widget to be wrapped in an html comment to ensure it is not visible to the end user: class EmailForm(Form): email = EmailField() website = HoneypotField(widget=HoneypotWidget( attrs={'class':'fish'}, html_comment=True))
Cheers to limodou for getting me thinking about this. The only problem with his implementation is that it doesn't support Django's "." syntax for accessing array/dict elements. In the Django style of allowing simple syntax for designers while allowing for greater flexibility, and less template duplication for conditionals that were previously impossible to represent in templates, I modified Django's built-in If tag. This is an adaptation/enhancement to Django's built in IfNode {% if ... %} that combines if ifequal ifnotequal into one and then adds even more. This Supports 1. ==, != 2. not .... 3. v in (1,"y",z) 4. <=, <, >=, > 5. nesting (True and (False or (True or False))) How to use it: {% pyif i == 1 or (5 >= i and i != 7) and user.first_name in ('John', 'Jacob') %} 'Tis true. {% else %} 'Tis false. {% endif %} I hope you like it.
2955 snippets posted so far.