Archive for the ‘Web Programming’ Category
“LESSjs will obsolete css”
Tuesday, August 31st, 2010“AttributeError: ‘module’ object has no attribute ‘blah’”
Wednesday, December 12th, 2007- The obvious cause of this is that the settings.py doesn’t have the directory containing blah listed in INSTALLED_APPS.
- A less obvious cause: you’ll also get this error if the directory doesn’t contain a file __init__.py.
Dojo Custom Widget namespaces in V0.4
Tuesday, January 30th, 2007Been beating my head against a brick wall trying to figure this out from the dojo documentation – here’s the answer…
http://blog.tijs.org/archives/2006/10/26/migrating-to-dojo-04/
Programmatic usage of FilteringTable
Friday, December 15th, 2006I’m using FilteringTable in a dynamically generated website, here’s how I got it working…
Thanks to Tom Trenka for the original nudge in the direction of the Dojo nightly test for the programmatic usage of FilteringTable
/*
* Dynamic Filtering Table
*/
// Creates the FilteringTable widget and ties it to an existing HTML Table.
// Call once on load.
function doCreateFilteringTable(view) {
// debugger;
dojo.io.bind({
url: "/get_columns?view="+view,
load: handleCreateFilteringTable,
error: handleError,
timeout: handleTimeout,
mimetype: "application/json"
});
}
// Populates the FilteringTable widget with live data.
// Call whenever you want.
function doUpdateFilteringTable(view) {
// debugger;
var url;
url="/get_rows?view="+view;
dojo.io.bind({
url: url,
load: handleUpdateFilteringTable,
error: handleError,
timeout: handleTimeout,
mimetype: "application/json"
});
}
function handleCreateFilteringTable(type,data,evt) {
var e;
// debugger;
try {
var table_id="tbl_"+data.view;
var widget_id=table_id; // they don't need to be the same
var table;
table=dojo.widget.createWidget(
"dojo:FilteringTable",
{
// this provides unique id for table rows
valueField:"id",
// must provide this so that we can find it again,
// otherwise random id is generated
widgetId: "tbl_"+data.view,
},
dojo.byId(table_id)
);
// add the columns
for (x in data.columns)
{
var col=data.columns[x];
table.columns.push(table.createMetaData(col));
}
// set the initial data set to be empty
table.store.setData([]);
// fetch the data
doUpdateFilteringTable(data.view);
} catch (e) {
var errstr=e.name+": "+e.message;
doLog(errstr,"error");
}
}
function handleUpdateFilteringTable(type,data,evt) {
// debugger;
var e;
/* get list of tickers and build table from them */
try {
var view=data.view;
// fill in table body
var tabledata=[];
var table;
var id;
var entry;
var x;
var col;
table=dojo.widget.byId("tbl_"+view);
for (id in data.list)
{
// construct line
var line={};
entry=data.list[id];
for (x in entry)
{
// add one cell
// This is the format expected by dojo:filteringTable
var value;
col=entry[x];
line["id"]=id;
line[col["heading"]]=col["value"]
}
// now add the row
tabledata.push(line);
}
table.store.setData(tabledata);
} catch (e) {
var errstr=e.name+": "+e.message;
doLog(errstr,"error");
}
}
In this example, the server is returning this for get_columns():
{
"columns": [
{"dataType": "String", "field": "Column1"},
{"dataType": "String", "field": "Column2"},
{"dataType": "String", "field": "Column3"},
etc...
],
other stuff...
}
and get_rows() returns this from the server:
{
"list": {
"id1": [
{"heading": "Column1", "value": 25},
{"heading": "Column2", "value": "ABC.L"},
{"heading": "Column3", "value": 395}
],
"id2": [
{"heading": "Column1", "value": 57},
{"heading": "Column2", "value": "MFXYZ.L"},
{"heading": "Column3", "value": 42}
]
}
}
(I've removed non-relevant stuff from these responses for clarity.)
Don’t use eval() for reading JSON from untrusted sites
Wednesday, November 1st, 2006Use a JSON parser instead, like this one at http://www.json.org/json.js/
Why? it protects you against malicious servers feeding you bad bad code…
Django GeoIP templatetag
Friday, October 27th, 2006I’ve published 2 template tags for use with GeoIP at geoip.py.
Hope they may be of use…
Usage:
# Templatetag get_country_name returns the client’s country code
#
# Example:
# {% ifequal get_country “GB” %}
# do something
# {% endifequal %}
# Templatetag get_country sets the given variable name
# to the client’s country code
#
# Example:
# {% get_country as my_country %}
# {% ifequal my_country “GB” %}
# do something
# {% endifequal %}
Django/Ajax: a great simple tutorial
Friday, October 27th, 2006An excellent tutorial from James Bennett for your first step into combining AJAX with Django
“A step-by-step walk through a simple AJAX form with Django backend”
How to make a Django ForeignKey optional
Friday, October 6th, 2006Looks like you need to have both blank=True and null=True to make a ForeignKey optional in a django model…
Django App Quick Start
Thursday, September 8th, 2005I wanted to start writing a Django app which was to allow a user to enter data in various tables, and then run a workflow process.
I liked the admin front-end but thought I needed to do something clever with generic views to replicate this in my own application.
So I asked this question on the django-users list
On 04/09/05, Rachel Willmerwrote: > I want to use the generic view mechanism to add/change/delete but I > don't want to have to write my own form template for each page. > > I'd like it to work just like the admin interface does. Is it > possible/sensible to hook into the admin code which seems to use > add_stage/change_stage to automatically generate the templates? Or is > there a better way of doing this? > > Any pointers welcome... > Rachel
Now I’ve read a bit more about it, the answer is of course to just use the admin interface.
django-admin.py includes a useful command “adminindex”, which will auto-generate a copy of the admin interface index page.
So generate that, and copy it into your template directory to over-ride the inbuilt one, as described in Tutorial2
Then you can modify that as you wish…
Hey presto, instant application front end that you can use as the basis for the new application…
In retrospect, this is obvious and documented in the Django tutorial. But at the time, I was thinking in terms of “admin” interface and “main” interface, and it slipped past me that I could in fact use the admin interface *as* the main interface…
That might not work too well for most web applications, but for my purposes, (a local single-user application), it will work just fine…
Rachel
Django search engine
Monday, September 5th, 2005To help me get to grips with Django quickly, I created a search engine
of the documentation.
On the off-chance this is useful to others, I made it available at http://www.hobthross.com/docs/django/phpdig/search.php
(Sorry if this does not show up as a hyperlink, WordPress appears to be chewing that up and ignoring it)