Just put it in your python path and add it into MIDDLEWARE_CLASSES.
I know that there are a couple of snippets on this site that do something similar to this, but none of them quite suited me.
I wanted something that would indent and space the SQL so that I could differentiate it from the other output from the development server.
Also, I wanted something that would output total query execution time, which my solution does. I just hope that it's useful for someone else, too!
UPDATE: Now this should no longer get upset when running it on windows.
This is a very simple approach to "schema evolution" (Not sure if you can even call it so) - I use it for my project: [SCT](http://sct.sphene.net) and it seems to work quite nicely.
The idea is, that if you add or change your models, you add a 'changelog' attribute to your class which defines the SQL queries required to update your models. Of course this only works for one database type...
An example 'syncdb' call if a new changelog entry was detected:
kahless@localhost ~/dev/python-new/sphenecommunity/sphenecommunity $ ./manage.py syncdb
Executing module body.
2007-06-16 00: SQL Statement: ALTER TABLE "sphboard_post" ADD markup varchar(250) NULL
Detected changes - Do you want to execute SQL Statements ? (yes,no):
So if the SQL statement won't work with the database the user is currently running, he at least knows exactly what he is expected to change in his models. and he can stop automatic execution by simply entering 'no' here.
You can use this method to send information mails to the related staff members about section specific site activity. All users which explicitly permitted to 'change' given object will be informed about activity.
If you defined get_absolute_url in your model then you can simply use it like this;
`
obj=form.save()
mail2perm(obj)
`
Or you can define your custom urls ;
`
from util.mail2perm import mail2perm,domain
reply=get_object_or_404(Reply,user=request.user,pk=id)
mail2perm(reply,url='http://%s/admin/support/show/?id=%s'%(domain,reply.id))
`
Display a random quote. Just add some quotes to the app (you may want to add the administration interface options) and then load the template tag:
`{% load random_quote %}`
and then call the tag to display a random quote from the app
`{% random_quote %}`
feel free to improve it/whatever..
:)
I have not extensively test this yet. But working for templates with embedded images.
If you want to use Django template system use `msg` and optionally `textmsg` as template context (dict) and define `template` and optionally `texttemplate` variables.
Otherwise msg and textmsg variables are used as html and text message sources.
If you want to use images in html message, define physical paths and ids in tuples.
(image paths are relative to MEDIA_ROOT)
example:
images=(('email_images/logo.gif','img1'),('email_images/footer.gif','img2'))
use them in html like this:
`<img src="cid:img1"><br><img src="cid:img2">`
stripogram and feedparser modules are used for extract plain text from html message source.
If you are going to define text partition explicitly, than you can comment out line 10,11 and 48.
This module is comes from the original staticview.py from django. But when you using it, it can looks for static files in your app's subdirectory. So that you can put static files which concerned with your app in a subdirectory of the app. I should say it method only suit for developing, so if you want to deploy your application to apache, you should copy static folder to the real media folder. And if you keep the same structure of the directory, then it'll be very easy. And you can write a little script to automatically do that. But for now, I didn't have written one yet :P
How to use it in urls.py
--------------------------
Here's an example:
(r'^site_media/(.*)$', 'utils.staticview.serve', {'document_root': settings.SITE_MEDIA, 'app_media_folder':'media'}),
It seems just like the original one in django. But there is a new parameter "app_media_folder", it's used for subdirectory name of app. So your django project folder structure maybe seem like this:
/yourproject
/apps
/appone
/media
/css
/img
/js
/media
/css
/img
/js
This filter will display the time as word(s) indicating roughly the time of day ("Morning", "Afternoon", "Evening", etc). For example, the following template snippet:
Posted in the {{ post.date|fuzzy_time }} of {{ post.date|date:"F j, Y"} }}.
will result in the following (assuming `post.date == datetime.datetime(2007, 6, 13, 20, 57, 55, 765000)`):
Posted in the evening of June 13, 2007.
The terms used and breakpoints (hours only) can be rather arbitrary so you may want to adjust them to your liking. See the docs for [bisect][] for help in understanding the code. Just remember you should have one less breakpoint than periods and the first breakpoint falls at the end of the first period. The idea was inspired by [Dunstan Orchard][1], although the code is *very* different (php case statement). He uses quite a bit more periods in a day, so you might want to take a look.
[bisect]: http://docs.python.org/lib/module-bisect.html
[1]: http://www.1976design.com/blog/archive/2004/07/23/redesign-time-presentation/
I tend to have all my python code together in a 'python' directory.
e.g. a typical project layout of mine looks like:
/python
/python/myproject - project python code
/python/django - local copy of django
/python/foolib - some third party library
/media
/templates
...
Since I don't want to set the python path explicitly I just assume the 'manage.py' is in the right place and use its __file__ variable to set up the python path correctly.
I use the same trick for my settings.py for setting MEDIA_ROOT and TEMPLATE_DIRS.
This snippet is a template filter based on ["truncate letters"](http://www.djangosnippets.org/snippets/126/) only it will either truncate or pad a string to ensure the output is always a set width.
Django ImageBundle tag, an implementation of image bundle by google: http://code.google.com/p/google-web-toolkit/wiki/ImageBundleDesign. Here is how to use it: http://www.djangosnippets.org/snippets/278/
Ttemplates and filters for quoting e-mails in templates.
The `quoted_email` tag takes a template, renders it and quotes the result.
The `quote_text` filter puts one or more levels of quotes around the passed text.
A simple template filter for taking a list and humanizing it, converting:
`["foo", "bar"]` to `"foo and bar"`
`["foo", "bar", "baz"]` to `"foo, bar and baz"`
`["foo", "bar", "baz", "42"]` to `"foo, bar, baz and 42"`
Decorator adding arbitrary HTTP headers to the response.
This decorator adds HTTP headers specified in the argument (map), to the
HTTPResponse returned by the function being decorated.
Example:
@headers({'Refresh': '10', 'X-Bender': 'Bite my shiny, metal ass!'})
def index(request):
....