def loadCustomTemplate(request, directory_settings, template_src_settings, fallbackoption): # TODO: template_str is not used. refactor this or use it custom_template_path = None base_path = request.registry.settings["root_dir"] relative_path = DirectoryRequestHandler.requestfolderpath(request) if template_src_settings in directory_settings: dir_path = directory_settings[template_src_settings] possible_prefixes = {"projectlocal:": base_path, "folderlocal:": relative_path, "absolute:": ""} found = False for (prefix, path) in possible_prefixes.items(): if not dir_path.startswith(prefix): continue dir_path = dir_path[len(prefix) :] custom_template_path = os.path.join(path, dir_path) found = True break if not found: log = logging.getLogger(__name__) log.info("Specified dir_path starts with unknown prefix: {0}".format(dir_path)) # check if the custom_directory_template is valid if custom_template_path is not None and not os.path.exists(custom_template_path): custom_template_path = None if custom_template_path is None: custom_template_path = fallbackoption return custom_template_path
def login(self): login_url = self.request.resource_url(self.request.context, "login") referrer = self.request.url if referrer == login_url: referrer = "/" # never use the login form itself as came_from came_from = self.request.params.get("came_from", referrer) message = "" login = "" password = "" if "form.submitted" in self.request.params: login = self.request.params["login"] password = self.request.params["password"] usermanager = self.request.registry.settings["usermanager"] if usermanager.validate_password(login, password): headers = remember(self.request, login) return HTTPFound(location=came_from, headers=headers) message = "Failed login" description_is_private = False if "privacy.description" in self.request.registry.settings: description_is_private = self.request.registry.settings["privacy.description"] == "private" # load the information try: relative_path = DirectoryRequestHandler.requestfolderpath(self.request) description = os.path.join(relative_path, ".description.json") if not os.path.exists(description) or description_is_private: information = None else: with open_resource(description) as file: json_file = file.read() description_obj = jsonpickle.decode(json_file) information = description_obj["shortdescription"] except BaseException as e: information = "Error: {0}".format(e.message) log = logging.getLogger(__name__) log.error(e.message) return dict( message=message, url=self.request.application_url + "/login", came_from=came_from, login=login, password=password, information=information, )