AppEngine filter command – fail

I’ve been using AppEngine, almost entirely using the GQL language to return my objects.  This is a bit of a curse, and now I’m playing with gaegene’s pagination lib, I’m having to look at why I did this.

I did things this way because I couldn’t get filter() to work.  I didn’t want to waste time finding out why, so I simply avoided it.  If you had to do the why on every command in GAE, you’d never complete anything.

Anyway, I’ve now found out why:

“The name and the operator must be separated by a space, as in: age >
GAE Docs

So my filter command:

messages.all.filter(‘board=’, board)

did not work, and I should have done this:

messages.all.filter(‘board =’, board)

Rarg.

App Engine Launcher on Windows

We now have an App Engine Launcher for Windows.
I’ve just tried all morning to get it running.

I got each project appearing as a red line of text, disabled, with no enabled buttons, and no explanation.

The reason?

Eventually I worked out that the app.yaml file needed to be ANSI, not UTF-8. Fixed that, and it’s all good.

Fireworks in Flex – Faster and with Source!

I’ve cleaned out the Fireworks code – it’s fast. Not smooth though – I don’t know how to do a proper timer in Flex – anyone got any hints over how to be smoother than just running off the frame event?
Anyway, source is here, for your hacking pleasure. There’s a txt file to explain what you need inside.
Demo:http://js-fireworks.appspot.com/flex/index.html
Source:http://js-fireworks.appspot.com/flex/flex.zip

For the record, I still prefer the JavaScript version :)

Porting JS-Fireworks to Flash

Flash ActionScript is pretty much JavaScript right?
So, I thought my Chrome Experiment, js-fireworks should be trivial to port across to AS, and take advantage of the extra speed.
It did prove pretty simple.
Instead of a canvas, I create a Sprite. The Sprite has a graphics object which is usable in much the same way as the canvas. So all I needed to do was to switch the methods around a bit and voila!
One gotcha was the difference in calling setTimeout, which does not pick up the right context. When I call FireworkDisplay.blah, it should have the context of FireworkDisplay, not global.
Second gotcha was the redefinition of loop variables. This is illegal:

for (var i=0;i<20;i++) {
}
for (var i=0;i<20;i++) {
}

I think this is a flaw in Flash. The var declares the loop counter to be local to the loop, so it should not "keep" a definition after exiting the loop. It's a pain.
Finally, the colours are a bit off. Don't know why - I pinched a simple util to convert rgb to hex, and I think it's off.
Anyway, it works. No extra speed though. Will have to look at optimization later.
Click here to see the demo.
Or click here to download the source.

JS Fireworks

I’ve just submitted my Chrome Experiment – JavaScript Fireworks.
http://js-fireworks.appspot.com/

This amuses me because it’s such an old-fashioned idea. A bit like snow on your website, it’s a very nineties theme and I suspect I’ll have a lot of ex-Geocities users asking me how to include it on their pages.

I’m particularly pleased with the TinyURL inclusion, just for the hell of it :) And I look forward to tracking the messages via Google Analytics.

It’s no revolution (some of those experiments are awesome), and it’s not very Chrome-specific. Firefox handles the canvas better now, and Safari is very fast. Should I use excanvas to support IE???
Anyways, I’m pleased with the effect.

Update (12 May 2009):
No response so far (snif). I saw some hits from California, and one message sent saying “Not Your Mother’s JavaScript” – which is the experiments’ tagline. Fingers still crossed.

Update (13 May 2009):
Some quick updates: IE support! Really shows off the awesome excanvas library. But it’s a bit slow. I’ve intentionally not reduced the activity in IE to show the performance difference. Also, changed the default message. :)
Also, allowed click events to bring up the window, so it’s a bit more useable.

Update (16 May 2009):

Added various controls to experiment with. Time and gravity controls are fun. Toyed with framerate and number of sparks sliders, but didn’t work out.

Update (21 May 2009):

Added credit for the font, which was a free font, BM Receipt, passed through Cufon Generator to get each point as a JavaScript array, then stripped back to remove the lines, leaving just the points.

Intermediate tables in Django

Intermediate, intermediary, join tables in Django are something I’ve just ranted about on Twitter. Twitter’s great, because rants are limited to 140chars, so you don’t look so silly when you find the answer in the documentation.

Django’s documentation says that you can add ManyToMany join tables using the “through” parameter.
http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships

That table can hold useful extra fields. The documentation shows how to query against those fields, but not how to return them to view.

Ideally, we want to return them in a template. My example is a school with members, and a year for each.

Models:

class School(models.Model):
name = models.CharField(max_length=200)
members = models.ManyToManyField(Member, through='SchoolMember')

class Member(models.Model):
name = models.CharField(max_length=200)

class SchoolMember(models.Model):
member = models.ForeignKey(Member)
school = models.ForeignKey(School)
year = models.IntegerField(default=1900)

Template:

{% for myschool in myschoollist %}
{{ myschool.name }}
{% for myschoolmember in myschool.schoolmember_set|dictsort:"year"?%}

{{ myschoolmember.year }}
{{ myschoolmember.member.name }}
{% endfor %}
{% endfor %}

I think this works, but I’m not sure it’s optimal. Can anyone set me straight?

Updated: ?I’ve added sorting to show each year in order.

JavaScript Mindmap

I’ve been writing a JavaScript Mindmap.
It’s got very few dependancies: Mootools is used for dragging and the $ and $$ shortcuts. Also, excanvas gives IE canvas support.
UPDATE: it now uses jQuery instead of Mootools.
I tried to make it use “good juju”, by using good semantics. Therefore, it just builds out HTML lists.

And it’s fairly easy to see how it works.

Not sure what to call it. Called it Mindmap, called it spidermap, called it js-mindmap again.
http://code.google.com/p/js-mindmap 

Demo:
http://kenneth.kufluk.com/google/js-mindmap/ 

The aim is to provide a nice example to play with, not for any commercial gain.

Check it out. Suggest improvements. Bleat about bugs. Put me down for my poor coding styles. Or otherwise ignore it :)

Cross-domain JavaScript to Flash

Ok, what we learnt last night:

If you move your SWF onto another server (eg, using a caching server, CDN or similar), and have JavaScript in the page calling the SWF, then it will fail.

First step, we added a crossdomain.xml to the CDN server.  It made no difference, and was not requested by the SWF anyway.
Useful fact:  you can see flash requesting crossdomain.xml in Firebug.

Second step, we added “System.security.allowDomain(“http://www.xyz.com”)” to the Flash.
Useful fact:  check the “content-length” in the response headers to see when the new file has been deployed – it took more effort to deploy than expected, and this was a lifesaver as we nearly dismissed this option.

The second step worked.

Useful fact:  even though the JS files were served from the CDN too, they were executed within the page, and so were executing on a different domain to the Flash.

Useful fact:  SWFLiveconnect was irrelevant.  We already had set allowScriptAccess to always in the params.  We used ExternalInterface to make the function calls available to the JS.

Useful fact:  The Adobe docs refer to the method as HTML->SWF, not JavaScript->SWF.

Useful fact:  we tracked the problem to a definite JS->SWF issue using breakpoints in the JS using Firebug.  Brilliant.  The JS call to the Flash returned nothing – it failed silently, but stopped the function.  Correct behaviours would have been to return “undefined” and continue to the next line.

Final note:  Someone who understands HTML, CSS, JS and Flash is not your weakest tech link.  They probably know the most about the many technologies on the Internet.  So, give them some days to test before you roll out something new like this.  The architects and Java guys won’t follow it – give the HTMLers the time, as they’re on the front line.

Satchmo finally running

Woah, that wasn’t easy.

I managed to get it running using Django SVN trunk revision 8222 (pre-signals/dispatcher rewrite), and latest SVN Satchmo 1404.

It’s not easy on a PC to get the required files, got to be said.  Most of the easy_installs don’t work. 

I wasn’t sure where trml2pdf should be placed (install instructions: “put it where you want!” – thanks :-p).  I put the folder in python/site-packages, and tested with “import trml2pdf” at the python line.

Finally, all was running well and I started the shop, when I hit:
‘WSGIRequest’ object has no attribute ‘session’

This is because I used the recommended setting.py almost directly.  However, their setting-customize.py doesn’t include the “standard” stuff.  I’ve no idea why – it should have everything needed to run.  Anyway, it missed the middleware settings for the sessions.  My middleware settings now read:

MIDDLEWARE_CLASSES = (“django.middleware.locale.LocaleMiddleware”,
                      “django.middleware.common.CommonMiddleware”,
                      “django.contrib.sessions.middleware.SessionMiddleware”,
                      “django.middleware.doc.XViewMiddleware”,
                      “django.contrib.auth.middleware.AuthenticationMiddleware”,
                      “satchmo.shop.SSLMiddleware.SSLRedirect”,
                      “satchmo.recentlist.middleware.RecentProductMiddleware”)

I still have some outstanding errors for the languages.  I had to set my LANGUAGE_CODE to “us” – pretty odd, because that’s a country code.  Doh.  Plus, I want proper English (GB), and I’ll have to make sure I can do that.

I don’t know if that’s connected to the errors I got when doing:
python manage.py satchmo_load_l10n

But I ignored that and it still seems to be running :)

Final note:  For a Django App, that demo store is bloody ugly ;-P

Update: Site looks better now – had to set the MEDIA_URL to ‘/static/’