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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. from django.conf import settings
  2. from django.shortcuts import render
  3. from django.http import HttpResponse, HttpResponseRedirect
  4. from django.utils.translation import gettext as _
  5. import logging
  6. from . import access
  7. from . import messages
  8. from . import url_page
  9. import config
  10. from .context import context_adaption
  11. from .forms import EditForm
  12. from .help import help_pages
  13. import mycreole
  14. from .page import creol_page
  15. from themes import Context
  16. logger = logging.getLogger(settings.ROOT_LOGGER_NAME).getChild(__name__)
  17. def root(request):
  18. return HttpResponseRedirect(url_page(request, config.STARTPAGE))
  19. def page(request, rel_path):
  20. context = Context(request) # needs to be executed first because of time mesurement
  21. #
  22. p = creol_page(request, rel_path)
  23. if access.read_page(request, rel_path):
  24. page_content = p.render_to_html()
  25. else:
  26. messages.permission_denied_msg_page(request, rel_path)
  27. page_content = ""
  28. #
  29. context_adaption(
  30. context,
  31. request,
  32. rel_path=rel_path,
  33. title=p.title,
  34. upload_path=p.attachment_path,
  35. page_content=page_content
  36. )
  37. return render(request, 'pages/page.html', context=context)
  38. def edit(request, rel_path):
  39. if access.write_page(request, rel_path):
  40. context = Context(request) # needs to be executed first because of time mesurement
  41. #
  42. p = creol_page(request, rel_path)
  43. #
  44. if not request.POST:
  45. form = EditForm(page_data=p.raw_page_src)
  46. #
  47. context_adaption(
  48. context,
  49. request,
  50. form=form,
  51. # TODO: Add translation
  52. title=_("Edit page %s") % repr(p.title),
  53. upload_path=p.attachment_path,
  54. )
  55. return render(request, 'pages/page_form.html', context=context)
  56. else:
  57. save = request.POST.get("save")
  58. page_txt = request.POST.get("page_txt")
  59. preview = request.POST.get("preview")
  60. #
  61. if save is not None:
  62. p.update_page(page_txt)
  63. return HttpResponseRedirect(url_page(request, rel_path))
  64. elif preview is not None:
  65. form = EditForm(page_data=page_txt)
  66. #
  67. context_adaption(
  68. context,
  69. request,
  70. form=form,
  71. # TODO: Add translation
  72. title=_("Edit page %s") % repr(p.title),
  73. upload_path=p.attachment_path,
  74. page_content=p.render_text(request, page_txt)
  75. )
  76. return render(request, 'pages/page_form.html', context=context)
  77. else:
  78. return HttpResponseRedirect(url_page(request, rel_path))
  79. else:
  80. messages.permission_denied_msg_page(request, rel_path)
  81. return HttpResponseRedirect(url_page(request, rel_path))
  82. def search(request):
  83. context = Context(request) # needs to be executed first because of time mesurement
  84. context_adaption(
  85. context,
  86. request,
  87. page_content="Search is not yet implemented..."
  88. )
  89. return render(request, 'pages/page.html', context=context)
  90. def helpview(request, page='main'):
  91. context = Context(request) # needs to be executed first because of time mesurement
  92. page_content = help_pages[page]
  93. context_adaption(
  94. context, # the base context
  95. request, # the request object to be used in context_adaption
  96. current_help_page=page, # the current help_page to identify which taskbar entry has to be highlighted
  97. page_content=page_content, # the help content itself (template)
  98. title=_('Help') # the title for the page (template)
  99. )
  100. return render(request, 'pages/page.html', context=context)