def update(self, name, photo_filename=''): try: now = datetime.now() if name and name != self.name: store.execute("update demo_page set name=%s, rtime=%s" " where id=%s", (name, now, self.id)) store.commit() if photo_filename: photo_ver = self.photo_ver + 1 data = open(photo_filename).read() rect = self.rect zoomout = self.app.zoomout with Image(blob=data) as img: img.resize(rect.width, rect.height, "catrom") filestore.save_image(img, "page-photo-%s-%s.jpg" % (self.id, photo_ver)) img.resize(rect.width/zoomout, rect.height/zoomout, "catrom") filestore.save_image(img, "page-photo-%s-%s.jpg" % (self.id, photo_ver), "s") store.execute("update demo_page set photo_ver=%s, rtime=%s" " where id=%s", (photo_ver, now, self.id)) store.commit() except IntegrityError: #traceback.print_exc() store.rollback()
def update(self, name, icon_filename='', zoomout=2): try: now = datetime.now() if name and name != self.name: store.execute("update demo_app set name=%s, rtime=%s" " where id=%s", (name, now, self.id)) store.commit() self.name = name if icon_filename: icon_ver = self.icon_ver + 1 data = open(icon_filename).read() screen = self.screen with Image(blob=data) as img: img.resize(screen.icon_width, screen.icon_height, "catrom") filestore.save_image(img, "app-icon-%s-%s.jpg" % (self.id, icon_ver)) img.resize(screen.icon_width/zoomout, screen.icon_height/zoomout, "catrom") filestore.save_image(img, "app-icon-%s-%s.jpg" % (self.id, icon_ver), "s") store.execute("update demo_app set icon_ver=%s, rtime=%s" " where id=%s", (icon_ver, now, self.id)) store.commit() self.icon_ver = icon_ver except IntegrityError: #traceback.print_exc() store.rollback()
def new(cls, app, name, rect, photo_filename='', parent_id='', page_type=None): screen = app.screen page_type = page_type or cls.TYPE_NORMAL try: photo_ver = photo_filename and 1 or 0 store.execute("insert into demo_page(name, parent_page_id, app_id, photo_ver, rect_id, `type`)" " values(%s,%s,%s,%s,%s,%s)", (name, parent_id or '0', app.id, photo_ver, rect.id, page_type)) store.commit() id = store.get_cursor(table="demo_page").lastrowid if photo_filename: data = open(photo_filename).read() with Image(blob=data) as img: if page_type == cls.TYPE_ITEM: rect.height = rect.width*img.height/img.width rect.save() img.resize(rect.width, rect.height, "catrom") filestore.save_image(img, "page-photo-%s-%s.jpg" % (id, photo_ver)) img.resize(rect.width/app.zoomout, rect.height/app.zoomout, "catrom") filestore.save_image(img, "page-photo-%s-%s.jpg" % (id, photo_ver), "s") else: rect.height = 100 #default height rect.save return id except IntegrityError: #traceback.print_exc() store.rollback()
def new(cls, user_id, name, icon_filename, screen_id=DEFAULT_SCREEN.id, zoomout=2): try: icon_ver = 1 store.execute("insert into demo_app(user_id, name, screen_id, icon_ver, zoomout)" " values(%s,%s,%s,%s,%s)", (user_id, name, screen_id, icon_ver, zoomout)) store.commit() id = store.get_cursor(table="demo_app").lastrowid screen = Screen.get(screen_id) data = open(icon_filename).read() with Image(blob=data) as img: img.resize(screen.icon_width, screen.icon_height, "catrom") filestore.save_image(img, "app-icon-%s-%s.jpg" % (id, icon_ver)) img.resize(screen.icon_width/zoomout, screen.icon_height/zoomout, "catrom") filestore.save_image(img, "app-icon-%s-%s.jpg" % (id, icon_ver), "s") return id except IntegrityError: #traceback.print_exc() store.rollback()