コード例 #1
0
 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
コード例 #2
0
    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()
コード例 #3
0
ファイル: talks.py プロジェクト: streeter/kateheddleston.com
 def get_talks(published=True):
     return [talk.to_dict() for talk in get_list(Talk, published=published, sort_by='date')]
コード例 #4
0
ファイル: asanas.py プロジェクト: heddle317/yoga-app
 def get_asana_attributes(asana_uuid):
     return [asana_attribute.to_dict() for asana_attribute in get_list(AsanaAttribute, asana_uuid=asana_uuid)]
コード例 #5
0
ファイル: asanas.py プロジェクト: heddle317/yoga-app
 def get_asanas():
     return [asana.to_dict() for asana in get_list(Asana)]
コード例 #6
0
ファイル: asanas.py プロジェクト: heddle317/yoga-app
 def get_asana_images(asana_uuid):
     return [asana_image.to_dict() for asana_image in get_list(AsanaImage, asana_uuid=asana_uuid)]
コード例 #7
0
 def delete_shop(id):
     db.delete_by_id(DATABASE_URL, id)
     alcoshops = db.get_list(DATABASE_URL)
     return render_template('index.html', alcoshops=alcoshops)
コード例 #8
0
 def index():
     alcoshops = db.get_list(DATABASE_URL)
     return render_template('index.html', alcoshops=alcoshops)
コード例 #9
0
 def delete_gallery(uuid):
     gallery = get(Gallery, uuid=uuid)
     for item in get_list(GalleryItem, gallery_uuid=uuid):
         delete(item)
     delete(gallery)
コード例 #10
0
 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]