djangosnippets.org: Latest snippets posted by bthomashttps://djangosnippets.org/users/bthomas/2009-07-30T09:17:06.049126-05:00bthomasS/MIME Encrypted E-mail
2009-07-30T09:17:06.049126-05:00bthomashttps://djangosnippets.org/snippets/1659/<p>Requires the M2Crypto module. See <a href="http://sandbox.rulemaker.net/ngps/m2/howto.smime.html">http://sandbox.rulemaker.net/ngps/m2/howto.smime.html</a> for more information on using M2Crypto to create S/MIME email. This could also be adapted to allow signing, or sign+encrypt, but currently only encrypts.</p>
<p>Use just like <code>EmailMessage</code>, except takes an extra parameter <code>cert</code>, which is the path to the recipient's public …</p>
Freely redistributableTemporary admin messages (MOTD)
2009-02-05T08:40:55.987704-06:00bthomashttps://djangosnippets.org/snippets/1310/<p>This small app can display messages to users after they login and before they get to the normal landing page. This can be useful for displaying maintenance notices, information on new features, or a one-day-sale on shoes.</p>
<p>To redirect to the MOTD view after login, change:</p>
<p><code><input type="hidden" name="next" value="{{ …</code></p>
Freely redistributableHTTP basic auth decorator
2009-02-02T09:21:17.392354-06:00bthomashttps://djangosnippets.org/snippets/1304/<p>This is a somewhat simpler alternative to <a href="http://www.djangosnippets.org/snippets/243/">http://www.djangosnippets.org/snippets/243/</a> that does not return a 401 response. It's meant to be used along with the login_required decorator as an alternative way to authenticate to REST-enabled views.</p>
<p>Usage:</p>
<pre><code>@http_basic_auth
@login_required
def my_view(request):
...
</code></pre>
<p>If an HTTP basic auth header is provided, the request …</p>
Freely redistributableUse MEDIA_URL in 500 error page
2008-11-17T15:20:13.832996-06:00bthomashttps://djangosnippets.org/snippets/1199/<p>The default server_error view uses Context instead of RequestContext. If you were depending on a context processor to make MEDIA_URL available in your templates, your 500.html template will not render with the correct image paths. This handler adds MEDIA_URL (and nothing else) back to the context that is sent to …</p>
Freely redistributableSimple E-mail registration
2008-11-17T15:07:22.194310-06:00bthomashttps://djangosnippets.org/snippets/1198/<p>This is a simplified rip-off of django-registration and the built-in forms and views in contrib.auth. It requires no models and is very customizable. Saving the form creates a user with an unusable password and sends a password reset email (by default, uses the password reset template too).</p>
<p>You must create …</p>
Freely redistributableAdd site info to request context
2008-11-17T14:35:58.925128-06:00bthomashttps://djangosnippets.org/snippets/1197/<p>Sometimes you want to generate a <strong>really</strong> absolute URL, but the built-in url tag only generates a URL relative to the current domain. This context processor adds the extra information needed to the request context, so you can generate an absolute URL in a template like so:
</p>
<p><code>{{ protocol }}://{{ …</code></p>
Freely redistributable