django tune in os x terminal
boost your speakers volume and paste this in your os x terminal replace Django with Python or whatever you want, original found with PHP
- humor
boost your speakers volume and paste this in your os x terminal replace Django with Python or whatever you want, original found with PHP
Simple decorator that checks for authentication and activation of account and redirect to login or activation page if needed Your ulrsconf file must have named urls with parameters that you call that decorator Dont forget to import reverse function from django.core.urlresolvers import reverse
Template: `<div id="messageBox_{{ forloop.counter0 }}" style="border:1px solid #ccc;background-color:white" onclick="document.getElementById ('messageBox_{{ forloop.counter0 }}').style.display = 'none';"> {% ifstartswith message "#ok#" %} <font color="green"> {% endifstartswith %} {% ifstartswith message "#error#" %} <font color="red"> {% endifstartswith %} {{ message|cut:"#ok#"|cut:"#error#" }} </font> </div>` In a view you can now do something like that: ` request.user.message_set.create(message="#ok#Hello User, this is a ok message!")`
This translates a given message with ugettext. That's it. `{% load where_you_have_it %}` `{% ugettext "German" %}`
With the child_object function defined in the parent model, you can get it's child object.
Edit: As James pointed out, `django.views.decorators.http` already provides stuff for this. Use that instead. Old description: Should be pretty straightforward; you give it the method you can accept, it returns 405's for other methods. EG, `@method_required("POST")` at the top of your view.
This is a little helper for associating an owner to a newly created object, in this case making the assumption that the current user is always the owner. It removes the necessity of adding a custom save hook to your model. get_current_user comes from this middleware trick to cache the current user: http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
This function can be util for transform pattern lists like these to strings: >>> list_to_pattern([42, 43, 44, 45]) '42-45' >>> list_to_pattern([15, 49, 50, 51, 52]) '15,49-52' >>> list_to_pattern([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) '0-13' You can use also the pattern to list function at [http://www.djangosnippets.org/snippets/495/](http://www.djangosnippets.org/snippets/495/)
Simple template filter that extracts from a text ids, replaces '_' with spaces and produces hyperlinked Table of Contents. More info and usage example please see at [http://www.mysoftparade.com/blog/autogenerated-toc/](http://www.mysoftparade.com/blog/autogenerated-toc/)
**Attention! This snippet must be ignored**, like [zgoda](http://www.djangosnippets.org/users/zgoda/) pointed with reason: already exists this functionality in `markup` contrib. **Explanations:** This template filter allows you to render easily a reStructuredText to **HTML** or another format it supports. **Setup:** Insert the snippet into an_app/templatetags/restutils.py. **Use in template:** `{% load restutils %}` and use it as following: - `{{ entry.content|rest:"html" }}`
this decorator will render template and encode it as JSON string if it find **ajax_request** variable in GET. It will not parse parent (extended) templates, only given template and nested (included). Only blocks will be rendered and encoded to JSON naming block__*BLOCKNAME*. Simple javascript can do ajax request adding *?ajax_request* or *&ajax_request* (if needed) and update given html elements if they id's are same as block__*BLOCKNAME*. you can find a full code (including javascript) at my (http://projects.barbuza.info/trac/browser/django_addons/django_ajax/trunk/ sandbox).
l = (1, 23, 60, 75, 3600, 36000) for n in l: print friendly_seconds(n) 00:00:01 00:00:23 00:01:00 00:01:15 01:00:00 10:00:00
Given an item and a list, check if the item is in the list ----- item = 'a' list = [1, 'b', 'a', 4] ----- {% ifinlist item list %} Yup, it's in the list {% else %} Nope, it's not in the list {% endifinlist %}
This was a much better way of incrementing variables that only changed a small amount in name. deltab in #python also said I could have used tuples, but I'm not familiar with them yet, so I added this to a list of things to look into.
Example usage of BetterPaginator