Login

Snippets by zeeg

Snippet List

Login with email or username

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' )

  • email
  • login
  • auth
  • backend
Read More

locale based on domain

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.

  • middleware
  • i18n
Read More

jQuery Autocomplete

A merged version of the many jQuery autocomplete widgets. See [1](http://php.scripts.psu.edu/rja171/widgets/autocomplete.php) and [2](http://www.dyve.net/jquery/?autocomplete) for more information.

  • jquery
  • autocomplete
Read More

Sphinx Search ORM

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>)

  • search
  • sphinx
  • full-text
Read More

MediaWiki Markup

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

  • markup
  • mediawiki
Read More

Captcha Middleware (Template)

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 python script](http://www.djangosnippets.org/snippets/127/)

  • captcha
  • anti-spam
Read More

Captcha Middleware

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

  • captcha
  • anti-spams
Read More

Browser Verification

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
Read More

Localized URLs (www-en)

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
Read More

zeeg has posted 14 snippets.