Ejemplo n.º 1
0
    def handerr(self, id):
        """Test error handler.

        This handler will receive exceptions and create a user with id+1
        so we can see if the exception was caught correctly.

        """
        if not id == 'XX':
            u = User()
            u.user_id = int(id)+1
            session.save(u)
            session.flush()
        msg = 'KARL27 responding'
        return dict(msg=msg)
Ejemplo n.º 2
0
    def doerr(self, id, dorb=0):
        """Test controller that raises an error.

        This controller will raise an exception after trying to create
        a new User. This new user should not be in the database at the end
        because the rollback should make it disapear.

        dorb is a flag to check that if a rollback occurs inside the
        controller code, the exception does not cause problems.

        """
        u = User()
        u.user_id = int(id)
        session.save(u)
        session.flush()
        if int(dorb) == 1:
            transaction.rollback()
        raise Exception('test')
Ejemplo n.º 3
0
def create_sa_catalog(locales, domain):
    """
    Creates a message catalog based on list of locales from existing
    GNU message catalog
    """

    tg_message_table.drop(checkfirst=True)
    tg_domain_table.drop(checkfirst=True)

    tg_domain_table.create(checkfirst=True)
    tg_message_table.create(checkfirst=True)

    localedir = gearshift.config.get("i18n.locale_dir", "locales")

    query = session.query(TG_Domain)
    domain = query.filter(TG_Domain.name==domain).first()
    if domain:
        return
    else:
        domain = TG_Domain()
        domain.name = domain
        session.save(domain)
        session.flush()

    for locale in locales:
        translations = translation(
                domain=domain.name,
                localedir=localedir,
                languages=[locale])
        catalog = translations._catalog

        for k, v in catalog.items():
            mess = TG_Message()
            mess.domain = domain
            mess.locale = locale
            mess.name = k
            mess.text = v
            session.save(mess)

        session.flush()
Ejemplo n.º 4
0
def create_sa_catalog(locales, domain):
    """
    Creates a message catalog based on list of locales from existing
    GNU message catalog
    """

    tg_message_table.drop(checkfirst=True)
    tg_domain_table.drop(checkfirst=True)

    tg_domain_table.create(checkfirst=True)
    tg_message_table.create(checkfirst=True)

    localedir = gearshift.config.get("i18n.locale_dir", "locales")

    query = session.query(TG_Domain)
    domain = query.filter(TG_Domain.name == domain).first()
    if domain:
        return
    else:
        domain = TG_Domain()
        domain.name = domain
        session.save(domain)
        session.flush()

    for locale in locales:
        translations = translation(domain=domain.name,
                                   localedir=localedir,
                                   languages=[locale])
        catalog = translations._catalog

        for k, v in catalog.items():
            mess = TG_Message()
            mess.domain = domain
            mess.locale = locale
            mess.name = k
            mess.text = v
            session.save(mess)

        session.flush()