967
|
1 #!/usr/bin/env python2.7 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 from libervia.server.constants import Const as C |
|
5 from sat.core.i18n import _ |
|
6 from twisted.internet import defer |
|
7 from twisted.words.protocols.jabber import jid |
|
8 from sat.tools.common import template_xmlui |
|
9 from sat.tools.common import data_objects |
|
10 from sat.core.log import getLogger |
|
11 log = getLogger('pages/ticket') |
|
12 """ticket handling pages""" |
|
13 |
|
14 name = u'tickets_list' |
|
15 access = C.PAGES_ACCESS_PUBLIC |
|
16 template = u"ticket/overview.html" |
|
17 trailing_slash = True |
|
18 |
|
19 |
|
20 def parse_url(self, request): |
|
21 try: |
|
22 service = self.nextPath(request) |
|
23 except IndexError: |
|
24 service = u'' |
|
25 else: |
|
26 if not service or service == u'@': |
|
27 service = u'' |
|
28 |
|
29 if service: |
|
30 try: |
|
31 service = jid.JID(service) |
|
32 except Exception: |
|
33 log.warning(_(u"bad service entered: {}").format(service)) |
|
34 self.pageError(request, C.HTTP_BAD_REQUEST) |
|
35 |
|
36 try: |
|
37 node = self.nextPath(request) |
|
38 except IndexError: |
|
39 node = u'' |
|
40 else: |
|
41 if not node or node == u'@': |
|
42 node = u'' |
|
43 |
|
44 data = self.getRData(request) |
|
45 |
|
46 data['service'] = service |
|
47 data['node'] = node |
|
48 |
|
49 |
|
50 @defer.inlineCallbacks |
|
51 def prepare_render(self, request): |
|
52 data = self.getRData(request) |
|
53 template_data = request.template_data |
|
54 service, node = data.get(u'service', u''), data.get(u'node', u'') |
|
55 profile = self.getProfile(request) or C.SERVICE_PROFILE |
|
56 |
|
57 tickets = yield self.host.bridge.ticketsGet(service.full() if service else u'', node, C.NO_LIMIT, [], '', {}, profile) |
|
58 tickets = [template_xmlui.create(self.host, x) for x in tickets[0]] |
|
59 template_data[u'tickets'] = tickets |
|
60 template_data[u'on_ticket_click'] = data_objects.OnClick(url="view/{item.id}") |