Piki is a minimal wiki
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

views.py 3.8KB

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