This view will serve media files from all media subdirectories of apps in your INSTALLED_APPS setting. Save the view as media.py in your django site folder and add to urls.py:
if settings.DEBUG:
urlpatterns += patterns('',
(r'^media/(?P<appname>\w+)/(?P<path>.+)$', 'devel_site.media.serve_apps')
)`
Now suppose your installed apps setting looks like:
INSTALLED_APPS = ('org.myself.myapp', ...)
Then a request to http://localhost/media/myapp/directory/file.css will serve the file org/myself/myapp/media/directory/file.css.
Special thanks to the author of snippet 769 who provided most of the code for this snippet.
Major differences:
1.Simpler/better handling of "extends" block tag
2.Searches If/Else blocks
3.Less code
4.Allow list of templates to be passed which is closer to the behavior of render_to_response
This is an (overly simple) example of how to manually delete something from the cache.
Usage is simply `delete_url_cache('/some_view/')`
This most likely doesn't work when using Vary headers but does seem to work fine for the most general case of simply needing to programmatically flush the cache after certain actions.
This template tag does two things needed to display content from something like a TextField wrapped with TinyMCE in Flash's htmlText component:
1. Replace `<p>` tags with `<br />`
2. Strip all occurances of `\n`
If you want to resize transparent PNGs with the `{% thumbnail %}` templatetag, they'll sometimes get an ugly black background that looks even more ugly on a white background. This processor puts the image on a white background. You can simply change the background color by replacing `white` with any other color.
To use this filter simple put the following two lines of code in your settings file:
from sorl.thumbnail.defaults import PROCESSORS as THUMBNAIL_PROCESSORS
THUMBNAIL_PROCESSORS = ('path.to.white_background',) + THUMBNAIL_PROCESSORS
Put this code and import it where you define your ModelAdmin-classes.
# typical admin.py file:
from django.contrib import admin
from foo.bar import ReadOnlyAdminFields
class MyModelAdmin(ReadOnlyAdminFields, admin.ModelAdmin):
readonly = ('field1', 'field2',)
A simple helper function that clears the cache for a given URL, assuming no headers. Probably best used when wired up to a model's post_save event via signals. See [message to django-users mailing list](http://groups.google.com/group/django-users/msg/b077ec2e97697601) for background.
**Step 1**
Save somewhere in your project directory
**Step 2**
Add to your settings.py
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
'utils.debug.UserBasedExceptionMiddleware',
)
Normal users will get your 500.html when debug = False, but If you are logged in as a super user then you get to see the stack trace in all its glory.
A FileField Widget that displays an image instead of a file path if the current file is an image. Could also be used with sorl.thumbnail to generate thumbnail images.
**Example**
class FileUploadForm(forms.ModelForm):
upload = forms.FileField(widget=AdminThumbnailWidget)
class Meta:
model = FileUpload
class FileUploadAdmin(admin.ModelAdmin):
form = FileUploadForm
admin.site.register(FileUpload, FileUploadAdmin)
This snippet uses the [django-environment project](http://code.google.com/p/django-environment/). Django-environment is used to provide "environment variables" to django apps.
This snippet uses the [django-environment project](http://code.google.com/p/django-environment/). Django-environment is used to provide "environment variables" to django apps.
Creates a message list, but unlike the messaging system in django.contrib.auth it is session-persistent and can therefor be displayed after a redirect.