djangosnippets.org: Latest snippets posted by johnnoonehttps://djangosnippets.org/users/johnnoone/2010-02-10T07:45:49.653741-06:00johnnooneAccess Control Mechanisms with mod_wsgi
2010-02-10T07:45:49.653741-06:00johnnoonehttps://djangosnippets.org/snippets/1920/<p>Here my piece of code for managing users with WSGIAuthUserScript.</p>
Freely redistributableGenerate QR Code image for a string
2009-05-06T09:31:24.692767-05:00johnnoonehttps://djangosnippets.org/snippets/1494/<p>Generate QR Code image from a string with the Google charts API</p>
<p>http://code.google.com/intl/fr-FR/apis/chart/types.html#qrcodes</p>
<p>Exemple usage in a template</p>
<pre><code>{{ my_string|qrcode:"my alt" }}
</code></pre>
<p>will return the image tag with </p>
<ul>
<li>src: http://chart.apis.google.com/chart?chs=150x150&amp;cht=qr&amp;chl=my_string&amp;choe=UTF-8</li>
<li>alt: my alt"</li>
</ul>
Freely redistributableExecute a signal once
2009-05-05T15:58:02.712215-05:00johnnoonehttps://djangosnippets.org/snippets/1490/<p>Decorates signals for executing only one time</p>
<p>Exemple usage :</p>
<pre><code>from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.contrib.auth.models import User
@one
def user_welcome(sender, instance, created, **kwargs):
# Send a welcome email
if created == True and isinstance(instance, User):
instance.message_set.create(message=_(u"Ho, Welcome %s!" % instance))
subject, from_email, to = 'Welcome …</code></pre>
Freely redistributableScript factory for monitoring django-sphinx with Nagios
2009-04-07T10:35:52.168782-05:00johnnoonehttps://djangosnippets.org/snippets/1418/<p>This snippet is used to create a script for monitoring sphinx status with Nagios via <a href="http://code.google.com/p/django-sphinx/">django-sphinx</a>.</p>
<p>It returns 0 (OK) or 2 (CRITICAL).</p>
<p>Remember to change this strings <code>ModelToMonitor</code> and <code>app_name</code>.</p>
<p>Usage :</p>
<p><code>./manage your-controls-command --log</code> > /your/script/name.py</p>
Freely redistributableMonitoring django-sphinx for Nagios
2009-04-07T10:29:27.407878-05:00johnnoonehttps://djangosnippets.org/snippets/1417/<p>This snippet is used to monitor sphinx status via <a href="http://code.google.com/p/django-sphinx/">django-sphinx</a>.</p>
<p>It returns 0 (OK) or 2 (CRITICAL).</p>
<p>Remember to change this strings <code>ModelToMonitor</code> and <code>app_name</code>.</p>
<p>Usage :</p>
<p><code>./manage your-controls-command --log</code></p>
Freely redistributableNonceField for disabling autocompletion
2009-02-22T08:35:59.504565-06:00johnnoonehttps://djangosnippets.org/snippets/1335/<p>For disabling autocomplete and security purpose, this snippet defines a CharField with a randomness name for each request of the form.
</p>
<p>This is useful for turning off autocomplete for credit card input in all browsers, without breaking the xhtml validation.
</p>
<ul>
<li>
<a href="https://wiki.mozilla.org/The_autocomplete_attribute_and_web_documents_using_XHTML#Security">https://wiki.mozilla.org/The_autocomplete_attribute_and_web_documents_using_XHTML#Security</a>
</li>
<li>
<a href="http://en.wikipedia.org/wiki/Cryptographic_nonce">http://en.wikipedia.org/wiki/Cryptographic_nonce</a>
</li>
</ul>
Freely redistributable