Sorrento & Sicily, here we come!

We're leaving now. Wish you all the best! Take care! See you in a month. You can contact me on my Italian number if you have to (See Contact Details).

Ciao!

— by Robert Thomson, created 31st Jul, 2009, last modified 31st Jul, 2009 | Tags: World

 Grok/Zope: Redirect from Traverser

class RedirectModel(grok.Model):
    """
    RedirectModel + RedirectView allow us to do redirects from Traverser's easily
    """
    def __init__(self, request, url):
        request.setTraversalStack(['@@index'])
        self.redirecturl = url

class RedirectView(grok.View):
    grok.context(RedirectModel)
    grok.name('index')
    def update(self):
        self.redirect(self.context.redirecturl)
    def render(self):
        pass

Then from your Traverser's traverse():

return RedirectModel(self.request, "/newURL/")
— by Robert Thomson, created 29th Jul, 2009, last modified 29th Jul, 2009 | Tags: Tech

 3 days until holidays!

On Friday, we hand over the keys to the apartment and embark on our trip down south. We will first go to Sorrento, where we will stay for a few days, exploring it and nearby places such as Capri and Naples.

We will then catch a ferry to Palermo, and travel counter-clockwise around the island. At the start of September, we will eventually fly to Berlin. No doubt somewhat exhausted and tanned. :-P

During this time, I won't have computer or regular Internet access, so excuse the lack of response!

— by Robert Thomson, created 28th Jul, 2009, last modified 28th Jul, 2009 | Tags: World

 SQLAlchemy, PyMSSQL, encoding problem .. FIXED

The Problem: MSSQL database with "LATIN1" (case-sensitive) encoding, SQLAlchemy and PyMSSQL. Fields with non-ascii characters were sometimes being returned double encoded.. The actual case is that SQLAlchemy passes parameters to the DBAPI as however you pass them to SQLAlchemy.. the convert_unicode option doesn't seem to change the encoding of unicode parameters when saving, only the SQL string.. which seems kind of inconsistent. I'm actually not 100% certain of the interactions here, and who is to blame - PyMSSQL or SQLAlchemy - but let's split the difference and blame Microsoft, they're always a good target.

The Solution: A custom type:

class EncodedString(types.TypeDecorator):
    impl = types.String
    def process_bind_param(self, value, dialect):
        if type(value) == unicode:
            return value.encode(dialect.encoding, 'replace')
        return value
    def process_result_value(self, value, dialect):
        if value and type(value) == str:
            return value.decode(dialect.encoding)
        return value

and instead of defining a Column with types.String or types.Unicode, use EncodedString.

It looks like types.Unicode should do exactly this, but for some reason it's not working for me.

— by Robert Thomson, created 16th Jul, 2009, last modified 16th Jul, 2009 | Tags: Tech

 Offline Web Apps on Maemo with Tear

It's possible via a slightly non-standard method to have offline web apps on the Maemo platform. Tear is a webkit based browser, and when using a recent webkit (more info here) you have access to the local storage facilities as specified in HTML5. The problem is that full AppCache functionality doesn't exist/work yet..

However, you can host your apps locally on your maemo device, and by setting "document.domain = your.domain" in javascript, you can use the security context of the remote domain when making requests.. When you're offline, you just return information from the local data stores, but when you're online, you can get new information easily. Neat, eh?

Still, I'm looking forward to AppCache support so I don't have to save pages locally.

— by Robert Thomson, created 10th Jul, 2009, last modified 10th Jul, 2009 | 1 comment | Tags: Tech