fix overwriting the pad from the template when saving again.
This commit is contained in:
@@ -43,6 +43,7 @@ def get_ep_client(groupName="fet"):
|
|||||||
|
|
||||||
return epc, group
|
return epc, group
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def ep_client(groupName="fet"):
|
def ep_client(groupName="fet"):
|
||||||
epc, group = get_ep_client(groupName)
|
epc, group = get_ep_client(groupName)
|
||||||
@@ -60,31 +61,41 @@ def __checkPadExists(padID=None):
|
|||||||
with ep_client() as (epc, group):
|
with ep_client() as (epc, group):
|
||||||
if not epc or not group:
|
if not epc or not group:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
lists = epc.listPads(groupID=group["groupID"])
|
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
|
return True
|
||||||
|
|
||||||
|
logger.info(f"Pad '{padID}' existiert nicht.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def createPadifNotExists(padID, text="helloworld"):
|
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):
|
if not __checkPadExists(padID=padID):
|
||||||
with ep_client() as (epc, group):
|
with ep_client() as (epc, group):
|
||||||
if not epc or not group:
|
if not epc or not group:
|
||||||
return None
|
return None
|
||||||
epc.createGroupPad(
|
|
||||||
groupID = group["groupID"], padName=padID, text=text
|
|
||||||
)
|
|
||||||
|
|
||||||
|
epc.createGroupPad(groupID=group["groupID"], padName=padID, text=text)
|
||||||
|
logger.info(f"neues Pad erzeugt: {padID}")
|
||||||
return padID
|
return padID
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def getPadHTML(padID):
|
def getPadHTML(padID):
|
||||||
text = None
|
text = None
|
||||||
with ep_client() as (epc, group):
|
with ep_client() as (epc, group):
|
||||||
if not epc or not group:
|
if not epc or not group:
|
||||||
return None
|
return None
|
||||||
text = epc.getHTML(padID = group["groupID"] + "$" + padID)["html"]
|
|
||||||
|
text = epc.getHTML(padID=group["groupID"] + "$" + padID)["html"]
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
@@ -104,6 +115,8 @@ def get_pad_link(padID):
|
|||||||
with ep_client() as (epc, group):
|
with ep_client() as (epc, group):
|
||||||
if not epc or not group:
|
if not epc or not group:
|
||||||
return "#"
|
return "#"
|
||||||
|
|
||||||
return urllib.parse.urljoin(
|
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")
|
request_logger = logging.getLogger("django.request")
|
||||||
|
|
||||||
|
|
||||||
def create_pad_for_post(slug, typ="agenda"):
|
def create_pad_for_post(slug, item="agenda"):
|
||||||
"Creates a Etherpad Pad and returns EtherpadKey"
|
"""
|
||||||
padID = createPadifNotExists(slug + "-" + typ)
|
Create a Etherpad pad.
|
||||||
|
|
||||||
|
Return a Etherpad key.
|
||||||
|
"""
|
||||||
|
logger.info(f"Pad-Type: {item}")
|
||||||
|
padID = createPadifNotExists(slug + "-" + item)
|
||||||
if padID:
|
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:
|
if page:
|
||||||
setPadHTML(padID, page.content)
|
setPadHTML(padID, page.content)
|
||||||
|
logger.info(f"Template gesetzt von: {page.title}")
|
||||||
|
else:
|
||||||
|
padID = f"{slug}-{item}"
|
||||||
|
|
||||||
|
logger.info(f"PadID: {padID}")
|
||||||
return padID
|
return padID
|
||||||
|
|
||||||
|
|
||||||
@@ -162,14 +171,14 @@ class Post(models.Model):
|
|||||||
Creates the pad if it doesn't exist"""
|
Creates the pad if it doesn't exist"""
|
||||||
if not self.slug:
|
if not self.slug:
|
||||||
return None
|
return None
|
||||||
return create_pad_for_post(self.slug, typ="agenda")
|
return create_pad_for_post(self.slug, "agenda")
|
||||||
|
|
||||||
def get_protocol_key(self):
|
def get_protocol_key(self):
|
||||||
"""Create a Etherpad Id for the Pad associated to this post.
|
"""Create a Etherpad Id for the Pad associated to this post.
|
||||||
Creates the pad if it doesn't exist"""
|
Creates the pad if it doesn't exist"""
|
||||||
if not self.slug:
|
if not self.slug:
|
||||||
return None
|
return None
|
||||||
return create_pad_for_post(self.slug, typ="protocol")
|
return create_pad_for_post(self.slug, "protocol")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def get_tagnames(self):
|
def get_tagnames(self):
|
||||||
@@ -230,7 +239,7 @@ class Post(models.Model):
|
|||||||
|
|
||||||
self.tags.set(
|
self.tags.set(
|
||||||
*re.findall(r"\#([\d\w-]+)", str(self.subtitle)),
|
*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):
|
def __str__(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user