Mercurial > libervia-web
comparison src/pages/tickets/page_meta.py @ 981:97cce8c1e96a
pages(tickets): better URL handling:
- do no accept anymore URL without service or node
- use new getSubPageURL for tickets_new and individual ticket viewing URLs
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 14 Nov 2017 08:37:48 +0100 |
parents | c8cafe316f6f |
children | 7fdd24014aa4 |
comparison
equal
deleted
inserted
replaced
980:bcacf970f970 | 981:97cce8c1e96a |
---|---|
15 access = C.PAGES_ACCESS_PUBLIC | 15 access = C.PAGES_ACCESS_PUBLIC |
16 template = u"ticket/overview.html" | 16 template = u"ticket/overview.html" |
17 | 17 |
18 | 18 |
19 def parse_url(self, request): | 19 def parse_url(self, request): |
20 # check the service and node to use | |
20 try: | 21 try: |
21 service = self.nextPath(request) | 22 service = self.nextPath(request) |
23 node = self.nextPath(request) | |
22 except IndexError: | 24 except IndexError: |
25 log.warning(_(u"missing service and node")) | |
26 self.pageError(request, C.HTTP_BAD_REQUEST) | |
27 | |
28 if not service or service == u'@': | |
23 service = u'' | 29 service = u'' |
24 else: | |
25 if not service or service == u'@': | |
26 service = u'' | |
27 | 30 |
28 if service: | 31 if service: |
29 try: | 32 try: |
30 service = jid.JID(service) | 33 service = jid.JID(service) |
31 except Exception: | 34 except Exception: |
32 log.warning(_(u"bad service entered: {}").format(service)) | 35 log.warning(_(u"bad service entered: {}").format(service)) |
33 self.pageError(request, C.HTTP_BAD_REQUEST) | 36 self.pageError(request, C.HTTP_BAD_REQUEST) |
34 | 37 |
35 try: | 38 if not node or node == u'@': |
36 node = self.nextPath(request) | |
37 except IndexError: | |
38 node = u'' | 39 node = u'' |
39 else: | |
40 if not node or node == u'@': | |
41 node = u'' | |
42 | 40 |
43 data = self.getRData(request) | 41 data = self.getRData(request) |
44 data['service'] = service | 42 data['service'] = service |
45 data['node'] = node | 43 data['node'] = node |
46 | 44 |
47 template_data = request.template_data | 45 template_data = request.template_data |
48 template_data[u'url_tickets_list'] = self.getPageByName('tickets_list').getURL(service.full(), node or u'@') | 46 template_data[u'url_tickets_list'] = self.getPageByName('tickets_list').getURL(service.full(), node or u'@') |
49 template_data[u'url_tickets_new'] = u'/' + ('/'.join(request.prepath + ['new']).decode('utf-8')) | 47 template_data[u'url_tickets_new'] = self.getSubPageURL(request, 'tickets_new') |
50 | 48 |
51 @defer.inlineCallbacks | 49 @defer.inlineCallbacks |
52 def prepare_render(self, request): | 50 def prepare_render(self, request): |
53 data = self.getRData(request) | 51 data = self.getRData(request) |
54 template_data = request.template_data | 52 template_data = request.template_data |
55 service, node = data.get(u'service', u''), data.get(u'node', u'') | 53 service, node = data[u'service'], data[u'node'] |
56 profile = self.getProfile(request) or C.SERVICE_PROFILE | 54 profile = self.getProfile(request) or C.SERVICE_PROFILE |
57 | 55 |
58 tickets = yield self.host.bridge.ticketsGet(service.full() if service else u'', node, C.NO_LIMIT, [], '', {}, profile) | 56 tickets = yield self.host.bridge.ticketsGet(service.full() if service else u'', node, C.NO_LIMIT, [], '', {}, profile) |
59 tickets = [template_xmlui.create(self.host, x) for x in tickets[0]] | 57 template_data[u'tickets'] = [template_xmlui.create(self.host, x) for x in tickets[0]] |
60 template_data[u'tickets'] = tickets | 58 template_data[u'on_ticket_click'] = data_objects.OnClick(url=self.getSubPageURL(request, 'tickets_view', '{item.id}')) |
61 template_data[u'on_ticket_click'] = data_objects.OnClick(url="view/{item.id}") |