Address model
This is standart address model. Must match US / GB / French address and other... Specifics locales fields are notice by comments.
- model
- address
This is standart address model. Must match US / GB / French address and other... Specifics locales fields are notice by comments.
Much stolen from base `truncate_html_words`. The difference is that this filter takes a number of characters as its argument and truncates to the nearest word boundary less than that count, rather than specifying a number of words.
I'm using Django 0.96 for a project, and the url tag does not have all the capabilities I need. I want a way to persist all or some of the GET parameters between requests. I also want a way to add to the current url a list of extra parameters, or nullify certain parameters. In this snippet I am defining 2 tags ... link_persist and link_add. It only works with Django 0.96, as the API changed ... but maybe a good soul can fix it for 1.0, as I haven't had any time available. A tip for usage: if you specify a parameter as being the empty string, or None, the parameter will be removed from the link. When you specify a parameter already available in GET, it will replace it.
I couldn't find a Python implementation of this, so I threw this class together real quick. This will let you share "private" files on S3 via a signed request. It will also have an expiration on the link, so it is only valid until a certain time period. Example Usage: s3 = SecureS3('AWS_ACCESS_KEY', 'AWS_SECRET_ACCESS_KEY') s3.get_auth_link('your_bucket', 'your_file') That would return your secure link. eg, http://your_bucket.s3.amazonaws.com/your_file?AWSAccessKeyId=AWS_ACCESS_KEY&Expires=1226198694&Signature=IC5ifWgiuOZ1IcWXRltHoETYP1A%3D
A subclassed version of the standard Django Paginator (django.core.paginator.Paginator) that automatically caches pages as they are requested. Very useful if your object list is expensive to compute. MIT licensed.
This is an override the save method of our Photo model. This new save method essentially takes the image, thumbnails it into our various sets of dimensions (for … in self.IMAGE_SIZES…), and save each one (into its own ImageField) before finally call the overwritten method to save the original image. Yes, the dimensions are hardcoded, and there is currently not a way to regenerate them in different sizes, but one shouldn't be that hard to come up with, because you just could just load each photo object to regenerate, then save it again (or something along those lines). mattpdx helped a lot with figuring out this code.
A Textarea widget which appends basic Textile formating instructions in the same way Basecamp's Writboard product displays some basic helper markup alongside the edit area.
Most of the time when I need to iterate over Whatever.objects.all() in a shell script, my machine promptly reminds me that sometimes even 4GB isn't enough memory to prevent swapping like a mad man, and bringing my laptop to a crawl. I've written 10 bazillion versions of this code. Never again. **Caveats** Note that you'll want to order the queryset, as ordering is not guaranteed by the database and you might end up iterating over some items twice, and some not at all. Also, if your database is being written to in between the time you start and finish your script, you might miss some items or process them twice.
I updated [MarkdownTextField](http://www.djangosnippets.org/snippets/882/) to have some choices in markup. It currently support for Markdown, Textile, Plain Text, and Plain HTML. It will add `%s_html` for the complied HTML and `%s_markup_choices` for a drop down of markup choices. Usage: class MyModel(models.Model): description = MarkupTextField()
This script generates an [GraphViz](http://www.graphviz.org/) graph of your database structure from your django models. See the usage if the file underneath the license.
Works exactly like the standard "extends" tag but enables one to fallback on a default template. This tag is LIMITED, as it falls back to the next template with the same name that DOES NOT contain "extends_default" (does NOT simulate full inheritance, just a single level). A partial solution to problems like http://jeffcroft.com/blog/2008/aug/05/default-templates-django/. MIT licensed.
Just a quick hack for a Controller style pattern. Similar to the approach taken in django.contrib.admin views things this breaks: 1. {% url %} and reverse() 2. validation provided by regex urlpatterns
Decorator for django.views.static.serve to serve static files as attachments, with 'application/octet-stream' mime-type
belongs in a model with datetimefields "end_time" and "start_time" (change as needed) returns float rounded to the next highest quarter hour
Django's serializer has some limitations which makes it a bit of a pain to use. Basically it will ignore any atributes that have been added to a model object. The code below is for an alternative serializer. This version allows you select what attributes will be serialized on a per object basis. It also allows you to either serialize the data into json or xml. The original json encoder was written by [Wolfram Kriesing](http://wolfram.kriesing.de/blog/) Example Usage: dumper = DataDumper() dumper.selectObjectFields('class_name',[...fields...]) dumper.selectObjectFields('class_name',[...fields...]) dumper.dump(model_instance,'xml') dumper.dump(model_instance,'json') dumper.dump(queryset,'xml')
2955 snippets posted so far.