fix overwriting the pad from the template when saving again.
This commit is contained in:
@@ -18,7 +18,7 @@ def ignore_ep_exception(msg="", *exceptions):
|
||||
except exceptions as e:
|
||||
logger.error(msg)
|
||||
logger.error("%s", e)
|
||||
|
||||
|
||||
|
||||
def get_ep_client(groupName="fet"):
|
||||
epc = None
|
||||
@@ -35,7 +35,7 @@ def get_ep_client(groupName="fet"):
|
||||
base_url=urllib.parse.urljoin(settings.ETHERPAD_CLIENT["url"], "api"),
|
||||
api_version="1.2.14",
|
||||
)
|
||||
|
||||
|
||||
if settings.ETHERPAD_CLIENT["group"] == "":
|
||||
group = epc.createGroupIfNotExistsFor(groupMapper=groupName)
|
||||
else:
|
||||
@@ -43,6 +43,7 @@ def get_ep_client(groupName="fet"):
|
||||
|
||||
return epc, group
|
||||
|
||||
|
||||
@contextmanager
|
||||
def ep_client(groupName="fet"):
|
||||
epc, group = get_ep_client(groupName)
|
||||
@@ -60,23 +61,32 @@ def __checkPadExists(padID=None):
|
||||
with ep_client() as (epc, group):
|
||||
if not epc or not group:
|
||||
return None
|
||||
|
||||
lists = epc.listPads(groupID=group["groupID"])
|
||||
if str(padID) in lists["padIDs"]:
|
||||
if any(str(padID) in s for s in lists["padIDs"]):
|
||||
logger.info(f"Pad '{padID}' existiert.")
|
||||
return True
|
||||
|
||||
logger.info(f"Pad '{padID}' existiert nicht.")
|
||||
return False
|
||||
|
||||
|
||||
def createPadifNotExists(padID, text="helloworld"):
|
||||
"""
|
||||
Create a pad if it doesn't exist.
|
||||
|
||||
Return a padID if new pad is created. Otherwise None (when the padID exists already).
|
||||
"""
|
||||
if not __checkPadExists(padID=padID):
|
||||
with ep_client() as (epc, group):
|
||||
if not epc or not group:
|
||||
return None
|
||||
epc.createGroupPad(
|
||||
groupID = group["groupID"], padName=padID, text=text
|
||||
)
|
||||
|
||||
return padID
|
||||
epc.createGroupPad(groupID=group["groupID"], padName=padID, text=text)
|
||||
logger.info(f"neues Pad erzeugt: {padID}")
|
||||
return padID
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def getPadHTML(padID):
|
||||
@@ -84,7 +94,8 @@ def getPadHTML(padID):
|
||||
with ep_client() as (epc, group):
|
||||
if not epc or not group:
|
||||
return None
|
||||
text = epc.getHTML(padID = group["groupID"] + "$" + padID)["html"]
|
||||
|
||||
text = epc.getHTML(padID=group["groupID"] + "$" + padID)["html"]
|
||||
return text
|
||||
|
||||
|
||||
@@ -104,6 +115,8 @@ def get_pad_link(padID):
|
||||
with ep_client() as (epc, group):
|
||||
if not epc or not group:
|
||||
return "#"
|
||||
|
||||
return urllib.parse.urljoin(
|
||||
settings.ETHERPAD_CLIENT["exturl"], "p/" + group["groupID"] + "$" + str(padID)
|
||||
settings.ETHERPAD_CLIENT["exturl"],
|
||||
"p/" + group["groupID"] + "$" + str(padID),
|
||||
)
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user