Skip to content
Snippets Groups Projects
Commit cb8173dd authored by OndraRehounek's avatar OndraRehounek
Browse files

district & region: WIP fancybox galleries

parent 786c4368
No related branches found
No related tags found
2 merge requests!468Release,!459district & region: fancybox galleries
Pipeline #7505 passed
...@@ -185,8 +185,8 @@ def get_or_create_image( ...@@ -185,8 +185,8 @@ def get_or_create_image(
file = ImageFile(open(img_path, "rb"), name=img_path) file = ImageFile(open(img_path, "rb"), name=img_path)
image = Image(title=file_path, file=file, collection=collection) image = Image(title=file_path, file=file, collection=collection)
try:
if not image_params["dry_run"]: if not image_params["dry_run"]:
try:
image.save() image.save()
except Exception as e: except Exception as e:
msg = "Nelze uložit obrázek" msg = "Nelze uložit obrázek"
...@@ -386,6 +386,50 @@ class JekyllArticleImporter: ...@@ -386,6 +386,50 @@ class JekyllArticleImporter:
text = re.split(r"^\s*$", text.strip(), flags=re.MULTILINE)[0] text = re.split(r"^\s*$", text.strip(), flags=re.MULTILINE)[0]
return plain_md.convert(text) return plain_md.convert(text)
def handle_fancybox_gallery(self, article, meta: dict):
for gallery in meta["fancybox"]:
# gallery by měl být dict o name a img
gallery_name = gallery.get("name", "")
if gallery_name:
article.content.append(
("text", RichText("<h2>{}</h2>".format(gallery_name)))
)
gallery_images = gallery.get("img", [])
if not len(gallery_images):
self.page_log += (
"{} Nepodařilo se získat obrázky v galerii {}\n".format(
article.title, gallery_name
)
)
continue
wagtail_image_list = []
for img in gallery_images:
if not img.get("src"):
self.page_log += (
'{}: Obrázek {} v galerii namá atribut "src" \n'.format(
article.title, img.get("title", "")
)
)
continue
wagtail_image, log_message = get_or_create_image(
self.path, img["src"], self.collection, self.repo_name
)
wagtail_image_list.append(wagtail_image)
# article.content += GalleryBlock(gallery_items=wagtail_image_list)
if log_message:
self.page_log += "{}: {}".format(article.title, log_message)
# article.content += [("gallery", GalleryBlock(local_blocks=(
# 'gallery_items', ListBlock(
# child_block=ImageChooserBlock()
# ) TODO use JSON
# )))]
@staticmethod @staticmethod
def handle_meta_is_str(meta: str) -> dict: def handle_meta_is_str(meta: str) -> dict:
""" """
...@@ -455,8 +499,11 @@ class JekyllArticleImporter: ...@@ -455,8 +499,11 @@ class JekyllArticleImporter:
except (Page.DoesNotExist, Page.MultipleObjectsReturned): except (Page.DoesNotExist, Page.MultipleObjectsReturned):
article = self.page_model() article = self.page_model()
article.content = [("text", RichText(html))]
article.perex = self.get_perex(md) or "..." article.perex = self.get_perex(md) or "..."
article.content = [("text", RichText(html))]
if meta.get("fancybox", None):
self.handle_fancybox_gallery(article, meta)
if meta.get("date", None): if meta.get("date", None):
meta_date = meta["date"] meta_date = meta["date"]
...@@ -551,7 +598,10 @@ class JekyllArticleImporter: ...@@ -551,7 +598,10 @@ class JekyllArticleImporter:
if self.dry_run or not article: if self.dry_run or not article:
return return
try:
article.save() # ujistím se, že mám "redirect_page" pro Redirect uloženou article.save() # ujistím se, že mám "redirect_page" pro Redirect uloženou
except:
pass
self.create_redirects(article, match) self.create_redirects(article, match)
else: else:
msg = "Nepodporovaná přípona souboru: %s" % ext msg = "Nepodporovaná přípona souboru: %s" % ext
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment