Login

All snippets

Snippet List

OracleAuthBackend

This code uses oracle as an authentication back end. It creates a new connection to the db and attempts to login. If successful it will then create an upper case User account with _ORACLE appended to the username. My urls.py call: from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}), ) My setting.py specific settings: AUTHENTICATION_BACKENDS = ( 'oracleauth.views.OracleAuthBackend', ) LOGIN_URL = '/accounts/login/' ORACLE_CONNECT = 'database-host:1521/database' DEBUG=True

  • authentication
  • oracle
  • login
  • auth
  • backend
Read More

EmailListField for Django

A simple Django form field which validates a list of emails. [See this at my blog](http://sciyoshi.com/blog/2009/aug/08/emaillistfield-django/)

  • fields
  • forms
  • email
  • form
  • field
  • email-list
Read More

Redirect view based on GEO

Wanted a neat way to redirect views based on GeoIP determined criteria, from HTTP_REFERER. Decorator approach seemed the best way to make it straightforward to redirect views. To use, installed the Max Mind Python GeoIP API : http://www.maxmind.com/app/python

  • view
  • redirect
  • geoip
Read More

Manager for multiple database connections

A Django model manager capable of using different database connections. Inspired by: * [Eric Florenzano](http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/) * [Kenneth Falck](http://kfalck.net/2009/07/01/multiple-databases-and-sharding-with-django) There's a more detailed version in Portuguese in my blog: [Manager para diferentes conexões de banco no Django](http://ricobl.wordpress.com/2009/08/06/manager-para-diferentes-conexoes-de-banco-no-django/)

  • multiple
  • manager
  • database
  • connection
  • databases
  • connections
Read More
Author: rix
  • 0
  • 6

UsernameField (for clean error messages)

This is a username field that matches (and slightly tightens) the constraints on usernames in Django's `User` model. Most people use RegexField, which is totally fine -- but it can't provide the fine-grained and user friendly messages that come from this field.

  • fields
  • forms
  • user
  • auth
  • form
  • field
  • username
  • users
  • authorization
Read More

SQL Log To Console Middleware

When running the Django development server, this middleware causes all executed SQL queries to get printed out to the console. This is based on [Snippet 161](http://www.djangosnippets.org/snippets/161/). The big difference is that 161 logs by adding stuff to your response text, which isn't very convenient IMO.

  • sql
  • middleware
  • log
  • debug
  • logging
  • console
Read More

@url decorator improvements

A slight modification (and, I think, improvement) of the URL decorator found in [snippet 395](http://www.djangosnippets.org/snippets/395/). What's different between this snippet and 395? 1. We use `django.conf.urls.defaults.url()` when adding patterns 2. We support arbitrary arguments to the `url()` method (like `name="foo"`) 3. We _do not_ support multiple url patterns (this didn't seem useful to me, but if it is I can add it back.)

  • urls
  • url
  • decorator
  • decorators
  • urlpatterns
Read More

Persistent Params Decorator

This snippet helps preserving query parameters such as page number when the view perform redirects. It does not support hooking templates and contexts currently.

  • pagination
  • url
  • argument
Read More

Base64Field: base64 encoding field for storing binary data in Django TextFields

This Base64Field class can be used as an alternative to a BlobField, which is not supported by Django out of the box. The base64 encoded data can be accessed by appending _base64 to the field name. This is especially handy when using this field for sending eMails with attachment which need to be base64 encoded anyways. **Example use:** class Foo(models.Model): data = Base64Field() foo = Foo() foo.data = 'Hello world!' print foo.data # will 'Hello world!' print foo.data_base64 # will print 'SGVsbG8gd29ybGQh\n'

  • django
  • model
  • field
  • base64
  • blob
  • base64field
Read More

automatic urlpattern creator

This method creates urlpatterns based on view functions that have 'request' as their first parameter. See docstring for details.

  • url
  • urlconf
  • patterns
  • auto
  • urlpattern
Read More

Cookieless Session Decorator

Although many people have already posted cookieless session middlewares and related stuffs, but this one is just for only required views. You can use this as a view decorator like: @session_from_http_params @login_required def your_view(request): ... This is very useful for those who use SWFUpload. Flash has a bug with sending cookies properly, so SWFUpload offers an workaround -- session key as a POST parameter.

  • session
  • decorator
  • cookieless
Read More

email rendered via javascript (trick spam crawlers)

The proper looking email links rendered to the browser are not in the source code that way, and are rendered by javascript, so robots can't extract it. Its a trick way to have the email displayed properly without getting spamed as a result. Unless the robots are getting smarter, this has worked for me thus far.

  • template
  • email
Read More

Choices helper

A quick and dirty helper for model field `choices`. It's not perfect, but this is what I use.

  • models
  • choices
Read More

3110 snippets posted so far.