Just a quick solution to import product data from a excel spreadsheet to satchmo.
Supports
* hierarchical and multi categories
* product attributes
* product variations (configurable product, options)
* product price
* product image
Since django insists on throwing a DoesNotExist rather than just returning a None from the far side of a null OneToOneField, I wrote this to have a sane way of getting those fields out without having to try/except all over in my code.
Sometimes you want to add CSS classes to HTML elements that are generated by Django using their `__unicode__` representation, eg. you can output a form field with `{{ form.name }}`, but if you would like to add a certain CSS class to the outputted input or select tag you would have to assort to plain HTML.
Using this filter you can simply do something like `{{ form.name|add_class:"span-4" }}` which will render an input like `<input type="..." name="..." class="span-4`.
This small decorator will trace the execution of your code every time it enters or exits a decorated function (by thread) and will insert appropriate indent into the log file along with exception information.
Enables convenient adding of fields, methods and properties to Django models.
Instead of:
User.add_to_class('foo', models.CharField(...)
User.add_to_class('bar', models.IntegerField(...)
you can write:
class UserMixin(ModelMixin):
model = User
foo = models.CharField(...)
bar = models.IntegerField(...)
Shows difference between two json like python objects. May help to test json response, piston API powered sites...
Shows properties, values from first object that are not in the second.
Example:
import simplejson # or other json serializer
first = simplejson.loads('{"first_name": "Poligraph", "last_name": "Sharikov",}')
second = simplejson.loads('{"first_name": "Poligraphovich", "pet_name": "Sharik"}')
df = Diff(first, second)
df.difference is ["path: last_name"]
Diff(first, second, vice_versa=True) gives you difference from both objects in the one result.
df.difference is ["path: last_name", "path: pet_name"]
Diff(first, second, with_values=True) gives you difference of the values strings.
Supposing you wanted to use a generic view, but you wanted to pass something over POST to show up in the resultant template. Perhaps you're creating a new object, and you want to pre-populate some hidden fields.
`urlpatterns = patterns('django.views.generic.create_update',
url(r'^obj/new$', view_post_vars_to_context(create_object), {'form_class': ThingForm, 'template_name': 'thing/new_thing.html', 'post_vars_to_context':{'obj_id':'objID'}, extra_context: {:this":"that"}}),
)`
Now objID will be a variable in your template, with the value passed via POST in the variable obj_id.
This is good for generic views, but there's no reason you couldn't use it for your own views if you really wanted, as long as you had an "extra_context" parameter.
For security, since POST variables aren't cleansed automatically, this only accepts values of "_" and "-". If you feel confident, you can alter this to your needs.
If your URL pattern looks like:
`urlpatterns = patterns('django.views.generic.create_update',
url(r'^obj/(?P<obj_id>\d+)/new_thing$', create_object, {'form_class': ThingForm, 'template_name': 'thing/new_thing.html', extra_context: {:this":"that"}),
)`
You will receive an error, because the create_update view doesn't have a parameter called "obj_id". Supposing you want that variable in the URL, and furthermore let's say you wanted to do something with it in the template. With this function, you can wrap the view, and add the parameter capture_to_context, which maps URL variables to template variables:
`urlpatterns = patterns('django.views.generic.create_update',
url(r'^obj/(?P<obj_id>\d+)/new_thing$', view_url_vars_to_context(create_object), {'form_class': ThingForm, 'template_name': 'thing/new_thing.html', 'url_vars_to_context':{'obj_id':'objID'}, extra_context: {:this":"that"}}),
)`
Now objID will be a variable in your template, with the value given to obj_id.
This is good for generic views, but there's no reason you couldn't use it for your own views if you really wanted, as long as you had an "extra_context" parameter.
The default traceback sent by email when an error occurs, usually gives too little information comparing it to the error page in the DEBUG mode. This snippet guerilla-patches error handling and sends by email the same information as you would see in DEBUG mode.
To set it up, add the snippet to any `models.py` of an installed app.
(I wonder why this hasn't been implemented in the core)
Prevents error flooding on high traffic production sites. Particularly useful to prevent clogging email servers etc.
See [discussion](http://groups.google.com/group/django-developers/browse_thread/thread/1dabc9139dd750ca/1d86fdca23189a7d?lnk=gst&q=error#1d86fdca23189a7d) and [closed ticket](http://code.djangoproject.com/ticket/11565).
Uses memcache if it can, or falls back to local, in-process memory where unavailable (down, etc).
Tweak to your needs using setting ERROR_RATE_LIMIT (seconds).
Requires Django 1.3+ or trunk r13981+
Very simple python class for querying Google Geocoder. Accepts a human-readable address, parses JSON results and sets lat and lng. (Full JSON results are stored to `results` property of GoogleLatLng for access to other attributes.)
This could easily be expanded to include the XML output option, etc.
**Requires PycURL and simplejson.**
Example:
>>> location = "1600 Amphitheatre Parkway, Mountain View, CA 94043"
>>> glatlng = GoogleLatLng()
>>> glatlng.requestLatLngJSON(location)
>>> print "Latitude: %s, Longitude: %s" % (glatlng.lat, glatlng.lng)
Latitude: 37.422782, Longitude: -122.085099`
** Do not forget the usage limits, which include request rate throttling, otherwise, Google might ban you. **
===
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.
Add the following to settings.py:
SERIALIZATION_MODULES = {
'csv' : 'path.to.csv_serializer',
}
Examples of usage:
$ python manage.py dumpdata --format csv auth.user > users.csv
from django.core import serializers
csvdata = serializers.serialize('csv', Foo.objects.all())
To run the regression tests distributed with the Django tarball:
$ cd /path/to/Django-1.2.x/tests
$ PYTHONPATH=/path/to/myproject ./runtests.py --settings=myproject.settings serializers_regress