PageRenderTime 277ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/helpdesk/urls.py

https://github.com/rossp/django-helpdesk
Python | 234 lines | 191 code | 0 blank | 43 comment | 1 complexity | d162f1de554defb9f6fe8825a39058fc MD5 | raw file
  1. """
  2. django-helpdesk - A Django powered ticket tracker for small enterprise.
  3. (c) Copyright 2008 Jutda. All Rights Reserved. See LICENSE for details.
  4. urls.py - Mapping of URL's to our various views. Note we always used NAMED
  5. views for simplicity in linking later on.
  6. """
  7. from django.urls import path, re_path
  8. from django.contrib.auth.decorators import login_required
  9. from django.contrib.auth import views as auth_views
  10. from django.urls import include
  11. from django.views.generic import TemplateView
  12. from rest_framework.routers import DefaultRouter
  13. from helpdesk.decorators import helpdesk_staff_member_required, protect_view
  14. from helpdesk.views import feeds, staff, public, login
  15. from helpdesk import settings as helpdesk_settings
  16. from helpdesk.views.api import TicketViewSet, CreateUserView
  17. if helpdesk_settings.HELPDESK_KB_ENABLED:
  18. from helpdesk.views import kb
  19. try:
  20. # TODO: why is it imported? due to some side-effect or by mistake?
  21. import helpdesk.tasks # NOQA
  22. except ImportError:
  23. pass
  24. class DirectTemplateView(TemplateView):
  25. extra_context = None
  26. def get_context_data(self, **kwargs):
  27. context = super(self.__class__, self).get_context_data(**kwargs)
  28. if self.extra_context is not None:
  29. for key, value in self.extra_context.items():
  30. if callable(value):
  31. context[key] = value()
  32. else:
  33. context[key] = value
  34. return context
  35. app_name = "helpdesk"
  36. base64_pattern = r"(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
  37. urlpatterns = [
  38. path("dashboard/", staff.dashboard, name="dashboard"),
  39. path("tickets/", staff.ticket_list, name="list"),
  40. path("tickets/update/", staff.mass_update, name="mass_update"),
  41. path("tickets/merge", staff.merge_tickets, name="merge_tickets"),
  42. path("tickets/<int:ticket_id>/", staff.view_ticket, name="view"),
  43. path(
  44. "tickets/<int:ticket_id>/followup_edit/<int:followup_id>/",
  45. staff.followup_edit,
  46. name="followup_edit",
  47. ),
  48. path(
  49. "tickets/<int:ticket_id>/followup_delete/<int:followup_id>/",
  50. staff.followup_delete,
  51. name="followup_delete",
  52. ),
  53. path("tickets/<int:ticket_id>/edit/", staff.edit_ticket, name="edit"),
  54. path("tickets/<int:ticket_id>/update/", staff.update_ticket, name="update"),
  55. path("tickets/<int:ticket_id>/delete/", staff.delete_ticket, name="delete"),
  56. path("tickets/<int:ticket_id>/hold/", staff.hold_ticket, name="hold"),
  57. path("tickets/<int:ticket_id>/unhold/", staff.unhold_ticket, name="unhold"),
  58. path("tickets/<int:ticket_id>/cc/", staff.ticket_cc, name="ticket_cc"),
  59. path("tickets/<int:ticket_id>/cc/add/", staff.ticket_cc_add, name="ticket_cc_add"),
  60. path(
  61. "tickets/<int:ticket_id>/cc/delete/<int:cc_id>/",
  62. staff.ticket_cc_del,
  63. name="ticket_cc_del",
  64. ),
  65. path(
  66. "tickets/<int:ticket_id>/dependency/add/",
  67. staff.ticket_dependency_add,
  68. name="ticket_dependency_add",
  69. ),
  70. path(
  71. "tickets/<int:ticket_id>/dependency/delete/<int:dependency_id>/",
  72. staff.ticket_dependency_del,
  73. name="ticket_dependency_del",
  74. ),
  75. path(
  76. "tickets/<int:ticket_id>/attachment_delete/<int:attachment_id>/",
  77. staff.attachment_del,
  78. name="attachment_del",
  79. ),
  80. re_path(r"^raw/(?P<type>\w+)/$", staff.raw_details, name="raw"),
  81. path("rss/", staff.rss_list, name="rss_index"),
  82. path("reports/", staff.report_index, name="report_index"),
  83. re_path(r"^reports/(?P<report>\w+)/$", staff.run_report, name="run_report"),
  84. path("save_query/", staff.save_query, name="savequery"),
  85. path("delete_query/<int:id>/", staff.delete_saved_query, name="delete_query"),
  86. path("settings/", staff.EditUserSettingsView.as_view(), name="user_settings"),
  87. path("ignore/", staff.email_ignore, name="email_ignore"),
  88. path("ignore/add/", staff.email_ignore_add, name="email_ignore_add"),
  89. path("ignore/delete/<int:id>/", staff.email_ignore_del, name="email_ignore_del"),
  90. re_path(
  91. r"^datatables_ticket_list/(?P<query>{})$".format(base64_pattern),
  92. staff.datatables_ticket_list,
  93. name="datatables_ticket_list",
  94. ),
  95. re_path(
  96. r"^timeline_ticket_list/(?P<query>{})$".format(base64_pattern),
  97. staff.timeline_ticket_list,
  98. name="timeline_ticket_list",
  99. ),
  100. ]
  101. if helpdesk_settings.HELPDESK_ENABLE_DEPENDENCIES_ON_TICKET:
  102. urlpatterns += [
  103. re_path(
  104. r"^tickets/(?P<ticket_id>[0-9]+)/dependency/add/$",
  105. staff.ticket_dependency_add,
  106. name="ticket_dependency_add",
  107. ),
  108. re_path(
  109. r"^tickets/(?P<ticket_id>[0-9]+)/dependency/delete/(?P<dependency_id>[0-9]+)/$",
  110. staff.ticket_dependency_del,
  111. name="ticket_dependency_del",
  112. ),
  113. ]
  114. urlpatterns += [
  115. path("", protect_view(public.Homepage.as_view()), name="home"),
  116. path("tickets/submit/", public.create_ticket, name="submit"),
  117. path(
  118. "tickets/submit_iframe/",
  119. public.CreateTicketIframeView.as_view(),
  120. name="submit_iframe",
  121. ),
  122. path(
  123. "tickets/success_iframe/", # Ticket was submitted successfully
  124. public.SuccessIframeView.as_view(),
  125. name="success_iframe",
  126. ),
  127. path("view/", public.view_ticket, name="public_view"),
  128. path("change_language/", public.change_language, name="public_change_language"),
  129. ]
  130. urlpatterns += [
  131. re_path(
  132. r"^rss/user/(?P<user_name>[a-zA-Z0-9\_\.]+)/",
  133. helpdesk_staff_member_required(feeds.OpenTicketsByUser()),
  134. name="rss_user",
  135. ),
  136. re_path(
  137. r"^rss/user/(?P<user_name>[^/]+)/(?P<queue_slug>[A-Za-z0-9_-]+)/$",
  138. helpdesk_staff_member_required(feeds.OpenTicketsByUser()),
  139. name="rss_user_queue",
  140. ),
  141. re_path(
  142. r"^rss/queue/(?P<queue_slug>[A-Za-z0-9_-]+)/$",
  143. helpdesk_staff_member_required(feeds.OpenTicketsByQueue()),
  144. name="rss_queue",
  145. ),
  146. path(
  147. "rss/unassigned/",
  148. helpdesk_staff_member_required(feeds.UnassignedTickets()),
  149. name="rss_unassigned",
  150. ),
  151. path(
  152. "rss/recent_activity/",
  153. helpdesk_staff_member_required(feeds.RecentFollowUps()),
  154. name="rss_activity",
  155. ),
  156. ]
  157. # API is added to url conf based on the setting (False by default)
  158. if helpdesk_settings.HELPDESK_ACTIVATE_API_ENDPOINT:
  159. router = DefaultRouter()
  160. router.register(r"tickets", TicketViewSet, basename="ticket")
  161. router.register(r"users", CreateUserView, basename="user")
  162. urlpatterns += [re_path(r"^api/", include(router.urls))]
  163. urlpatterns += [
  164. path("login/", login.login, name="login"),
  165. path(
  166. "logout/",
  167. auth_views.LogoutView.as_view(
  168. template_name="helpdesk/registration/login.html", next_page="../"
  169. ),
  170. name="logout",
  171. ),
  172. path(
  173. "password_change/",
  174. auth_views.PasswordChangeView.as_view(
  175. template_name="helpdesk/registration/change_password.html",
  176. success_url="./done",
  177. ),
  178. name="password_change",
  179. ),
  180. path(
  181. "password_change/done",
  182. auth_views.PasswordChangeDoneView.as_view(
  183. template_name="helpdesk/registration/change_password_done.html",
  184. ),
  185. name="password_change_done",
  186. ),
  187. ]
  188. if helpdesk_settings.HELPDESK_KB_ENABLED:
  189. urlpatterns += [
  190. path("kb/", kb.index, name="kb_index"),
  191. re_path(r"^kb/(?P<slug>[A-Za-z0-9_-]+)/$", kb.category, name="kb_category"),
  192. path("kb/<int:item>/vote/", kb.vote, name="kb_vote"),
  193. re_path(
  194. r"^kb_iframe/(?P<slug>[A-Za-z0-9_-]+)/$",
  195. kb.category_iframe,
  196. name="kb_category_iframe",
  197. ),
  198. ]
  199. urlpatterns += [
  200. path(
  201. "help/context/",
  202. TemplateView.as_view(template_name="helpdesk/help_context.html"),
  203. name="help_context",
  204. ),
  205. path(
  206. "system_settings/",
  207. login_required(
  208. DirectTemplateView.as_view(template_name="helpdesk/system_settings.html")
  209. ),
  210. name="system_settings",
  211. ),
  212. ]