Snippet List
A simple backend which allows you to login with either an email address or a username.
It should be combined with another backend for checking permissions:
AUTHENTICATION_BACKENDS = (
'myproject.accounts.backends.EmailOrUsernameModelBackend',
'django.contrib.auth.backends.ModelBackend'
)
This is something we're using over at Curse to keep things clean and simple for our users.
* We needed a url for any language code (which the domain provides) vs a cookie
* We needed a to only store 2 letter codes in the db for each language (thus the key doesn't always match the code)
This consists of two major modifications:
* LANGUAGES in settings.py is a completely different format and would need changed based on your setup
* the locale middleware has a couple absolute instances of where to point a user by default.
Works just like the normal template filter, escape(), except that it works on dictionaries and lsits
An ORM model for the Sphinx full-text search engine.
See http://www.sphinxsearch.com/ for more information.
It currently supports the following:
class MyModel(models.Model):
search = SphinxSearch()
MyModel.search.query('query')
MyModel.search.query('query').order_by('@weight', '@id', 'my_attribute')
MyModel.search.query('query').filter(my_attribute=5)
MyModel.search.query('query').filter(my_other_attribute=[5, 3,4])
MyModel.search.query('query').exclude(my_attribute=5)[0:10]
MyModel.search.query('query').count()
SphinxSearch().query('hello').on_index('model_myapp model_myotherapp')
Returns an ordered list of the objects in your database.
-- Update:
New Methods:
* count()
* index_on(<str index>)
* extra(<see django>)
* all() (does nothing)
* select_related(<see django>)
* group_by(<str attribute>, <const function>[, <str sort>)
* weights(<list weights>)
A middleware we are using to stop "spam" on Curse. It makes the user fill in a captcha box whenever they submit a form unless a cookie is set (which expires by default after 6 hours)
See also [the template](http://www.djangosnippets.org/snippets/128/)
Note: render_template is simply a shortcut function we have for doing render_to_response with a request context
A page we used on Curse to stop users who are new, who are using old browsers (ones who usually have extreme issues with CSS handling) and recommend they update.
Can easily be modified to suit your needs.
- middleware
- browsers
- validation
An example on how we changed our localization middleware to use www-en.<domain> instead of it being hidden in the cookie.
This also changes zh-cn to cn, and zh-tw to tw in the URLs.
This is only a base snippet and you will most likely need to modify it to fit your needs.
- internationalization
- middleware
- il8n
- urls
zeeg has posted 14 snippets.