Piki is a minimal wiki
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

views.py 3.9KB

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