def to_dict(self): items = [item.to_dict() for item in get_list(GalleryItem, gallery_uuid=self.uuid)] items.sort(key=lambda x: x['position']) data = {'uuid': self.uuid, 'name': self.name, 'author': self.author, 'cover_photo': self.cover_photo, 'created_ago': relative_time(self.created_at), 'created_at': format_date(self.created_at, format='%B %d, %Y'), 'published_ago': relative_time(self.published_at) if self.published_at else '', 'published': self.published, 'items': items, 'next_uuid': next_uuid(Gallery, self, sort_by='created_at', published=True), 'prev_uuid': prev_uuid(Gallery, self, sort_by='created_at', published=True), } return data
def update_gallery(uuid, **kwargs): gallery = get(Gallery, uuid=uuid) if not gallery.published and kwargs.get('published', False): kwargs['published_at'] = datetime.datetime.utcnow() gallery = update(gallery, kwargs) current_items = [item.get('uuid') for item in kwargs.get('items', [])] item_list = get_list(GalleryItem, gallery_uuid=gallery.uuid) delete_items = [item.uuid for item in item_list if item.uuid not in current_items] for uuid in delete_items: GalleryItem.delete(uuid) for item in kwargs.get('items', []): if item.get('uuid'): GalleryItem.update(uuid=item.pop('uuid'), **item) else: item['gallery_uuid'] = gallery.uuid GalleryItem.add_item(**item) return gallery.to_dict()
def get_talks(published=True): return [talk.to_dict() for talk in get_list(Talk, published=published, sort_by='date')]
def get_asana_attributes(asana_uuid): return [asana_attribute.to_dict() for asana_attribute in get_list(AsanaAttribute, asana_uuid=asana_uuid)]
def get_asanas(): return [asana.to_dict() for asana in get_list(Asana)]
def get_asana_images(asana_uuid): return [asana_image.to_dict() for asana_image in get_list(AsanaImage, asana_uuid=asana_uuid)]
def delete_shop(id): db.delete_by_id(DATABASE_URL, id) alcoshops = db.get_list(DATABASE_URL) return render_template('index.html', alcoshops=alcoshops)
def index(): alcoshops = db.get_list(DATABASE_URL) return render_template('index.html', alcoshops=alcoshops)
def delete_gallery(uuid): gallery = get(Gallery, uuid=uuid) for item in get_list(GalleryItem, gallery_uuid=uuid): delete(item) delete(gallery)
def get_galleries(published=True): item_list = get_list(Gallery, published=published, sort_by='published_at') return [gallery.to_dict() for gallery in item_list]