comparison libervia/pages/lists/view_item/page_meta.py @ 1509:106bae41f5c8

massive refactoring from camelCase -> snake_case. See backend commit log for more details
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:44:11 +0200
parents ce879da7fcf7
children
comparison
equal deleted inserted replaced
1508:ec3ad9abf9f9 1509:106bae41f5c8
18 access = C.PAGES_ACCESS_PUBLIC 18 access = C.PAGES_ACCESS_PUBLIC
19 template = "list/item.html" 19 template = "list/item.html"
20 20
21 21
22 def parse_url(self, request): 22 def parse_url(self, request):
23 self.getPathArgs(request, ["service", "node", "item_id"], service="jid", node="@") 23 self.get_path_args(request, ["service", "node", "item_id"], service="jid", node="@")
24 data = self.getRData(request) 24 data = self.get_r_data(request)
25 if data["item_id"] is None: 25 if data["item_id"] is None:
26 log.warning(_("no list item id specified")) 26 log.warning(_("no list item id specified"))
27 self.pageError(request, C.HTTP_BAD_REQUEST) 27 self.page_error(request, C.HTTP_BAD_REQUEST)
28 28
29 29
30 def add_breadcrumb(self, request, breadcrumbs): 30 def add_breadcrumb(self, request, breadcrumbs):
31 data = self.getRData(request) 31 data = self.get_r_data(request)
32 list_url = self.getPageByName("lists").getURL(data["service"].full(), 32 list_url = self.get_page_by_name("lists").get_url(data["service"].full(),
33 data.get("node") or "@") 33 data.get("node") or "@")
34 breadcrumbs.append({ 34 breadcrumbs.append({
35 "label": D_("List"), 35 "label": D_("List"),
36 "url": list_url 36 "url": list_url
37 }) 37 })
39 "label": D_("Item"), 39 "label": D_("Item"),
40 }) 40 })
41 41
42 42
43 async def prepare_render(self, request): 43 async def prepare_render(self, request):
44 data = self.getRData(request) 44 data = self.get_r_data(request)
45 template_data = request.template_data 45 template_data = request.template_data
46 session = self.host.getSessionData(request, session_iface.IWebSession) 46 session = self.host.get_session_data(request, session_iface.IWebSession)
47 service, node, item_id = ( 47 service, node, item_id = (
48 data.get("service", ""), 48 data.get("service", ""),
49 data.get("node", ""), 49 data.get("node", ""),
50 data["item_id"], 50 data["item_id"],
51 ) 51 )
52 namespace = node or self.host.ns_map["tickets"] 52 namespace = node or self.host.ns_map["tickets"]
53 node = await self.host.bridgeCall("psSchemaSubmittedNodeGet", namespace) 53 node = await self.host.bridge_call("ps_schema_submitted_node_get", namespace)
54 54
55 profile = self.getProfile(request) 55 profile = self.get_profile(request)
56 if profile is None: 56 if profile is None:
57 profile = C.SERVICE_PROFILE 57 profile = C.SERVICE_PROFILE
58 58
59 list_raw = await self.host.bridgeCall( 59 list_raw = await self.host.bridge_call(
60 "listGet", 60 "list_get",
61 service.full() if service else "", 61 service.full() if service else "",
62 node, 62 node,
63 C.NO_LIMIT, 63 C.NO_LIMIT,
64 [item_id], 64 [item_id],
65 "", 65 "",
73 comments_uri = list_item.widgets["comments_uri"].value 73 comments_uri = list_item.widgets["comments_uri"].value
74 except KeyError: 74 except KeyError:
75 pass 75 pass
76 else: 76 else:
77 if comments_uri: 77 if comments_uri:
78 uri_data = uri.parseXMPPUri(comments_uri) 78 uri_data = uri.parse_xmpp_uri(comments_uri)
79 template_data["comments_node"] = comments_node = uri_data["node"] 79 template_data["comments_node"] = comments_node = uri_data["node"]
80 template_data["comments_service"] = comments_service = uri_data["path"] 80 template_data["comments_service"] = comments_service = uri_data["path"]
81 try: 81 try:
82 comments = data_format.deserialise(await self.host.bridgeCall( 82 comments = data_format.deserialise(await self.host.bridge_call(
83 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], 83 "mb_get", comments_service, comments_node, C.NO_LIMIT, [],
84 data_format.serialise({}), profile 84 data_format.serialise({}), profile
85 )) 85 ))
86 except BridgeException as e: 86 except BridgeException as e:
87 if e.classname == 'NotFound' or e.condition == 'item-not-found': 87 if e.classname == 'NotFound' or e.condition == 'item-not-found':
88 log.warning( 88 log.warning(
91 ) 91 )
92 else: 92 else:
93 raise e 93 raise e
94 else: 94 else:
95 template_data["comments"] = comments 95 template_data["comments"] = comments
96 template_data["login_url"] = self.getPageRedirectURL(request) 96 template_data["login_url"] = self.get_page_redirect_url(request)
97 self.exposeToScripts( 97 self.expose_to_scripts(
98 request, 98 request,
99 comments_node=comments_node, 99 comments_node=comments_node,
100 comments_service=comments_service, 100 comments_service=comments_service,
101 ) 101 )
102 102
105 # the node owner 105 # the node owner
106 publisher = jid.JID(list_item.widgets["publisher"].value) 106 publisher = jid.JID(list_item.widgets["publisher"].value)
107 is_publisher = publisher.userhostJID() == session.jid.userhostJID() 107 is_publisher = publisher.userhostJID() == session.jid.userhostJID()
108 affiliation = None 108 affiliation = None
109 if not is_publisher: 109 if not is_publisher:
110 affiliation = await self.host.getAffiliation(request, service, node) 110 affiliation = await self.host.get_affiliation(request, service, node)
111 if is_publisher or affiliation == "owner": 111 if is_publisher or affiliation == "owner":
112 self.exposeToScripts( 112 self.expose_to_scripts(
113 request, 113 request,
114 pubsub_service = service.full(), 114 pubsub_service = service.full(),
115 pubsub_node = node, 115 pubsub_node = node,
116 pubsub_item = item_id, 116 pubsub_item = item_id,
117 ) 117 )
118 template_data["can_modify"] = True 118 template_data["can_modify"] = True
119 template_data["url_list_item_edit"] = self.getURLByPath( 119 template_data["url_list_item_edit"] = self.get_url_by_path(
120 SubPage("list_edit"), 120 SubPage("list_edit"),
121 service.full(), 121 service.full(),
122 node or "@", 122 node or "@",
123 item_id, 123 item_id,
124 ) 124 )
126 # we add xmpp: URI 126 # we add xmpp: URI
127 uri_args = {'path': service.full()} 127 uri_args = {'path': service.full()}
128 uri_args['node'] = node 128 uri_args['node'] = node
129 if item_id: 129 if item_id:
130 uri_args['item'] = item_id 130 uri_args['item'] = item_id
131 template_data['xmpp_uri'] = uri.buildXMPPUri('pubsub', **uri_args) 131 template_data['xmpp_uri'] = uri.build_xmpp_uri('pubsub', **uri_args)
132 132
133 133
134 async def on_data_post(self, request): 134 async def on_data_post(self, request):
135 type_ = self.getPostedData(request, "type") 135 type_ = self.get_posted_data(request, "type")
136 if type_ == "comment": 136 if type_ == "comment":
137 blog_page = self.getPageByName("blog_view") 137 blog_page = self.get_page_by_name("blog_view")
138 await blog_page.on_data_post(self, request) 138 await blog_page.on_data_post(self, request)
139 else: 139 else:
140 log.warning(_("Unhandled data type: {}").format(type_)) 140 log.warning(_("Unhandled data type: {}").format(type_))