Standard memcache client uses pickle as a serialization format. It can be handy to use json, especially when another component (e.g. backend) doesn't know pickle, but json yes.
Small function that i use to save files to an imagefield, the file can be either an url or a file.
This function has the following requirements.
import requests
from django.core.files import File
from django.core.files.temp import NamedTemporaryFile
from django.conf import settings
Get the awesome requests library: pip install requests
This function uses MEDIA_ROOT to know the location of the static dir, you can change that chaging the static_dir variable.
Upload an image with file-uploader from http://github.com/valums/file-uploader
and save it to disk with the snippet and also to database if you want to
I've updated the `DjangoSoapApp` class from [this popular soaplib snippet](http://djangosnippets.org/snippets/2210/) so the snippet will work properly with soaplib 2.0.
Usage is the same as before:
my_soap_service = DjangoSoapApp([MySOAPService], __name__)
1) Simply create a "management/commands" folder in one of your INSTALLED_APPS folders. Then add a "reboot.py" file in your "management/commands"
2) In settings.py, you can OPTIONALLY add:
PROJECT_NAME = 'Blah'
PROJECT_DOMAIN = 'blah.com'
These two settings will be used to create a "Site" object as well as a superuser. If you choose not to use these settings, the reboot command simply reverts to using your DATABASES[default] username as superuser.
3) Execute the command via "python manage.py reboot"
Enjoy.
Template filter to mark-up individual form fields.
Usage :
In template - {% load form_custom %}
then for a form field - {{ form.field|form_row:"default" }}
for default wrapper
or - {{ form.field|form_row:"lbl_cls=some_class_name&reqd=no" }}
to pass option args seperated by &
Optional args are :-
wrapper_cls - override default field wrapper div class name
error_cls - override default field error div class name
lbl_cls - override default label_tag div class name
label - yes/no default is yes - output label_tag
reqd - yes/no default is yes - marks up required fields as bold with label ending with *
See code for all default args.
Add this to your admin change_list.html template to replace the actions drop-down with buttons.
This is a rewritten version of snippet [1931](http://djangosnippets.org/snippets/1931/) with Django 1.3 compatibility and cleaner code. Thanks to [andybak](http://djangosnippets.org/users/andybak/) for the idea.
This snippet is greatly inspired by [@jlorich](http://djangosnippets.org/users/jlorich/)'s useful [#2436](http://djangosnippets.org/snippets/2436/).
The main difference is that I wanted to choose the names of my URL params instead of being forced into naming them "value1", "value2", etc. When reversing the URL you have to remember that the kwargs aren't friendly. By using the same names in the `filters` list, you don't have to change the way your otherwise write the URL pattern. Also it's clear throughout how you'll be filtering the QuerySet.
The other change I made was "erroring early". This avoids running the QuerySet all over again inside `object_detail()` just to have it raise an exception we could have caught the first time.
Basically the idea is to import/update model instances from a json data that closely matches the model structure (i.e. identical field names)
From my answer to this question: [http://stackoverflow.com/a/8377382/202168](http://stackoverflow.com/a/8377382/202168)
See the original question for sample data format.
Have you ever wanted a decorator that you could apply either straight-out:
@mydec
def myfun(...):
...
or with special arguments:
@mydec(special=foo)
def myfun(...):
...
? Well, decorate it with this metadecorator, and voila.
(I had this idea independently, but it's been done before as decorator_withargs: http://osdir.com/ml/python.ideas/2008-01/msg00048.html. My version is actually useful because it deals with signatures and calling directly.)
As http://www.siafoo.net/article/68 points out, the standard decorator module has too much magic: the "@decorator" decorator expects a wrapping function, not a working decorator. This module fixes that.
You're looking at the top-rated snippets currently on the site; if you'd like to contribute, sign up for an account and you'll be able to rate any snippet you see.