annotate src/pages/tickets/page_meta.py @ 999:ded41172dcb5

pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
author Goffi <goffi@goffi.org>
date Fri, 05 Jan 2018 16:30:03 +0100
parents 7fdd24014aa4
children c1c74d97a691
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2.7
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from libervia.server.constants import Const as C
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.core.i18n import _
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from twisted.internet import defer
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from twisted.words.protocols.jabber import jid
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 from sat.tools.common import template_xmlui
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 from sat.tools.common import data_objects
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 from sat.core.log import getLogger
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 log = getLogger('pages/ticket')
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 """ticket handling pages"""
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 name = u'tickets_list'
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 access = C.PAGES_ACCESS_PUBLIC
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 template = u"ticket/overview.html"
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 def parse_url(self, request):
981
97cce8c1e96a pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
20 # check the service and node to use
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 try:
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 service = self.nextPath(request)
981
97cce8c1e96a pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
23 node = self.nextPath(request)
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 except IndexError:
981
97cce8c1e96a pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
25 log.warning(_(u"missing service and node"))
97cce8c1e96a pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
26 self.pageError(request, C.HTTP_BAD_REQUEST)
97cce8c1e96a pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
27
97cce8c1e96a pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
28 if not service or service == u'@':
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 service = u''
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 if service:
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 try:
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 service = jid.JID(service)
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 except Exception:
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 log.warning(_(u"bad service entered: {}").format(service))
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 self.pageError(request, C.HTTP_BAD_REQUEST)
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
981
97cce8c1e96a pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
38 if not node or node == u'@':
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 node = u''
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
986
7fdd24014aa4 pages(tickets): use new cache mechanism for tickets list
Goffi <goffi@goffi.org>
parents: 981
diff changeset
41
7fdd24014aa4 pages(tickets): use new cache mechanism for tickets list
Goffi <goffi@goffi.org>
parents: 981
diff changeset
42 self.checkCache(request, C.CACHE_PUBSUB, service=service, node=node, short='tickets')
7fdd24014aa4 pages(tickets): use new cache mechanism for tickets list
Goffi <goffi@goffi.org>
parents: 981
diff changeset
43
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 data = self.getRData(request)
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 data['service'] = service
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 data['node'] = node
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
973
2e75dc986e03 pages (tickets): URLs for list and new are set in the template for the whole subhierarchy
Goffi <goffi@goffi.org>
parents: 967
diff changeset
48 template_data = request.template_data
2e75dc986e03 pages (tickets): URLs for list and new are set in the template for the whole subhierarchy
Goffi <goffi@goffi.org>
parents: 967
diff changeset
49 template_data[u'url_tickets_list'] = self.getPageByName('tickets_list').getURL(service.full(), node or u'@')
981
97cce8c1e96a pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
50 template_data[u'url_tickets_new'] = self.getSubPageURL(request, 'tickets_new')
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 @defer.inlineCallbacks
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 def prepare_render(self, request):
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 data = self.getRData(request)
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 template_data = request.template_data
981
97cce8c1e96a pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
56 service, node = data[u'service'], data[u'node']
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 profile = self.getProfile(request) or C.SERVICE_PROFILE
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 tickets = yield self.host.bridge.ticketsGet(service.full() if service else u'', node, C.NO_LIMIT, [], '', {}, profile)
981
97cce8c1e96a pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
60 template_data[u'tickets'] = [template_xmlui.create(self.host, x) for x in tickets[0]]
97cce8c1e96a pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents: 978
diff changeset
61 template_data[u'on_ticket_click'] = data_objects.OnClick(url=self.getSubPageURL(request, 'tickets_view', '{item.id}'))