def new_visit_with_key(self, visit_key): created = datetime.now() visit = visit_class() visit.visit_key = visit_key visit.created = created visit.expiry = created + self.timeout session.flush() return Visit(visit_key, True)
def logout(self): """Remove the link between this identity and the visit.""" visit = self.visit_link if visit: session.delete(visit) session.flush() # Clear the current identity identity.set_current_identity(SqlAlchemyIdentity())
def login(self): """Set the link between this identity and the visit.""" visit = self.visit_link if visit: visit.user_id = self._user.user_id else: visit = visit_class() visit.visit_key = self.visit_key visit.user_id = self._user.user_id session.flush()
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)
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')
def create_person(self, id, docom=0, doerr=0, doflush=0, name="John Doe"): """Test controller""" Person(id=id, name=name) if int(docom) == 1: transaction.commit() ## cherrypy.request.sa_transaction.commit() if int(doerr) == 1: raise Exception('User generated exception') elif int(doerr) == 2: raise gearshift.redirect('/') if int(doflush): try: session.flush() except Exception: if int(doflush) == 1: raise return "No exceptions occurred"
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()
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()