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
From time to time I often have to work with a site that has two domain names. This can be an issue when dealing with mapping api keys so to solve this problem I whipped up a decorator function that allows a preferred domain to be enforced on a per view basis.
It wouldn't be too much to take this onto a middleware, but for my usage I just wanted a per view granularity and a decorator function suited my needs quite nicely.
Example Usage of [Very basic CouchDB Paginator](http://www.djangosnippets.org/snippets/1208/)
An Example setup of CouchDB with django can be found at:
[Eric Florenzanos post about django+couchdb](http://www.eflorenzano.com/blog/post/using-couchdb-django/)
This is a very basic paginator for CouchDB ViewResults.
It's usage is similar to the django one.
**CouchPaginator** is almost like the django version with one exception: It's constructor needs an additional argument `pages_view` which is either a reduce result or an integer which holds the total number of objects across all pages.
*Example Map/Reduce for pages*:
> map = function(doc) {
> if(doc.type=="application" || doc.type==\"inquiry\"){
> emit([doc.meta.user.toLowerCase(), doc.type], 1);
> }
> reduce = function (doc, value, rereduce){
> return sum(value);
> }
**SimpleCouchPaginator** is much simpler and needs no total number and can only paginate by "next" and "previous" page. Use this if you don't have an reduce view which tells you the amount of total object.
An Example setup of CouchDB with django can be found at:
[Eric Florenzanos post about django+couchdb](http://www.eflorenzano.com/blog/post/using-couchdb-django/)
[See example usage](http://www.djangosnippets.org/snippets/1209/)
All you need to do is include the file you save this as in your other templates. The css and javascript is right in the file. Fully customizable. Very easy.
Click a date to choose a single date. Click a second date to choose a range. A third click will act as a first click.
note: you also will want to customize the django template specific variables in elements with ids:
s_date
e_date
cal_month
if you change those, it's not even really django specific, but i use this in my form for time off requests at work.
`python manage.py inspectdb` allows you to generate the models from a legacy database. The generated model classes are not arranged by dependencies. When the number of tables is big, it becomes really painful to rearrange by hand.
This small script should rearrange the models for you. It doesn't solve every problem with generated models, but it makes our the process easier
In order to integrate Wymeditor with the Django filebrowser, put the code in a file, set the fb_url variable to point to your filebrowser instance and add the file to your Javascript headers:
<script type="text/javascript" src="/media/wymeditor/plugins/jquery.wymeditor.filebrowser.js"></script>
or in your admin.py:
class Media:
js = ('/media/wymeditor/plugins/jquery.wymeditor.filebrowser.js',)
Add the postInitDialog parameter to the Wymeditor initialization:
$('textarea').wymeditor({
postInitDialog: wymeditor_filebrowser
});
If you already have a postInitDialog function, you need to put a call to wymeditor_filebrowser inside that function. Then you should be able to click on the Filebrowser link to select an image.
This is a simplified rip-off of django-registration and the built-in forms and views in contrib.auth. It requires no models and is very customizable. Saving the form creates a user with an unusable password and sends a password reset email (by default, uses the password reset template too).
You must create templates/registration_form.html and the view registration_complete. I ripped this out of my site, which has a more complicated form, so I may be missing a few other things here.
FixedCharField is used similarly to CharField, but takes a length attribute, and will only accept strings with that exact length.
class Student(models.Model):
student_id = FixedCharField(length=8)
It currently only supports mysql, sqlite3, and oracle. The port to postgresql should be straightforward but I'm not sure about it so I haven't added it yet.
This is a copy-paste (plus a couple of adaptations) from my project Chango, found at http://launchpad.net/chango/, so in order to keep up with latest updates it might be a good idea to use code directly from there.
A simple template filter that detects [iPernity](http://www.ipernity.com) static URLs and creates clickable thumbnail for them. Use it with [Lightbox](http://www.huddletogether.com/projects/lightbox2/) or any other funky image overlay script.
Your HTML code may contain this:
<p>A short example <img
src="http://...ipernity..."
title="The Description" />.</p>
After applying this filter it will become:
<p>A short example <a
href="http://...large version..."
title="The Title"><img
alt="The Title"
src="http://...thumb version..."/>
</a>.</p>
Thats all! You may have a look at this: [iPernity and static URLs](http://www.ipernity.com/group/api-users/discuss/20098)
Save this file as httpauth.py. This example should help you guys out for sure.
from httpauth import *
@logged_in_or_basicauth()
def temp_view(request):
pass
Feel free to contact me in case you need help.
By [Dipankar sarkar](http://dipankar.name)
[email protected]
This solves the problem of losing sessions data when you restart memcached. So you use a different memcached instance for sessions which you rarely restart.
Use the above code and add the following to you settings.py
SESSION_ENGINE = "kwippyproject.session_backend"
SESSION_CACHE = 'memcached://127.0.0.1:11200/'
(Above assumes that your session's memcached is running on port 11200)
Feel free to contact me in case you need help.
By [Dipankar sarkar](http://dipankar.name)
[email protected]
This is form field for PDF or Microsoft Word Document (both .doc and .docx)
It will validate the file uploaded as a valid PDF and MS Word Document.
It extends a forms.FileField, so you can put all the arguments relevant to FileField.
IMPORTANT NOTE: The method of validation is actually run thru *nix OS shell command 'file', therefore,
1. only *nix system can use this class.
2. The file uploaded must be saved on disk, meaning you need to set your upload handler to use TempoaryFileUploadHandler Only.
# (i.e. put this in your settings.py)
FILE_UPLOAD_HANDLERS = (
"django.core.files.uploadhandler.TemporaryFileUploadHandler",
)
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.