Piki is a minimal wiki
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

views.py 4.1KB

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