def look_up_library_for_role(self, role):
     """If the role is affiliated with a particular library, as opposed to being
     sitewide, find the library (and check that it actually exists)."""
     library = None
     library_short_name = role.get("library")
     if library_short_name:
         library = Library.lookup(self._db, library_short_name)
         if not library:
             return LIBRARY_NOT_FOUND.detailed(_("Library \"%(short_name)s\" does not exist.", short_name=library_short_name))
     return library
Example #2
0
 def look_up_library_for_role(self, role):
     """If the role is affiliated with a particular library, as opposed to being
     sitewide, find the library (and check that it actually exists)."""
     library = None
     library_short_name = role.get("library")
     if library_short_name:
         library = Library.lookup(self._db, library_short_name)
         if not library:
             return LIBRARY_NOT_FOUND.detailed(
                 _("Library \"%(short_name)s\" does not exist.",
                   short_name=library_short_name))
     return library
Example #3
0
    def library_for_request(self, library_short_name):
        """Look up the library the user is trying to access.

        Since this is called on pretty much every request, it's also
        an appropriate time to check whether the site configuration
        has been changed and needs to be updated.
        """
        self.manager.reload_settings_if_changed()

        if library_short_name:
            library = Library.lookup(self._db, short_name=library_short_name)
        else:
            library = Library.default(self._db)

        if not library:
            return LIBRARY_NOT_FOUND
        flask.request.library = library
        return library