Ajout d'une classe qui supprime les bbcode

Fix #83
This commit is contained in:
Jean-Marie Favreau 2024-02-17 10:02:00 +01:00
parent 084fb9c3b3
commit f182f7ac0f
4 changed files with 34 additions and 0 deletions

View File

@ -98,6 +98,8 @@ def run_recurrent_import(self, pk):
extractor = ICALExtractor()
elif rimport.processor == RecurrentImport.PROCESSOR.ICALNOBUSY:
extractor = ICALNoBusyExtractor()
elif rimport.processor == RecurrentImport.PROCESSOR.ICALNOVC:
extractor = ICALNoVCExtractor()
else:
extractor = None

View File

@ -2,11 +2,18 @@ import icalendar
import warnings
from icalendar import vDatetime
import bbcode
from datetime import datetime, date
from bs4 import BeautifulSoup, MarkupResemblesLocatorWarning
from .extractor import *
from celery.utils.log import get_task_logger
logger = get_task_logger(__name__)
class ICALExtractor(Extractor):
@ -112,9 +119,32 @@ class ICALExtractor(Extractor):
return self.get_structure()
# A variation on ICAL extractor that removes any even named "Busy"
class ICALNoBusyExtractor(ICALExtractor):
def add_event(self, title, category, start_day, location, description, tags, uuid, recurrences=None, url_human=None, start_time=None, end_day=None, end_time=None, last_modified=None, published=False, image=None, image_alt=None):
if title != 'Busy':
super().add_event(title, category, start_day, location, description, tags, uuid, recurrences, url_human, start_time, end_day, end_time, last_modified, published, image, image_alt)
# A variation on ICAL extractor that remove any visual composer anchors
class ICALNoVCExtractor(ICALExtractor):
def __init__(self):
self.parser = bbcode.Parser(newline="\n", drop_unrecognized=True, install_defaults=False)
self.parser.add_simple_formatter("vc_row", "%(value)s")
self.parser.add_simple_formatter("vc_column", "%(value)s")
self.parser.add_simple_formatter("vc_column_text", "%(value)s")
self.parser.add_simple_formatter("vc_raw_html", "")
super().__init__()
def clean_vc(self, text):
if text is None:
return text
else:
result = self.parser.format(text)
logger.warning(result)
return result
def add_event(self, title, category, start_day, location, description, tags, uuid, recurrences=None, url_human=None, start_time=None, end_day=None, end_time=None, last_modified=None, published=False, image=None, image_alt=None):
super().add_event(title, category, start_day, location, self.clean_vc(description), tags, uuid, recurrences, url_human, start_time, end_day, end_time, last_modified, published, image, image_alt)

View File

@ -717,6 +717,7 @@ class RecurrentImport(models.Model):
class PROCESSOR(models.TextChoices):
ICAL = "ical", _("ical")
ICALNOBUSY = "icalnobusy", _("ical no busy")
ICALNOVC = "icalnovc", _("ical no VC")
class DOWNLOADER(models.TextChoices):
SIMPLE = "simple", _("simple")

View File

@ -35,4 +35,5 @@ django-ckeditor==6.7.0
django-recurrence==1.11.1
icalendar==5.0.11
lxml==5.1.0
bbcode==1.1.0