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
unique_together doesn't work with ManyToMany, yet. See: http://code.djangoproject.com/ticket/702
Here a simple test in save() that would raise a IntegrityError.
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
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/)
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.
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.
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.)
This snippet helps preserving query parameters such as page number when the view perform redirects.
It does not support hooking templates and contexts currently.
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'
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.
Template tag to obfuscate emails and other spam sensitive information.
Usage
obfuscate '[email protected]' 'Link display' 'Link title'
obfuscate '[email protected]' 'Link display'
obfuscate 'phone number'
Renders complex xhmtl compliant javascript.
May need caching as it renders a new code every time.
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.