Archive for the tag 'turbogears'

starting Turbogears apps automatically under Gentoo

Zahnräder

Thanks to some little scripts for Gentoo by Dennis Muhlestein you can start your TurboGears applications automatically at system’s startup under Gentoo. In case you’re too lazy to read his entry, here is what to do (enriched by my ideas):

  1. create a init.d template in /etc/init.d as follows, name it cherrypy and grant execute rights to everyone:
    #!/sbin/runscript
    
    depend() {
            need net
    }
    start() {
            su -l $APPUSER -c "screen -S $SESS_NAME -d -m $APP_DIR/$SCRIPT_NAME"
    }
    stop() {
            su -l $APPUSER -c "screen -S $SESS_NAME -X kill"
    }
    
  2. make a link to it, naming it similar to your application
    ln -s cherrypy hsyssite
  3. create a configuration file in /etc/conf.d for this application with following settings:
    APPUSER="mark"
    APP_DIR="/home/mark/WebApps/HsysSite"
    SESS_NAME="hsyssite"
    SCRIPT_NAME="start.sh"
    
  4. put that start-script in the application’s directory (named start.sh):
    #!/bin/bash
    #PATH=/home/the_user/bin:$PATH
    
    cd `dirname $0`
    ./start-hsyssite.py prod.cfg
  5. don’t forget to add it to the default runlevel!
    rc-update add hsyssite default

Thank you, Dennis!

new validators in FormEncode

Since yesterday you can find another set of country, language and address validators in FormEncode. The most convenient and underestimated is InternationalPhoneNumber, which converts phone numbers in standardized format understood in many countries. Plus, by having data stored in the same format no matter where it has been entered, you can easily convert it to the local format – in the US, just replace “+1-” by empty string. Voila.

An easy way of letting your user enter phone numbers as usual and to add his/her country code stored with his account is:

from formencode.national import InternationalPhoneNumber

def PhoneNumber(*args, **kw):
    def get_cc():
        try:
            return identity.current.user.phone_cc
        except:
            return 49
    return InternationalPhoneNumber(default_cc=get_cc, *args, **kw)