I ended up not needing this (there's a good reason it's in JS and not Python, but most people would probably want to do this server-side instead) but I'm stashing it here in case I need it later.
It uses jQuery for the .each() method - which is very easy to replace if you need it to work without that dependency.
Usage:
var src = generateChart({
"foo": 5,
"bar": 3,
"baz": 6
});
This code assumes your XFN field is called 'rel' in models. See the last call (addLoadEvent down the bottom) for the two lines requiring modification; otherwise, aside from the Django-styling involved, it can be used anywhere.
The accompanying model.py and admin.py information can be found here: [http://www.djangosnippets.org/snippets/1265/](http://www.djangosnippets.org/snippets/1265/).
I'm no master programmer, so feedback/comments/criticism is more than welcome.
EDIT: Fixed my esoteric dev. comments and removed references to spawning more overlords.
Use this code in *change_form.html* in your projects admin templates to add a character counter beside the input field(s) in admin to let users know how many characters they have remaining for a particular input field. The total number of characters allowed is determined by the max_length in your model for the models.CharField you're using this with.
This code is designed to add the counter after the input field, but could easily be customized to fit the style of any admin. If the number of characters remaining is 10 or less the background color changes to yellow to visually warn the user.
**Usage Examples:**
In this example only the input field with id=id_pull_quote will receive the counter:
$(document).ready(function() {
$("#id_pull_quote").counter();
});
You could also apply the counter to all input fields on a page:
$(document).ready(function() {
$("form input[@maxlength]").counter();
});
**Note:** *You have to download jQuery to your project and place the appropriate call in order for this to work. The best place to do this is in the extrahead block. I left my call in as an example but your path and file name will probably vary.*
Credit for base jQuery code goes to Brad Landis at [bradlis7.com](http://www.bradlis7.com).
Add extra form elements in your contib admin
Install
add this in header of base.html
<script type="text/javascript" src="/static/jquery-1.2.6.min.js"></script>
http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.6.min.js
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
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.
If you want to add an fckeditor for every vLargeTextField (the input class used by models.TextField) you can use this javascript.
you can load that in all admin pages overriding templates/admin/base_site.html with this:
{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}{{ title }} | {% trans "Administrative Area" %}{% endblock %}
{% block branding %}
<h1 id="site-name">{% trans "Administrative Area" %}</h1>
{% endblock %}
{% block nav-global %}{% endblock %}
{% block extrahead %}{{ block.super }}
<script src="{{media_url}}js/jquery.js" type="text/javascript"></script>
<script src="{{media_url}}fckeditor/fckeditor.js" type="text/javascript"></script>
<script src="{{media_url}}fckeditor/custom/vTextField.js" type="text/javascript"></script>
{% endblock %}
Often its useful to get error information for ajax/javascript errors happening on various clients. This can go to something like this:
# error_sink
def error_sink(request):
# post request, with event name in "event", and event data in "data"
context = request.REQUEST.get("context", "")
context = cgi.parse_qs(context)
context["data"] = cgi.parse_qs(context.get("data", [""])[0])
context["user"] = request.vuser
context["referrer"] = request.META.get('HTTP_REFERER', "referrer not set")
context = pformat(context)
send_mail(
"ajax error", context, "[email protected]",
["[email protected]",], fail_silently=True
)
return JSONResponse({"status": "ok" })
# }}}
This middleware allows you to easily include the excellent debugging tool Firebug Lite in your projects. To install it, just add the middleware class to your list of installed middleware, pretty much anywhere in the list. If DEBUG is True, and your IP address is in the list of INTERNAL_IPS, Firebug Lite will load. It will, however, only load in browsers that are **not** Firefox, as I'm assuming that you have the **real** Firebug installed in Firefox. If you don't, go install it--what's wrong with you?
Check out http://getfirebug.com/lite.html for more information.
This patch allows to open a popup to edit the selected object of either the left or right select input of a filter_horizontal or filter_vertical field, when pressing the "Insert" key.
Being a noob with general client-side issue, it's served as a patch that suits my needs. Maybe it's possible to do it cleaner by overloading the javascript methods, or get rid of the jquery dependency in order to integrate it into django trunk ... Any contribution is welcome! It's licensed under WTFPL license.
Requires jquery.
Generic Relations with django.contrib.contenttypes.generic.GenericForeignKey work well for models but the admin interface just shows the object id as an integer with no easy way to lookup the id of a new object. This jquery javascript adds a "Lookup <ContentType Name>" link next to the object id field in the admin interface.
This is done by reusing the showRelatedObjectLookupPopup() function provided with django which is used when the field is included in raw_id_fields (a little magnifying glass linked to popup object selector shows up). This essentially works the same way but changes which model's objects are shown and selected in the popup based on the ContentType selected for object_type
This is a simple fixture that is useful for many tests.
It contains the following users:
* admin
* staff
* user0
* user1
* user2
* user3
* inactive0
* inactive1
The password of every user is the same as his username, e.g.: admin/admin
with jQuery and [jQuery templates](http://plugins.jquery.com/project/jquerytemplate) you can use the django template language on the client-side with javascript.