def update_gallery_images(): galleries = Gallery.get_galleries(published=False) for gallery in galleries: for item in gallery.get('items', []): if item.get('image_name'): print("{} {}".format(gallery.get('uuid'), item.get('image_name'))) update_image_headers( 'galleries/{}'.format(gallery.get('uuid')), item.get('image_name')) update_image_headers( 'galleries/{}'.format(gallery.get('uuid')), "{}_thumbnail".format(item.get('image_name'))) update_image_headers( 'galleries/{}'.format(gallery.get('uuid')), "{}_small".format(item.get('image_name'))) update_image_headers( 'galleries/{}'.format(gallery.get('uuid')), "{}_medium".format(item.get('image_name'))) update_image_headers( 'galleries/{}'.format(gallery.get('uuid')), "{}_large".format(item.get('image_name'))) update_image_headers( 'galleries/{}'.format(gallery.get('uuid')), "{}_grande".format(item.get('image_name'))) update_image_headers( 'galleries/{}'.format(gallery.get('uuid')), "{}_jumbo".format(item.get('image_name')))
def get_galleries(): galleries = Gallery.get_galleries(published=False) if request.is_xhr: return json.dumps(galleries), 200, {'Content-Type': 'application/json'} g.nav_view = 'galleries' galleries = [json.dumps(gallery) for gallery in galleries] return render_template('admin/galleries.html', galleries=galleries)
def blog_feed(): posts = Gallery.get_list(published=True, to_json=True) feed_url = "{}/blog/feed.atom".format(g.app_base_link) feed = AtomFeed('KateHeddleston.com Blog Posts', feed_url=feed_url, url='{}/blog'.format(g.app_base_link)) for post in posts: post_html = [] for item in post.get('items'): item_text = "" if item.get('title'): item_text += u'<h2>{}</h2><br>'.format(item.get('title')) if item.get('image_name'): img_src = u'{}/{}'.format(post.get('base_url'), item.get('image_name')) item_text += u"<img src='{}' />".format(img_src) if item.get('image_caption'): item_text += u"<div>{}</div>".format(item.get('image_caption')) item_text += '<br>' item_text += item.get('body') post_html.append(item_text) text = '</p><p>'.join(post_html) text = '<p>' + text + '</p>' post_url = "{}/blog/{}".format(g.app_base_link, post.get('uuid')) published_at = datetime.datetime.strptime(post['published_at_raw'], '%Y-%m-%dT%H:%M:%S') feed.add(post.get('name'), unicode(text), content_type='html', author=post.get('author'), url=post_url, updated=published_at, published=published_at) return feed.get_response()
def about(): g.nav_view = 'about' gallery = Gallery.get(uuid='7baf4d66-afa2-46dd-8fee-8b113d255d14') return render_template('about.html', gallery=gallery.to_dict(), gallery_items=[item.to_dict() for item in gallery.items()], gallery_uuid='7baf4d66-afa2-46dd-8fee-8b113d255d14')
def blog_feed(): posts = Gallery.get_list(published=True, to_json=True) feed_url = "{}/blog/feed.atom".format(g.app_base_link) feed = AtomFeed('KateHeddleston.com Blog Posts', feed_url=feed_url, url='{}/blog'.format(g.app_base_link)) for post in posts: post_html = [] for item in post.get('items'): item_text = "" if item.get('title'): item_text += u'<h2>{}</h2><br>'.format(item.get('title')) if item.get('image_name'): img_src = u'{}/{}'.format(post.get('base_url'), item.get('image_name')) item_text += u"<img src='{}' />".format(img_src) if item.get('image_caption'): item_text += u"<div>{}</div>".format(item.get('image_caption')) item_text += '<br>' item_text += item.get('body') post_html.append(item_text) text = '</p><p>'.join(post_html) text = '<p>' + text + '</p>' post_url = "{}/blog/{}".format(g.app_base_link, post.get('uuid')) published_at = datetime.datetime.strptime(post['published_at_raw'], '%Y-%m-%dT%H:%M:%S') feed.add(post.get('name'), text, content_type='html', author=post.get('author'), url=post_url, updated=published_at, published=published_at) return feed.get_response()
def create_gallery(): data = json.loads(request.data) try: gallery = Gallery.create_gallery(**data) except ValueError as e: flash(e.message, 'danger') return json.dumps({'message': e.message}), 400, {'Content-Type': 'application/json'} return json.dumps(gallery), 200, {'Content-Type': 'application/json'}
def blog_post_title(blog_attr): gallery = Gallery.get_custom_url(blog_attr) if gallery is None: gallery = Gallery.get(uuid=blog_attr) if gallery is None: abort(404) latest_title_url = gallery.latest_url_title() if blog_attr != latest_title_url: return redirect(u'{}/blog/{}'.format(config.APP_BASE_LINK, latest_title_url)) current_url = u"{}/blog/{}".format(config.APP_BASE_LINK, blog_attr) return render_template('post.html', gallery_uuid=gallery.uuid, gallery=gallery.to_dict(), current_url=current_url, facebook_app_id=config.FACEBOOK_APP_ID, full_page=True)
def get_comments_for_galleries(): galleries = Gallery.get_list(published=True) tweets = [] for gallery in galleries: gallery_uuid = gallery.uuid url = 'https://www.kateheddleston.com/blog/{}'.format(gallery_uuid) update_facebook_comments(url, gallery_uuid) tweets = tweets + update_tweet_comments(url, gallery_uuid) return tweets
def blog_post_title(blog_attr): gallery = Gallery.get_custom_url(blog_attr) if gallery is None: gallery = Gallery.get(uuid=blog_attr) if gallery is None: abort(404) latest_title_url = gallery.latest_url_title() if blog_attr != latest_title_url: return redirect(u'{}/blog/{}'.format(config.APP_BASE_LINK, latest_title_url)) current_url = u"{}/blog/{}".format(config.APP_BASE_LINK, blog_attr) return render_template('post.html', gallery_uuid=gallery.uuid, gallery=gallery.to_dict(), gallery_items=[item.to_dict() for item in gallery.items()], current_url=current_url, facebook_app_id=config.FACEBOOK_APP_ID, full_page=True)
def create_gallery(): data = json.loads(request.data) try: gallery = Gallery.create_gallery(**data) except ValueError as e: flash(e.message, 'danger') return json.dumps({'message': e.message}), 400, { 'Content-Type': 'application/json' } return json.dumps(gallery.to_dict(admin=True)), 200, { 'Content-Type': 'application/json' }
def edit_gallery(uuid): gallery = Gallery.get_gallery(uuid) g.nav_view = 'galleries' policy = base64.b64encode(json.dumps(policy_document)) signature = base64.b64encode(hmac.new(config.AWS_SECRET_ACCESS_KEY, policy, hashlib.sha1).digest()) access_key = config.AWS_ACCESS_KEY_ID return render_template('admin/edit_gallery.html', gallery=gallery, gallery_json=json.dumps(gallery), policy=policy, signature=signature, accessKey=access_key)
def update_gallery_images(): galleries = Gallery.get_galleries(published=False) for gallery in galleries: for item in gallery.get('items', []): if item.get('image_name'): print "{} {}".format(gallery.get('uuid'), item.get('image_name')) update_image_headers('galleries/{}'.format(gallery.get('uuid')), item.get('image_name')) update_image_headers('galleries/{}'.format(gallery.get('uuid')), "{}_thumbnail".format(item.get('image_name'))) update_image_headers('galleries/{}'.format(gallery.get('uuid')), "{}_small".format(item.get('image_name'))) update_image_headers('galleries/{}'.format(gallery.get('uuid')), "{}_medium".format(item.get('image_name'))) update_image_headers('galleries/{}'.format(gallery.get('uuid')), "{}_large".format(item.get('image_name'))) update_image_headers('galleries/{}'.format(gallery.get('uuid')), "{}_grande".format(item.get('image_name'))) update_image_headers('galleries/{}'.format(gallery.get('uuid')), "{}_jumbo".format(item.get('image_name')))
def blog_post(uuid): post = Gallery.get_gallery(uuid) return render_template('post.html', post=post, post_json=json.dumps(post))
def api_edit_gallery(uuid=None): if uuid: gallery = Gallery.get(uuid=uuid).to_dict(admin=True) else: gallery = Gallery.blank() return json.dumps(gallery), 200, {'Content-Type': 'application/json'}
def get_admin_gallery(uuid=None): gallery = Gallery.blank() return json.dumps(gallery), 200, {'Content-Type': 'application/json'}
def blog(): g.nav_view = 'blog' posts = Gallery.get_list(published=True, to_json=True, sort_by='published_at') return render_template('blog.html', posts=posts)
def about(): g.nav_view = 'about' gallery = Gallery.get_gallery(uuid='7baf4d66-afa2-46dd-8fee-8b113d255d14') return render_template('about.html', gallery=json.dumps(gallery))
def contact(): g.nav_view = 'contact' gallery = Gallery.get(uuid='3d93674d-8331-4ac1-a318-26c7bb415fd9') return render_template('contact.html', gallery=gallery.to_dict(), gallery_uuid='3d93674d-8331-4ac1-a318-26c7bb415fd9', contact=True)
def api_get_galleries(): galleries = Gallery.get_list(published=False, to_json=True, sort_by='published_at') return json.dumps(galleries), 200, {'Content-Type': 'application/json'}
def send_gallery_emails(uuid): Gallery.send_emails(uuid) return json.dumps({'message': 'Emails were successfully sent.'}), 200, { 'Content-Type': 'application/json' }
def delete_gallery(uuid): Gallery.delete(uuid=uuid) return_data = {'message': 'Your gallery was successfully deleted.'} return json.dumps(return_data), 200, {'Content-Type': 'application/json'}
def update_gallery(uuid=None): data = json.loads(request.data) gallery = Gallery.update(uuid, **data) return json.dumps(gallery.to_dict(admin=True)), 200, { 'Content-Type': 'application/json' }
def send_gallery_emails(uuid): Gallery.send_emails(uuid) return json.dumps({'message': 'Emails were successfully sent.'}), 200, {'Content-Type': 'application/json'}
def preview_gallery(uuid): gallery = Gallery.get_gallery(uuid) g.nav_view = 'galleries' return render_template('admin/preview.html', post=gallery, post_json=json.dumps(gallery))
def update_gallery(uuid=None): data = json.loads(request.data) gallery = Gallery.update(uuid, **data) return json.dumps(gallery.to_dict(admin=True)), 200, {'Content-Type': 'application/json'}
def blog(): g.nav_view = 'blog' posts = Gallery.get_galleries() return render_template('blog.html', posts=posts)
def update_gallery(uuid): data = json.loads(request.data) gallery = Gallery.update_gallery(uuid, **data) return json.dumps(gallery), 200, {'Content-Type': 'application/json'}
def delete_gallery(uuid): Gallery.delete_gallery(uuid) return_data = {'message': 'Your gallery was successfully deleted.'} return json.dumps(return_data), 200, {'Content-Type': 'application/json'}
from app.db.talks import Talk from app.utils.aws import s3_change_image_resolutions if __name__ == '__main__': db_table = sys.argv[1] if len(sys.argv) > 3: uuid = sys.argv[2] image_route = "{}/{}".format(db_table, uuid) filename = sys.argv[3] s3_change_image_resolutions(image_route, filename) elif len(sys.argv) > 2: uuid = sys.argv[2] image_route = "{}/{}".format(db_table, uuid) if db_table == 'galleries': db_item = Gallery.get_gallery(uuid=uuid) for item in db_item.get('items', []): if item.get('image_name'): print(item.get('image_name')) s3_change_image_resolutions(image_route, item.get('image_name')) elif db_table == 'talks': db_item = Talk.get_talk(uuid=uuid) if db_item.get('image_name'): print(db_item.get('image_name')) s3_change_image_resolutions(image_route, db_item.get('image_name')) else: if db_table == 'galleries': db_items = Gallery.get_galleries() for db_item in db_items: image_route = "{}/{}".format(db_table, db_item.get('uuid')) for item in db_item.get('items', []):
from app.db.talks import Talk from app.utils.aws import s3_change_image_resolutions if __name__ == '__main__': db_table = sys.argv[1] if len(sys.argv) > 3: uuid = sys.argv[2] image_route = "{}/{}".format(db_table, uuid) filename = sys.argv[3] s3_change_image_resolutions(image_route, filename) elif len(sys.argv) > 2: uuid = sys.argv[2] image_route = "{}/{}".format(db_table, uuid) if db_table == 'galleries': db_item = Gallery.get_gallery(uuid=uuid) for item in db_item.get('items', []): if item.get('image_name'): print item.get('image_name') s3_change_image_resolutions(image_route, item.get('image_name')) elif db_table == 'talks': db_item = Talk.get_talk(uuid=uuid) if db_item.get('image_name'): print db_item.get('image_name') s3_change_image_resolutions(image_route, db_item.get('image_name')) else: if db_table == 'galleries': db_items = Gallery.get_galleries() for db_item in db_items: image_route = "{}/{}".format(db_table, db_item.get('uuid')) for item in db_item.get('items', []):
import sys from app import app from app.db.subscriptions import Subscription from app.db.galleries import Gallery if __name__ == "__main__": email = sys.argv[1] gallery_uuid = sys.argv[2] gallery = Gallery.get(uuid=gallery_uuid) with app.app_context(): Subscription.send_subscription_email(email, gallery)
def get_gallery_ajax(uuid): gallery = Gallery.get(uuid=uuid) return json.dumps(gallery.to_dict()), 200, { 'Content-Type': 'application/json' }
def get_gallery_ajax(uuid): gallery = Gallery.get(uuid=uuid) return json.dumps(gallery.to_dict()), 200, {"Content-Type": "application/json"}