Django Snippets Cream
Django app packaging the best snippets found on http://djangosnippets.org
Included Snippets
186. Profiling Middleware
Displays 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/?prof
Original Snippet - http://djangosnippets.org/snippets/186/
To enable add snippetscream.ProfileMiddleware to your MIDDLEWARE_CLASSES setting, i.e.:
MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + ('snippetscream.ProfileMiddleware',)
963. RequestFactory
Easily 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 Type
Supplies 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 Name
Supplies 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 syncdb
This 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 add snippetscream to your INSTALLED_APPS settings and create the following setting:
CREATE_DEFAULT_SUPERUSER = True
2240. CSV Serializer
Supplies CSV serialization for models. Can be used via the dumpdata/loaddata management commands or programmatically using the django.core.serializers module. Supports multiple header lines and natural keys.
Original Snippet - http://djangosnippets.org/snippets/2240/
To enable add snippetscream.csv_serializer to your SERIALIZATION_MODULES setting, 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 syncdb
Modelled after #1875, this provides a more sensible default for the Site object created during the first pass of syncdb (default domain of localhost:8000). It means that the admin’s view on site button will work automagically, amongst other things.
Original Snippet - http://djangosnippets.org/snippets/2536/
To enable add snippetscream to your INSTALLED_APPS settings and create the following setting:
CREATE_DEFAULT_SITE = True
If you’d like to customise the default Site yourself, you can specify DEFAULT_SITE_DOMAIN and DEFAULT_SITE_NAME settings, e.g:
DEFAULT_SITE_DOMAIN = 'my.site.com' DEFAULT_SITE_NAME = 'My Site'
Optionally you can manually call the create_default_site method and pass name and domain arguments which take precedence over the settings parameters.
Metadata
Release files for django-snippetscream 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-snippetscream-0.0.7.tar.gz | 11.9 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_snippetscream-0.0.7-py2.7.egg | Legacy Egg format | - | - | Details |
| django_snippetscream-0.0.7-py2.6.egg | Legacy Egg format | - | - | Details |
Total release size: 62.9 kB
Release files / django-snippetscream-0.0.7.tar.gz
| Download URL | django-snippetscream-0.0.7.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09e62070afb49fa7dd33124f13a7540179a22ba63bfc2af6315e5e18c97fd5f7
|
|
BLAKE2b-256 checksum How to use checksums |
864b5521e6de58738117589d19f268a1d3293b74b5bbf7e396bb1eef4dbd6fd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_snippetscream-0.0.7-py2.7.egg
| Download URL | django_snippetscream-0.0.7-py2.7.egg |
|---|---|
| Size | 25.5 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
996965c92a5b1d04843c0cebc3ae5a45e2c4bd088c82db1985a2d7e5cecc6661
|
|
BLAKE2b-256 checksum How to use checksums |
866bd8650188af76f5b8ed4083035d44263678bacecf38488a52b17ea598afc9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_snippetscream-0.0.7-py2.6.egg
| Download URL | django_snippetscream-0.0.7-py2.6.egg |
|---|---|
| Size | 25.6 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
6aba04eb4ae83570a7634b62e108aa4242848e8429ebc71f2241deefbb7f2e01
|
|
BLAKE2b-256 checksum How to use checksums |
1a854f390cdf79a2d6d77787e9c3bdee2fc0fe376aa355ef56ff965141732026
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |