This test runner is invoked with its own command:
./manage.py quicktest {usual test args follow}
this creates a test database if it needs to and then DOES NOT delete it. subsequent uses of it start with the same database. this is for rapid test/development cycles usually running a single test. a single test can run in less than a second.
when you need to alter the schema simply use the normal ./manage.py test which will delete the old test database and create a fresh one.
it does not replace your normal test runner. it could probably be altered to even use your custom test runner.
there are improvements to be done, and it will be included with a small testy app soon.
This is my first snipplet. With this, you can manage your models in console using ncurses Dialog or Whiptail or XDialog. Models are auto-discovered. You can browse, edit, add and delete models. Bugreports very welcome.
This snippet is a replacement views.py for [SOAP views with on-demand WSDL generation](http://www.djangosnippets.org/snippets/979/)
It iterates over your installed apps looking for web_service.py in each one, any methods decorated with @soapmethod within web_service.py will automatically be imported into the local namespace making them visible in the WSDL.
It will blindly override local objects of the same name so it's not very safe (could do with some more error checks) but it works very well.
In-browser testing frameworks (I'm using [Windmill](http://www.getwindmill.com/)) have trouble testing file uploads because javascript's security policy prevents them from setting the value of file input fields. Instead the tests must issue some sort of "fake" file upload request, but implementing this on an ad-hoc basis quickly gets ugly.
This middleware is designed to support fake file uploads as transparently and as thoroughly as possible. For example, it is careful to properly trigger any file upload handlers so that things like upload progress reporting will work correctly. It can also simulate a slow file upload by sleeping between reads from the file.
From the client-side point of view, each input field of type "file" has a similarly-named hidden field automatically prepended. Test scripts can simply set the value of this hidden field to trigger a fake upload, rather than having to set the value of the file input field itself.
Automatically adds filter methods to your objects manager based on their display name.
class Foo(models.Model):
MOO_CHOICES=((1,'foo'),(2,'bar'))
moo = models.IntegerField(choices=MOO_CHOICES)
objects = ChoiceFilterManager('moo',MOO_CHOICES)
Foo.objects.foo()
Foo.objects.bar()
### Simple wiki with MediaWiki and Markdown Support
Once you install the mwlib you can use mwit to convert Mediawiki markup to HTML. I am include the model that uses it to hopefully provide a good example. I maintain a version and only one copy of each wiki entry in the main table and archive replaced markup into another table, you will need to create the archive model or remove that section of code. The line ending changes in mwit are so that it will work with IE.
**A Magick PIL**
I used to do my image conversions with ImageMagick and system calls back in my PHP days. With Django PIL is the obvious choice for most image stuff, but frustrated by the lack of a proper unsharp mask function for PIL I found some code in the bits and pieces of documentation for PythonMagick. (yes I know, Kevin Cabazon wrote PIL_usm, but I could not get it to work, probably due to my inexperience. Anyway, this code makes it easy to convert back and forth from PIL to PythonMagick (maybe not such a good idea on a memory tight high loaded production server, but no problem on my private server (Pentium-M @ 1.8 Ghz with 1 GB Mem.)
**usage:**
usm takes a PIL image object. Radius and sigma is in pixels, amount 1 compares to 100% in photoshop, threshold 0.004 ~ (1/256) compares to 1 in photoshop: I'm using r=1,s=0.5,a=0.8,t=0.016 for roughly 800x600 images created from 3000x2000 (6MP) images. Experiment for your own preferences.
Some times I want to change the `owner` of an object to another user - problem is the object often has a lot of other objects pointing to them - I also want to update those fields.
This is a generic snippet for doing just that!
For instance:
change_owner(obj, new_owner_id):
return update_related_field(obj, new_owner_id, field="user")
The utility of a login script is self-evident. As I learned about Django's built-in user authentication features, I whipped up this script and figured that I'd post it here. I am by no means an expert and would appreciate any constructive criticism. However, per the rules of this site, this is working code and not work in progress.
Thanks
Also: I wrote a blog post explaining the script for those who are interested: http://bit.ly/bwIL
A simple view used to manage the page cache stored in the database (here Postgresql in the django_cache table, you also have to set correctly CACHE_TABLE_OID, by the OID of the cache table (you can get it in PgAdmin)
This middleware will put the sessionid in every place that it might be needed, I mean, as a hidden input in every form, at the end of the document as a javascrit variable to allow the AJAX request use it and of course as a GET variable of the request.
To make it work correctly the MIDDLEWARE_CLASSES tuple must be in this order:
`
'CookielessSessionPreMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'CookielessSessionPosMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
`
Hope it work for someone else out there.
This is a bastardisation of a few of the Amazon s3 file uploader scripts that are around on the web. It's using Boto, but it's pretty easy to use the Amazon supplied S3 library they have for download at [their site](http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134).
It's mostly based on [this](http://www.holovaty.com/blog/archive/2006/04/07/0927) and [this](http://www.davidcramer.net/code/112/writing-a-build-bot.html).
It's fairly limited in what it does (i didn't bother os.walking the directory structure), but I use it to quickly upload updated css or javascript. I'm sure it's a mess code wise, but it does the job.
This will first YUI compress the files, and then gzip them before uploading to s3. Hopefully someone might find this useful. It will also retain the path structure of the files in your MEDIA_ROOT directory.
To use it, set up your Amazon details, download the [YUI Compressor](http://developer.yahoo.com/yui/compressor/), and then enter the folder you wish to upload to s3, and basically run the script - python /path/to/s3_uploader.py
Originally posted by [Leah Culver on her blog](http://leahculver.com/2008/11/25/couchdb-documents-python-objects/).
This allows you to convert a CouchDB document into a python object and work on CouchDB fields as if they were properties of a python object.
Save a filter in admin app
Example:
http://localhost:8000/admin/org/registrationprofile/?title__exact=Dr&ot=asc&o=4&speciality__exact=gynaecology
you can save this path org/registrationprofile/?title__exact=Dr&ot=asc&o=4&speciality__exact=gynaecology
as your filter with name like "DrGynecologySortedCyty" and then select this filter from selectbox
include JavaScript file FilterManager.js and jQuery in all admin templates.
=== Install ===
1. Add this in header of base.html for contrib.admin
You can download this files from
http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.6.min.js
2. Change path for your model that you will save in javaScript file FilterManager.js
Example:
/admin/org/registrationprofile/
3. Add models and views. see code
You're looking at the most-bookmarked snippets on the site; if you'd like to help useful snippets show up here, sign up for an account and you'll get your own bookmarks list.