Package: django-snippetscream
Django Snippets CreamDjango app packaging the best snippets found onhttp://djangosnippets.orgIncluded Snippets186. Profiling MiddlewareDisplays hotshot profiling for any view. Add a “prof” key to the query string by appending ?prof (or &prof=) and you’ll see the profiling results in your browser, i.e.http://yoursite.com/yourview/?profOriginal Snippet -http://djangosnippets.org/snippets/186/To enable addsnippetscream.ProfileMiddlewareto yourMIDDLEWARE_CLASSESsetting, i.e.:MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + ('snippetscream.ProfileMiddleware',)963. RequestFactoryEasily create mock request objects for use in testing.Original Snippet -http://djangosnippets.org/snippets/963/Example:from snippetscream import RequestFactory
request = RequestFactory().get('/')1031. Model Inheritance With Content TypeSupplies a model class aware of its child models, allowing for child class objects to be resolved from parent objects.Original Snippet -http://djangosnippets.org/snippets/1031/Example:=== example usage in interpreter ===
>>> from snippetscream import PolyModel
>>> class TrunkModel(PolyModel):
...     pass
>>> class LeafModel(TrunkModel):
...     pass
>>> leaf_obj = LeafModel()
>>> leaf_obj.save()
>>> trunk_obj = TrunkModel.objects.get(id=leaf_obj.id)
>>> trunk_obj
... <TrunkModel: TrunkModel object>
>>> trunk_obj.as_leaf_class()
... <LeafModel: LeafModel object>1378. Resolve URLs to View NameSupplies a resolve_to_name function that takes in a path and resolves it to a view name or view function name (given that the path is actually defined in your urlconf).Original Snippet -http://djangosnippets.org/snippets/1378/Example:=== urlconf ====
urlpatterns = patterns(''
    url(r'^some/url/$', 'app.views.view'),
    url(r'^some/other/url/$', 'app.views.other.view', name='this_is_a_named_view'),
)

=== example usage in interpreter ===
>>> from snippetscream import resolve_to_name
>>> print resolve_to_name('/some/url/')
'app.views.view'
>>> print resolve_to_name('/some/other/url/')
'this_is_a_named_view'1875. Auto-create Django Admin User During syncdbThis avoids the frustrating step of having to set up a new admin user every time you re-initialize your database.Original Snippet -http://djangosnippets.org/snippets/1875/To enable addsnippetscreamto yourINSTALLED_APPSsettings and create the following setting:CREATE_DEFAULT_SUPERUSER = True2240. CSV SerializerSupplies CSV serialization for models. Can be used via thedumpdata/loaddatamanagement commands or programmatically using thedjango.core.serializersmodule. Supports multiple header lines and natural keys.Original Snippet -http://djangosnippets.org/snippets/2240/To enable addsnippetscream.csv_serializerto yourSERIALIZATION_MODULESsetting, i.e.:SERIALIZATION_MODULES = {
    'csv': 'snippetscream.csv_serializer',
}Example:=== example dumpdata usage ===
$ python manage.py dumpdata --format csv auth.user > users.csv

=== example usage in interpreter ===
>>> from django.core import serializers
>>> csvdata = serializers.serialize('csv', Foo.objects.all())2536. Configurable defaults for contrib.sites default Site during syncdbModelled after #1875, this provides a more sensible default for theSiteobject created during the first pass ofsyncdb(default domain oflocalhost:8000). It means that the admin’sview on sitebutton will work
automagically, amongst other things.Original Snippet -http://djangosnippets.org/snippets/2536/To enable addsnippetscreamto yourINSTALLED_APPSsettings and create the following setting:CREATE_DEFAULT_SITE = TrueIf you’d like to customise the defaultSiteyourself, you can specifyDEFAULT_SITE_DOMAINandDEFAULT_SITE_NAMEsettings, e.g:DEFAULT_SITE_DOMAIN = 'my.site.com'
DEFAULT_SITE_NAME = 'My Site'Optionally you can manually call thecreate_default_sitemethod and passnameanddomainarguments which take precedence over the settings parameters.AuthorsAll credit goes to the various super generous snippet creators and comment contributors. Thanks for sharing!Maintained ByShaun Sephton186. Profiling Middlewareudfalkso963. RequestFactorysimonakalhola1031. Model Inheritance With Content Typecrucialfelixtygielzchaosem1378. Resolve URLs to View NameUloPeaehlkefahhem1875. Auto-create Django Admin User During syncdbstaticoBrandon Craig Rhodes2240. CSV serializerstringify2536. Configurable defaults for contrib.sites default Site during syncdb#. chrischambers
Changelog
=========0.0.7 (2011-09-19)Removed monkeypatching on and added test for 1378.Included 2536 -Configurable defaults for contrib.sites default Site during syncdb0.0.6 (2011-09-01)Pep8.Don’t fail without profiler.0.0.5 (2011-07-06)Included 2240 -CSV serializer0.0.4Included 186 -Profiling Middlware0.0.3Included 1875 -Auto-create Django Admin User During syncdb0.0.2Included 1031 -Model Inheritance With Content Type0.0.1Initial release