Skip to content

Instantly share code, notes, and snippets.

View aaronlelevier's full-sized avatar

Aaron Lelevier aaronlelevier

View GitHub Profile
@aaronlelevier
aaronlelevier / metaclass_password.py
Created July 22, 2014 16:48
metaclass example of looping through classes of password validation in python
class PluginMount(type):
"""
A Meta Class plugin mount location for a list of plugin classes.
By creating this, on all subclasses of PluginMount, python will
instantiate a plugin attribute list and maintain it for the Class
using this Meta Class.
"""
def __init__(cls, name, bases, attrs):
if not hasattr(cls, 'plugins'):
cls.plugins = []
@aaronlelevier
aaronlelevier / access.py
Created July 16, 2014 00:35
django-braces AnonymousRequiredMixin snippet b/c normal import from braces was failing for AnonymousRequiredMixin
import six
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.views import redirect_to_login
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.http import HttpResponseRedirect
from django.utils.encoding import force_text
@aaronlelevier
aaronlelevier / views.py
Created July 13, 2014 19:19
Handle 404 and 500 errors easy with this snippet in your main Django views.py file. No urls.py configuration needed.
from django.shortcuts import render_to_response
from django.template import RequestContext
def handler404(request):
response = render_to_response('404.html', {},
context_instance=RequestContext(request))
response.status_code = 404
return response
@aaronlelevier
aaronlelevier / settings_apps.py
Created March 26, 2014 13:37
A simple way in Django's settings.py to separate out default, 3rd party, and local Apps
# A simple way to break out Apps within the Django settings.py
# file in a logical way. Third party and Local Apps will vary
# based on the project.
DEFAULT_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',