fix overwriting the pad from the template when saving again.

This commit is contained in:
2021-12-05 10:52:26 +00:00
parent 0a4f1a50ce
commit 86c5f8a0ad
2 changed files with 38 additions and 16 deletions

View File

@@ -27,15 +27,24 @@ logger = logging.getLogger(__name__)
request_logger = logging.getLogger("django.request")
def create_pad_for_post(slug, typ="agenda"):
"Creates a Etherpad Pad and returns EtherpadKey"
padID = createPadifNotExists(slug + "-" + typ)
def create_pad_for_post(slug, item="agenda"):
"""
Create a Etherpad pad.
Return a Etherpad key.
"""
logger.info(f"Pad-Type: {item}")
padID = createPadifNotExists(slug + "-" + item)
if padID:
page = CustomFlatPage.objects.filter(title__iexact=typ).first()
# set template into the newly created pad if it exists
page = CustomFlatPage.objects.filter(title__iexact=item).first()
if page:
setPadHTML(padID, page.content)
logger.info(f"Template gesetzt von: {page.title}")
else:
padID = f"{slug}-{item}"
logger.info(f"PadID: {padID}")
return padID
@@ -162,14 +171,14 @@ class Post(models.Model):
Creates the pad if it doesn't exist"""
if not self.slug:
return None
return create_pad_for_post(self.slug, typ="agenda")
return create_pad_for_post(self.slug, "agenda")
def get_protocol_key(self):
"""Create a Etherpad Id for the Pad associated to this post.
Creates the pad if it doesn't exist"""
if not self.slug:
return None
return create_pad_for_post(self.slug, typ="protocol")
return create_pad_for_post(self.slug, "protocol")
@property
def get_tagnames(self):
@@ -230,7 +239,7 @@ class Post(models.Model):
self.tags.set(
*re.findall(r"\#([\d\w-]+)", str(self.subtitle)),
*re.findall(r"\#([\d\w-]+)", str(self.title))
*re.findall(r"\#([\d\w-]+)", str(self.title)),
)
def __str__(self):