comparison libervia/pages/files/list/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
17 access = C.PAGES_ACCESS_PROFILE 17 access = C.PAGES_ACCESS_PROFILE
18 template = "file/overview.html" 18 template = "file/overview.html"
19 19
20 20
21 def parse_url(self, request): 21 def parse_url(self, request):
22 self.getPathArgs(request, ["service", "*path"], min_args=1, service="jid", path="") 22 self.get_path_args(request, ["service", "*path"], min_args=1, service="jid", path="")
23 23
24 24
25 def add_breadcrumb(self, request, breadcrumbs): 25 def add_breadcrumb(self, request, breadcrumbs):
26 data = self.getRData(request) 26 data = self.get_r_data(request)
27 breadcrumbs.append({ 27 breadcrumbs.append({
28 "label": data["service"], 28 "label": data["service"],
29 "url": self.getURL(data["service"].full()), 29 "url": self.get_url(data["service"].full()),
30 "icon": "server", 30 "icon": "server",
31 }) 31 })
32 for idx, p in enumerate(data["path"]): 32 for idx, p in enumerate(data["path"]):
33 breadcrumbs.append({ 33 breadcrumbs.append({
34 "label": p, 34 "label": p,
35 "url": self.getURL(data["service"].full(), *data["path"][:idx+1]), 35 "url": self.get_url(data["service"].full(), *data["path"][:idx+1]),
36 "icon": "folder-open-empty", 36 "icon": "folder-open-empty",
37 }) 37 })
38 38
39 39
40 async def prepare_render(self, request): 40 async def prepare_render(self, request):
41 data = self.getRData(request) 41 data = self.get_r_data(request)
42 thumb_limit = data.get("thumb_limit", 400) 42 thumb_limit = data.get("thumb_limit", 400)
43 template_data = request.template_data 43 template_data = request.template_data
44 service, path_elts = data["service"], data["path"] 44 service, path_elts = data["service"], data["path"]
45 path = Path('/', *path_elts) 45 path = Path('/', *path_elts)
46 profile = self.getProfile(request) or C.SERVICE_PROFILE 46 profile = self.get_profile(request) or C.SERVICE_PROFILE
47 session_data = self.host.getSessionData( 47 session_data = self.host.get_session_data(
48 request, session_iface.IWebSession 48 request, session_iface.IWebSession
49 ) 49 )
50 50
51 try: 51 try:
52 files_data = await self.host.bridgeCall( 52 files_data = await self.host.bridge_call(
53 "FISList", service.full(), str(path), {}, profile) 53 "fis_list", service.full(), str(path), {}, profile)
54 except BridgeException as e: 54 except BridgeException as e:
55 if e.condition == 'item-not-found': 55 if e.condition == 'item-not-found':
56 log.debug( 56 log.debug(
57 f'"item-not-found" received for {path} at {service}, this may indicate ' 57 f'"item-not-found" received for {path} at {service}, this may indicate '
58 f'that the location is new') 58 f'that the location is new')
68 file_data["extra"] = json.loads(extra_raw) if extra_raw else {} 68 file_data["extra"] = json.loads(extra_raw) if extra_raw else {}
69 dir_path = path_elts + [file_data["name"]] 69 dir_path = path_elts + [file_data["name"]]
70 if file_data["type"] == C.FILE_TYPE_DIRECTORY: 70 if file_data["type"] == C.FILE_TYPE_DIRECTORY:
71 page = self 71 page = self
72 elif file_data["type"] == C.FILE_TYPE_FILE: 72 elif file_data["type"] == C.FILE_TYPE_FILE:
73 page = self.getPageByName("files_view") 73 page = self.get_page_by_name("files_view")
74 74
75 # we set URL for the last thumbnail which has a size below thumb_limit 75 # we set URL for the last thumbnail which has a size below thumb_limit
76 try: 76 try:
77 thumbnails = file_data["extra"]["thumbnails"] 77 thumbnails = file_data["extra"]["thumbnails"]
78 thumb = thumbnails[0] 78 thumb = thumbnails[0]
88 pass 88 pass
89 else: 89 else:
90 raise ValueError( 90 raise ValueError(
91 "unexpected file type: {file_type}".format(file_type=file_data["type"]) 91 "unexpected file type: {file_type}".format(file_type=file_data["type"])
92 ) 92 )
93 file_data["url"] = page.getURL(service.full(), *dir_path) 93 file_data["url"] = page.get_url(service.full(), *dir_path)
94 94
95 ## comments ## 95 ## comments ##
96 comments_url = file_data.get("comments_url") 96 comments_url = file_data.get("comments_url")
97 if comments_url: 97 if comments_url:
98 parsed_url = uri.parseXMPPUri(comments_url) 98 parsed_url = uri.parse_xmpp_uri(comments_url)
99 comments_service = file_data["comments_service"] = parsed_url["path"] 99 comments_service = file_data["comments_service"] = parsed_url["path"]
100 comments_node = file_data["comments_node"] = parsed_url["node"] 100 comments_node = file_data["comments_node"] = parsed_url["node"]
101 try: 101 try:
102 comments_count = file_data["comments_count"] = int( 102 comments_count = file_data["comments_count"] = int(
103 file_data["comments_count"] 103 file_data["comments_count"]
104 ) 104 )
105 except KeyError: 105 except KeyError:
106 comments_count = None 106 comments_count = None
107 if comments_count and data.get("retrieve_comments", False): 107 if comments_count and data.get("retrieve_comments", False):
108 file_data["comments"] = await pages_tools.retrieveComments( 108 file_data["comments"] = await pages_tools.retrieve_comments(
109 self, comments_service, comments_node, profile=profile 109 self, comments_service, comments_node, profile=profile
110 ) 110 )
111 111
112 # parent dir affiliation 112 # parent dir affiliation
113 # TODO: some caching? What if affiliation changes? 113 # TODO: some caching? What if affiliation changes?
114 114
115 try: 115 try:
116 affiliations = await self.host.bridgeCall( 116 affiliations = await self.host.bridge_call(
117 "FISAffiliationsGet", service.full(), "", str(path), profile 117 "fis_affiliations_get", service.full(), "", str(path), profile
118 ) 118 )
119 except BridgeException as e: 119 except BridgeException as e:
120 if e.condition == 'item-not-found': 120 if e.condition == 'item-not-found':
121 log.debug( 121 log.debug(
122 f'"item-not-found" received for {path} at {service}, this may indicate ' 122 f'"item-not-found" received for {path} at {service}, this may indicate '
132 132
133 directory_affiliation = affiliations.get(session_data.jid.userhost()) 133 directory_affiliation = affiliations.get(session_data.jid.userhost())
134 if directory_affiliation == "owner": 134 if directory_affiliation == "owner":
135 # we need to transtype dict items to str because with some bridges (D-Bus) 135 # we need to transtype dict items to str because with some bridges (D-Bus)
136 # we have a specific type which can't be exposed 136 # we have a specific type which can't be exposed
137 self.exposeToScripts( 137 self.expose_to_scripts(
138 request, 138 request,
139 affiliations={str(e): str(a) for e, a in affiliations.items()} 139 affiliations={str(e): str(a) for e, a in affiliations.items()}
140 ) 140 )
141 141
142 template_data["directory_affiliation"] = directory_affiliation 142 template_data["directory_affiliation"] = directory_affiliation
143 template_data["files_data"] = files_data 143 template_data["files_data"] = files_data
144 template_data["path"] = path 144 template_data["path"] = path
145 self.exposeToScripts( 145 self.expose_to_scripts(
146 request, 146 request,
147 directory_affiliation=str(directory_affiliation), 147 directory_affiliation=str(directory_affiliation),
148 files_service=service.full(), 148 files_service=service.full(),
149 files_path=str(path), 149 files_path=str(path),
150 ) 150 )
151 if path_elts: 151 if path_elts:
152 template_data["parent_url"] = self.getURL(service.full(), *path_elts[:-1]) 152 template_data["parent_url"] = self.get_url(service.full(), *path_elts[:-1])