Skip to main content

Django app packaging the best snippets found on http://djangosnippets.org

Project description

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

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(''
    (r'/some/url', 'app.views.view'),
    (r'/some/other/url', 'app.views.other.view', {}, '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.

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())

Authors

All credit goes to the various super generous snippet creators and comment contributors. Thanks for sharing!

Maintained By

  1. Shaun Sephton

186. Profiling Middleware

  1. udfalkso

963. RequestFactory

  1. simon

  2. akalhola

1031. Model Inheritance With Content Type

  1. crucialfelix

  2. tygielzchaosem

1378. Resolve URLs to View Name

  1. UloPe

1875. Auto-create Django Admin User During syncdb

  1. statico

  2. Brandon Craig Rhodes

2240. CSV serializer

  1. stringify

Changelog

0.0.5 (2011-07-06)

  1. Included 2240 - CSV serializer

0.0.4

  1. Included 186 - Profiling Middlware

0.0.3

  1. Included 1875 - Auto-create Django Admin User During syncdb

0.0.2

  1. Included 1031 - Model Inheritance With Content Type

0.0.1

  1. Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-snippetscream-0.0.5.tar.gz (10.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

django_snippetscream-0.0.5-py2.7.egg (21.5 kB view details)

Uploaded Egg

django_snippetscream-0.0.5-py2.6.egg (21.6 kB view details)

Uploaded Egg

File details

Details for the file django-snippetscream-0.0.5.tar.gz.

File metadata

File hashes

Hashes for django-snippetscream-0.0.5.tar.gz
Algorithm Hash digest
SHA256 3738accb8d7e29fa047422af32f34eff11bdb8bed24f8bfaedf09b2dce83ed5a
MD5 3e88650c49f69f955acc7eb684252e2f
BLAKE2b-256 7337fafa9cbc27e72d210acc78eb97a0a6902b481e81f911ab1304fbaa84bc99

See more details on using hashes here.

File details

Details for the file django_snippetscream-0.0.5-py2.7.egg.

File metadata

File hashes

Hashes for django_snippetscream-0.0.5-py2.7.egg
Algorithm Hash digest
SHA256 658eb6b74556e353c210d9a7ad1573490ea4b621fd77e73252825976246b0ec1
MD5 deeca1639e3bccf99a156310ac139c44
BLAKE2b-256 0a0f475be8eef3fbc6636b9af82fb237662899f25ed333ac6ed43df95ef371f7

See more details on using hashes here.

File details

Details for the file django_snippetscream-0.0.5-py2.6.egg.

File metadata

File hashes

Hashes for django_snippetscream-0.0.5-py2.6.egg
Algorithm Hash digest
SHA256 4362fd8811fd3d74062c421336fb8df8289ced270e21d178f3e91d8705148599
MD5 c4942f9d6ec7ec59f24a7e6a1b0eeab3
BLAKE2b-256 8f89a42a182e1bac74181f4ee76305afae42343f3d28ca86441e65c878c79d2b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page