Piki is a minimal wiki
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from django.conf import settings
  2. import mycreole
  3. import os
  4. class page(object):
  5. SPLITCHAR = ":"
  6. FOLDER_ATTACHMENTS = "attachments"
  7. FOLDER_CONTENT = 'content'
  8. FILE_NAME = 'page'
  9. def __init__(self, rel_path) -> None:
  10. self._rel_path = rel_path
  11. def rel_path_is_valid(self):
  12. return not self.SPLITCHAR in self._rel_path
  13. def is_available(self):
  14. return os.path.isfile(self.content_file_name)
  15. @property
  16. def title(self):
  17. return os.path.basename(self._rel_path)
  18. @property
  19. def attachment_path(self):
  20. return os.path.join(self.content_folder_name, self.FOLDER_ATTACHMENTS)
  21. @property
  22. def content_folder_name(self):
  23. return self._rel_path.replace('/', '::')
  24. @property
  25. def content_file_name(self):
  26. return os.path.join(settings.PAGES_ROOT, self.content_folder_name, self.FOLDER_CONTENT, self.FILE_NAME)
  27. def __read_content__(self):
  28. if self.is_available():
  29. with open(self.content_file_name, 'r') as fh:
  30. return fh.read()
  31. else:
  32. # TODO: Create message for creation or no content dependent of user has write access
  33. return "Page not available. Create it."
  34. def render_to_html(self, request):
  35. return mycreole.render(request, self.__read_content__(), self.attachment_path, "next_anchor")