1#!/usr/bin/env python3
2
3"""Map URLs to Django functions."""
4
5from django.urls import path
6from django.urls import re_path
7from django.views.generic import TemplateView
8
9import chart.reportviewer.views
10from chart.project import settings
11
12app_name = 'reportviewer'
13
14urlpatterns = [
15 # Landing page, list of all reports
16 path('',
17 chart.reportviewer.views.index,
18 name='index'),
19
20 # Most recently generated reports
21 path('latest',
22 chart.reportviewer.views.latest_reports,
23 name='latest_reports'),
24
25 # Calendar page html
26 path('calendar',
27 chart.reportviewer.views.calendar,
28 name='calendar'),
29
30 # Calendar page js
31 path('calendar.js',
32 TemplateView.as_view(template_name='reportviewer/calendar.js',
33 content_type='text/javascript'),
34 name='calendar/js'),
35
36 # Retrieve a file from inside a report
37 # shouldn't this work?
38 # url(r'^report/(?P<report_name>[a-zA-Z0-9_]+)/((?P<filename>[a-zA-Z0-9_.-]+))?$',
39 # chart.reportviewer.views.report_file),
40 # but it works fine if we supply 2 rules, with and without the filename part
41 re_path(r'report/(?P<report_name>[a-zA-Z0-9_-]+)$',
42 chart.reportviewer.views.report_index,
43 name='report/index'),
44 re_path(r'report/(?P<report_name>[a-zA-Z0-9_-]+)/(?P<filename>[a-zA-Z0-9_.-]+)$',
45 chart.reportviewer.views.report_file,
46 name='report/file'),
47
48 # see the raw report.html with no headers
49 re_path(r'raw/(?P<report_name>[a-zA-Z0-9_-]+)/(?P<filename>[a-zA-Z0-9_.-]+)$',
50 chart.reportviewer.views.raw,
51 name='report/raw'),
52
53 # Javascript for all reports
54 path('report.js',
55 TemplateView.as_view(template_name='reportviewer/report.js',
56 content_type='text/javascript'),
57 name='report/js'),
58
59 # Ajax call used by report js to navigate to other pages
60 path('nav',
61 chart.reportviewer.views.nav,
62 name='nav'),
63
64 ## Initial ajax request to show Info popup
65 #url(r'^info/(?P<report_name>\d+)$', chart.reportviewer.views.info),
66
67 ## Internal call to return content of popup
68 #url(r'^info$', chart.reportviewer.views.info, name='chart.reportviewer.views.info_raw'),
69
70 # Download a report as a .zip file
71 re_path('zip/(?P<report_name>[a-zA-Z0-9_-]+)$',
72 chart.reportviewer.views.zip_download,
73 name='report/zip'),
74
75 # Unpublish a report
76 re_path(r'unpublish/(?P<report_name>[a-zA-Z0-9_-]+)$',
77 chart.reportviewer.views.handle_unpublish_report,
78 name='report/unpublish'),
79
80 # Publish a report
81 re_path(r'publish/(?P<report_name>[a-zA-Z0-9_-]+)$',
82 chart.reportviewer.views.handle_publish_report,
83 name='report/publish'),
84
85 # Download a report as a .pdf
86 re_path(r'pdf/(?P<report_name>[a-zA-Z0-9_-]+)$',
87 chart.reportviewer.views.pdf_convert,
88 name='report/pdf'),
89
90 # Ajax call to store modified report
91 path('save',
92 chart.reportviewer.views.save,
93 name='report/save'),
94
95 # Retrieve a specific report revision
96 #url(r'^revision/(?P<report_name>\d+)/(?P<filename>[a-zA-Z0-9_.-]+)/(?P<revision_number>\d+)$',
97 # chart.reportviewer.views.revision),
98]
99
100if not settings.LOCKDOWN_RESTRICTED_ACCESS:
101 urlpatterns += [
102 # Edit report
103 re_path(r'edit/(?P<report_name>[a-zA-Z0-9_-]+)/(?P<filename>[a-zA-Z0-9_.-]+)',
104 chart.reportviewer.views.edit,
105 name='report/edit'),
106
107 # Edit page js
108 path('edit.js',
109 TemplateView.as_view(template_name='reportviewer/edit.js',
110 content_type='text/javascript'), # pylint:disable=E1120
111 name='report/edit/js'),
112
113 # Ajax call to store modified report
114 path('save',
115 chart.reportviewer.views.save,
116 name='report/save'),
117]