djangosnippets.org: Latest snippets posted by zeeghttps://djangosnippets.org/users/zeeg/2008-08-23T12:35:17.145074-05:00zeegLogin with email or username
2008-08-23T12:35:17.145074-05:00zeeghttps://djangosnippets.org/snippets/1001/<p>A simple backend which allows you to login with either an email address or a username.</p>
<p>It should be combined with another backend for checking permissions:</p>
<pre><code>AUTHENTICATION_BACKENDS = (
'myproject.accounts.backends.EmailOrUsernameModelBackend',
'django.contrib.auth.backends.ModelBackend'
)
</code></pre>
Freely redistributableBetterQuerySetPaginator
2008-07-10T04:17:21.967405-05:00zeeghttps://djangosnippets.org/snippets/867/<p>A more useful paginator. </p>
Freely redistributablelocale based on domain
2007-06-08T10:44:55.415612-05:00zeeghttps://djangosnippets.org/snippets/271/<p>This is something we're using over at Curse to keep things clean and simple for our users.</p>
<ul>
<li>We needed a url for any language code (which the domain provides) vs a cookie</li>
<li>We needed a to only store 2 letter codes in the db for each language (thus the key …</li></ul>
Freely redistributablejQuery Autocomplete
2007-06-07T14:50:34.915727-05:00zeeghttps://djangosnippets.org/snippets/269/<p>A merged version of the many jQuery autocomplete widgets.</p>
<p>See <a href="http://php.scripts.psu.edu/rja171/widgets/autocomplete.php">1</a> and <a href="http://www.dyve.net/jquery/?autocomplete">2</a> for more information.</p>
Freely redistributableescape() -- works on dictionaries/lists
2007-05-17T15:43:28.446200-05:00zeeghttps://djangosnippets.org/snippets/241/<p>Works just like the normal template filter, escape(), except that it works on dictionaries and lsits</p>
Freely redistributableSphinx Search ORM
2007-05-11T18:05:10.520888-05:00zeeghttps://djangosnippets.org/snippets/231/<p>An ORM model for the Sphinx full-text search engine.</p>
<p>See http://www.sphinxsearch.com/ for more information.</p>
<p>It currently supports the following:</p>
<pre><code>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')
</code></pre>
<p>Returns an ordered list of the objects in your database.</p>
<p>-- Update:</p>
<p>New Methods:</p>
<ul>
<li>count() …</li></ul>
Freely redistributablereal_printf
2007-05-11T15:43:29.428781-05:00zeeghttps://djangosnippets.org/snippets/229/<p>Allows you to use the N argument parameters in a printf string</p>
Freely redistributablereally_equals
2007-05-11T15:42:55.273974-05:00zeeghttps://djangosnippets.org/snippets/228/<p>Lets you compare two objects based on fields</p>
Freely redistributableMediaWiki Markup
2007-03-28T12:10:36.280779-05:00zeeghttps://djangosnippets.org/snippets/139/<p>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</p>
<p>MediaWiki-style markup
parse(text) -- returns safe-html from wiki markup
code based off of mediawiki</p>
Freely redistributableCaptcha Middleware (Template)
2007-03-23T12:29:09.872396-05:00zeeghttps://djangosnippets.org/snippets/128/<p>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)
</p>
<p>See also <a href="http://www.djangosnippets.org/snippets/127/">the python script</a>
</p>
Freely redistributableCaptcha Middleware
2007-03-23T12:23:58.900663-05:00zeeghttps://djangosnippets.org/snippets/127/<p>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)</p>
<p>See also <a href="http://www.djangosnippets.org/snippets/128/">the template</a></p>
<p>Note: render_template is simply a shortcut function we have for …</p>
Freely redistributableBrowser Verification
2007-03-02T14:49:52.617744-06:00zeeghttps://djangosnippets.org/snippets/77/<p>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.</p>
<p>Can easily be modified to suit your needs.</p>
Freely redistributableLocalized URLs (www-en)
2007-02-25T14:04:28.465751-06:00zeeghttps://djangosnippets.org/snippets/5/<p>An example on how we changed our localization middleware to use www-en.<domain> instead of it being hidden in the cookie.</p>
<p>This also changes zh-cn to cn, and zh-tw to tw in the URLs.</p>
<p>This is only a base snippet and you will most likely need to modify it to fit …</p>
Freely redistributablerender_template shortcut
2007-02-25T13:50:00.628586-06:00zeeghttps://djangosnippets.org/snippets/4/<p>A shortcut to render templates with RequestContext</p>
Freely redistributable