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.

import_system_pages.py 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from django.conf import settings
  2. from django.contrib.auth.models import User
  3. from django.core.management.base import BaseCommand
  4. from pages.models import PikiPage
  5. from datetime import datetime
  6. import fstools
  7. from zoneinfo import ZoneInfo
  8. SYSTEM_PAGES = {
  9. "tree": """= Tree
  10. <<allpagestree>>""",
  11. "index": """= Index
  12. <<allpages>>""",
  13. }
  14. def add_page_data(rel_path, tags, page_txt, creation_time, creation_user, modified_time, modified_user):
  15. try:
  16. page = PikiPage.objects.get(rel_path=rel_path)
  17. except PikiPage.DoesNotExist:
  18. page = PikiPage(rel_path=rel_path)
  19. #
  20. page.tags = tags
  21. page.page_txt = page_txt
  22. #
  23. page.creation_time = creation_time
  24. try:
  25. page.creation_user = User.objects.get(username=creation_user)
  26. except User.DoesNotExist:
  27. page.creation_user = None
  28. page.modified_time = modified_time
  29. try:
  30. page.modified_user = User.objects.get(username=modified_user)
  31. except User.DoesNotExist:
  32. page.modified_user = None
  33. #
  34. page.save()
  35. class Command(BaseCommand):
  36. def handle(self, *args, **options):
  37. for rel_path in SYSTEM_PAGES:
  38. self.stdout.write(self.style.MIGRATE_HEADING("Migration of page '%s'" % rel_path))
  39. #
  40. dtm = datetime.now(ZoneInfo("UTC"))
  41. add_page_data(
  42. rel_path,
  43. "",
  44. SYSTEM_PAGES[rel_path],
  45. dtm,
  46. None,
  47. dtm,
  48. None
  49. )