Package: django-classsettings
Just a collection of Django settings helpers.Requirements.Settings.urlconfs helpers.RequirementsPython 2.6, 2.7, 3.2, 3.3Django 1.4-1.6SettingsSettings class - adds ability to group Django settings with classes. As many text editors and IDEs indexes code symbols, with such approach you can
easily navigate to any group and any line of your settings file.classApps(Settings):defDJANGO_APPS(self):return('django.contrib.auth',...)defTHIRD_PARTY_APPS(self):return('rest_framework','south',)defOWN_APPS(self):return('app1','app2',)defINSTALLED_APPS(self):returnself.DJANGO_APPS()+self.THIRD_PARTY_APPS()+self.OWN_APPS()WithSublime Text 3pressCmd+Shift+Rand type “THIRD”.
Same thing could be done withTEMPLATE_CONTEXT_PROCESSORS,MIDDLEWARE_CLASSESetc.Config class - injects dictionary of variables into module’s scope:fromclasssettingsimportConfigclassREST_FRAMEWORK(Config):defDEFAULT_FILTER_BACKENDS(self):return('rest_framework.filters.DjangoFilterBackend',)DEFAULT_RENDERER_CLASSES=('rest_framework.renderers.YAMLRenderer',)Will result inREST_FRAMEWORK={'DEFAULT_FILTER_BACKENDS':('rest_framework.filter.DjangoFilterBackend',),'DEFAULT_RENDERER_CLASSES':('rest_framework.renderers.YAMLRenderer',)}And some decorators may be found usefull:fromclasssettingsimportSettings,from_envclassMySettingsGroup(Settings):# Will look for `EMAIL_HOST` key in `os.environ`# and use `smtp.gmail.com` if such key was not found@from_envdefEMAIL_HOST(self):return'smtp.gmail.com'# Will raise Django's `ImproperlyConfigured` exception# if such key was not found@from_envdefSECRET_KEY(self):pass# Will look for specified key@from_env(key='CUSTOM_ENV_VAR_NAME')defvariable(self):pass# Will apply `through` callable to result@from_env(through=dj_database_url.parse)defDATABASE_URL(self):return'sqlite://'urlconfs helpersSample urlconf:fromdjango.conf.urlsimportpatterns,urlimportviewsurlpatterns=patterns('',url(r'^$',views.ProjectList.as_view(),name='projects_project_list'),url(r'^create/$',views.ProjectCreate.as_view(),name='projects_project_create'),url(r'^view/(?P<pk>\w+)/$',views.ProjectDetail.as_view(),name='projects_project_view'),url(r'^update/(?P<pk>\w+)/$',views.ProjectUpdate.as_view(),name='projects_project_update'),url(r'^delete/(?P<pk>\w+)/$',views.ProjectDelete.as_view(),name='projects_project_delete'),url('^accounts/(?P<pk>\d+)/$','project.accounts.profile_info',name='users_info')url('^accounts/edit/$','project.accounts.profile_edit',name='users_edit'))is equivalent tofromclasssettings.urlsimportScope,urlimportviews## Define url pattern, views or view name prefix:## Views resolution:##   some.module, 'string' => getattr(module, 'string')#   'scope_str', 'string' => 'string'.format('scope_str', ...)#withScope(regex='^',views=views,name='projects')asroot:## Strings are formatted with `str.format`:##   value.format(value_of_parent_scope, **scope.context)## Additional context variables can be defined and used with `{variable}`withScope(name='{}_project',pk=r'(?P<pk>\w+)')asproject:# Also supportedproject['pk']=r'(?P<pk>\w+)'# For CBV `.as_view()` is called automaticallyurl('{}$','ProjectList',name='{}_list')# url => '^$', name => 'projects_project_list'url('{}create/$','ProjectCreate',name='{}_create')url('{}view/{pk}/$','ProjectDetail',name='{}_detail')url('{}update/{pk}/$','ProjectUpdate',name='{}_update')url('{}delete/{pk}/$','ProjectDelete',name='{}_delete')withScope(regex='{}accounts/',views='project.accounts',name='users',user_id=r'(?P<pk>\d+)'):url('{}{user_id}?/$','{}.profile_info',name='{}_info')url('{}edit/$','{}.profile_edit',name='{}_edit')urlpatterns=root.urlsFor urls defined outsideScope objectnative django’s url function is used.