Piki is a minimal wiki
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

views.py 4.0KB

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