Skip to content

Instantly share code, notes, and snippets.

/*
* Simple code snippet to apply a "* denotes required field" below the Django Admin page title, ex "Change [Model]"
* It also appends a "[field name]*" to all fields that are required.
* And finally it makes all the labels for required fields nice a red.
** Note: make sure to reference jquery in templates/admin/base_site.html <script type="text/javascript" src="{{ STATIC_URL }}js/jquery-latest.pack.js"></script>
/*
A simple bash script to easily create django (trunk) virtual environments, wrapping around virtualwrapper bash script.
Inspiration from: http://justindriscoll.us/2008/11/setting-up-django-development-virtual.html
I place this script in my /usr/local/bin directory and named it dve.sh
To execute, run:
# Django virtualenv helpers
VIRTUALENV_PROJECTS=~/projects
# work on virtualenv
function workon(){
cd $VIRTUALENV_PROJECTS/$1
source bin/activate
}
# Run Django management commands
<script type="text/javascript">
$(window).load(function(){
var hash_count = 0;
$('a[href="#"]').each(function(){
if(!$(this).data("events")) hash_count++;
});
$('head').append("&lt;!-- " + hash_count + " links with # as their href --&gt;");
});
</script>
def extract_form_fields(self, soup):
"Turn a BeautifulSoup form in to a dict of fields and default values"
fields = {}
for input in soup.findAll('input'):
# ignore submit/image with no name attribute
if input['type'] in ('submit', 'image') and not input.has_key('name'):
continue
# single element nome/value fields
if input['type'] in ('text', 'hidden', 'password', 'submit', 'image'):
======================================================
Setting up Django using Apache/mod_wsgi on Ubuntu 8.10
======================================================
This article will cover setting up Django using Apache/mod_wsgi on Ubuntu
8.10. The article is targeted at a production environment, but keep in mind
this is a more generalized environment. You may have different requirements,
but this article should at least provide the stepping stones.
The article will use distribution packages where nesscary. As of 8.10 the
# Bash snippet to open new shells in most recently visited dir.
# Useful if you want to open a new terminal tab at the present
# tab's location.
#
# Put this in your .bashrc or whatever.
pathed_cd () {
if [ "$1" == "" ]; then
cd
else
We couldn’t find that file to show.