Login

Tag "django"

Snippet List

boostrap prepend-input for widgets

Prepend span with text, image or other data to any django widget so bootstrap can format it like in [here](http://twitter.github.com/bootstrap/base-css.html#forms) (scroll to "Extending form controls" section) Example usage: ` example_field = CharField( max_length=255, min_length=1, label='Label', required=False, widget=PrependWidget(base_widget=TextInput, data='@') ) `

  • django
  • bootstrap
  • prepend-input
Read More

Closure for FieldListFilter classes with custom sets of ranges

This closure lets you quickly produce date-style range filters in the Django Admin interface without having to create a new class for each one. It follows Python range semantics, with the lower value using a `_gte` test and the upper value using an `_lt` test. Here's an example of how I'm using it in one of my projects: list_filter = ('complete', ('chapters', makeRangeFieldListFilter([ (_('1'), 1, 2), (_('2 to 10'), 2, 10), (_('11 to 30'), 11, 30), (_('31 to 100'), 31, 100), (_('At least 100'), 100, None), ], nullable=True)), ('word_count', makeRangeFieldListFilter([ (_('Less than 1000'), None, 1000), (_('1K to 5K'), 1000, 5000), (_('5K to 10K'), 5000, 10000), (_('10K to 75K'), 10000, 75000), (_('75K to 150K'), 75000, 150000), (_('150K to 300K'), 150000, 300000), (_('At least 300K'), 300000, None), ], nullable=True)), ('derivatives_count', makeRangeFieldListFilter([ (_('None'), 0, 1), (_('1 to 5'), 1, 5), (_('5 to 50'), 5, 50), (_('50 to 1000'), 50, 1000), (_('At least 1000'), 1000, None), ])), 'pub_date', 'upd_date') It is based on code from `DateFieldListFilter` and `BooleanFieldListFilter` from `django.contrib.admin.filters`.

  • filter
  • django
  • admin
  • fieldlistfilter
Read More

IsNullFieldListFilter

As the title does a pretty good job of condensing, this is a subclass of `FieldListFilter` for the Django 1.4 Admin system which allows you filter by whether a field is or is not `NULL`. For example, if you had an `Author` model and wanted to filter it by whether authors were also users of the site, you could add this to your `AuthorAdmin` class: list_filter = ( ('user_acct', IsNullFieldListFilter), ) For the record, it began life as a modified version of `BooleanFieldListFilter` from `django.contrib.admin.filters`.

  • filter
  • django
  • admin
  • fieldlistfilter
Read More

yandex maps templatetag

https://github.com/coolchevy/django-yandexmaps django-yandexmaps ================= easy maps integration via yandex maps api Installation ============ 1. Add your YANDEXMAPS_API_KEY to settings.py http://api.yandex.ru/maps/form.xml/ 2. Add 'yandex_maps' in INSTALLED_APPS Usage ============ Template:: {% load yandexmaps_tags %} {% yandex_map_by_address object.get_address object.title 500,300 %} Demo ============ http://colorsound.com.ua/clubs/porter-pub-1/

  • template
  • django
  • templatetag
  • api
  • templatetags
  • yandex
  • maps
Read More

Django mediagenerator folder bundler

This code will put an entire folder into your media bundle - instead of having to write out every file in a given folder: *It assumes your static root is a absolute directory* **Usage** MEDIA_BUNDLES = ( ('init.js', 'coffeescript/init.coffee', ), bundle_builder('libraries.js', 'javascript/vendor'), bundle_builder('main.js', 'coffeescript', exclude=['init.js',]), bundle_builder('templates.js', 'eco'), ) **Notes** You may wish to use [cache_utils](http://pypi.python.org/pypi/django-cache-utils) or similar to avoid crawling the filesystem every time the site loads

  • django
  • wildcard
  • django-mediagenerator
  • mediagenerator
Read More

Pagination Alphabetically compatible with paginator_class

This is just a modified version of a [previous snippet](http://djangosnippets.org/snippets/1364/) to make it work with unicode and with class-based ListView paginator_class To use it put this in your urls.py: `from youapp.fileyouchose import NamePaginator` `urlpatterns = patterns('',` `url(r'^example/(?P<page>[0-9]+)/$', ListView.as_view(model=myModel,template_name="mytemplate.html",paginator_class=NamePaginator,paginate_by=25), name="url_name"),` And then in your template something like this would work: {% if page_obj.has_other_pages %} <div class="row"> <div class="span12"> <div class="pagination"> <ul> {% if page_obj.has_previous %} <li><a href="{% url page page=page_obj.previous_page_number %}">Prev</a></li> {% else %} <li class="disabled"><a>Prev</a></li> {% endif %} {% for p in page_obj.paginator.pages %} <li {% if p == page_obj %}class="active"{% endif %}> <a href="{% url category_page page=p.number %}">{{ p }}</a> </li> {% endfor %} {% if page_obj.has_next %} <li><a href="{% url page page=page_obj.next_page_number %}">Next</a></li> {% else %} <li class="disabled"><a>Next</a></li> {% endif %} </ul> </div> </div> </div> {% endif %}

  • django
  • pagination
  • listview
Read More

Decode HTML Template Tag

This is useful if you have a string that is html encoded (i.e. "&lt;p&gt;Hello world!&lt;/p&gt;") and you want to do something more complex than just display it as html, such as using the striptags filter.

  • template
  • tag
  • django
  • templatetag
  • html
  • decode
Read More

Custom Filter using filterspecs

This snippet is based on [#1051](http://djangosnippets.org/snippets/1051/). It adds filtering by existence of at least one related object. It is an example of how to simply subclass the FilterSpec class, in order to build a custom Filter. The comment in the code contains instructions on how to implement it in a real project.

  • django
  • filterspecs
  • custom filters
Read More

Generate a dineromail form in python

This is the code we use on bandtastic.me to build a html that sends users to dineromail to pay with. This code builds a form thats ready to send multiple items.

  • django
  • python
  • dineromail
  • express checkout
Read More

django piston use origin django auth

Django-piston have two build-in authentication handlers, the HttpBasicAuthentication and OAuthAuthentication. This snippet give another choice which use the django auth. It can support ajax and normal request.

  • django
  • auth
  • piston
Read More

213 snippets posted so far.