288 |
288 |
if not self.backoffice:
|
289 |
289 |
self.backoffice = get_publisher().backoffice_directory_class()
|
290 |
290 |
|
291 |
|
try:
|
292 |
|
output = Directory._q_traverse(self, path)
|
293 |
|
if path and path[0] == 'saml':
|
294 |
|
return output
|
295 |
|
return self.automatic_sso(output)
|
296 |
|
except errors.TraversalError as e:
|
297 |
|
try:
|
298 |
|
f = FormDef.get_by_urlname(path[0])
|
299 |
|
except KeyError:
|
300 |
|
pass
|
301 |
|
else:
|
302 |
|
base_url = get_publisher().get_root_url()
|
303 |
|
|
304 |
|
uri_rest = get_request().environ.get('REQUEST_URI')
|
305 |
|
if not uri_rest:
|
306 |
|
# REQUEST_URI doesn't exist when using internal HTTP server
|
307 |
|
# (--http)
|
308 |
|
uri_rest = urllib.parse.quote(get_request().get_path())
|
309 |
|
if get_request().get_query():
|
310 |
|
uri_rest += '?' + get_request().get_query()
|
311 |
|
if uri_rest.startswith(base_url):
|
312 |
|
uri_rest = uri_rest[len(base_url) :]
|
313 |
|
if f.category:
|
314 |
|
if f.category.url_name == f.url_name:
|
315 |
|
return FormsRootDirectory(f.category)._q_traverse(path[1:])
|
316 |
|
return redirect('%s%s/%s' % (base_url, f.category.url_name, uri_rest))
|
317 |
|
|
318 |
|
try:
|
319 |
|
cat = Category.get_by_urlname(path[0])
|
320 |
|
except KeyError:
|
321 |
|
pass
|
322 |
|
else:
|
323 |
|
if len(path) == 1:
|
324 |
|
# category with missing trailing slash, redirect.
|
325 |
|
path = quixote.get_path()
|
326 |
|
return quixote.redirect(path + "/", permanent=True)
|
327 |
|
return FormsRootDirectory(cat)._q_traverse(path[1:])
|
328 |
|
|
329 |
|
raise e
|
330 |
|
|
331 |
|
def _q_lookup(self, component):
|
332 |
|
# is this a category ?
|
333 |
|
try:
|
334 |
|
category = Category.get_by_urlname(component)
|
335 |
|
except KeyError:
|
336 |
|
category = None
|
337 |
|
|
338 |
|
# is this a formdef ?
|
339 |
|
try:
|
340 |
|
formdef = FormDef.get_by_urlname(component)
|
341 |
|
except KeyError:
|
342 |
|
if category:
|
343 |
|
return FormsRootDirectory(category)
|
344 |
|
else:
|
345 |
|
# if the form has no category, or the request is a POST, or the
|
346 |
|
# slug matches both a category and a formdef, directly call
|
347 |
|
# into FormsRootDirectory.
|
348 |
|
if formdef.category_id is None or get_request().get_method() == 'POST' or (formdef and category):
|
349 |
|
get_response().filter['bigdiv'] = 'rub_service'
|
350 |
|
return FormsRootDirectory()._q_lookup(component)
|
351 |
|
|
352 |
|
# if there is category, let it fall back to raise TraversalError,
|
353 |
|
# it will get caught in _q_traverse that will redirect it to an
|
354 |
|
# URL embedding the category
|
355 |
|
|
356 |
|
return None
|
|
291 |
return super()._q_traverse(path)
|
357 |
292 |
|
358 |
293 |
def json(self):
|
359 |
294 |
return FormsRootDirectory().json()
|