[sync] updated; page images

This commit is contained in:
tmshv committed 2016-11-23 02:10:26 +03:00
1 parent 9f58ffca09
commit a4b4e07687
6 files changed
+104 -28

No files matched your search

+8 -14
View File
@@ -3,6 +3,7 @@ from lxml import etree
import lxml.html
import settings
from sync import create_post
from sync.core import Sync
from sync.models.product import create_product
from utils.fn import lmap, iterate_iter_over_fns, combine
@@ -10,20 +11,6 @@ from utils.hash import hash_file, hash_str
from utils.text.transform import url_encode_text
def create_post(md, image_path_fn):
html = lxml.html.fromstring(md)
for img in html.cssselect('img'):
src = img.get('src')
path = image_path_fn(src)
if path:
img.set('src', path)
img.set('class', settings.album_html_img_class)
img.set('data-file', src)
return etree.tounicode(html)
def create_url(a, i, s, e):
return 'https://static.shburg.org/art/images/product-{album}-{id}-{size}{ext}'.format(
album=a,
@@ -120,6 +107,13 @@ class SyncAlbum(Sync):
images = []
post_html = create_post(doc['post'], process_post_image)
if 'preview' in doc:
preview = os.path.join(doc['folder'], doc['preview'])
doc['preview'] = self.create_image(preview, url_creator(
doc['id'],
image_id(doc['preview'])
))
doc['post'] = post_html
doc['images'] = images
return doc