Exemplo n.º 1
0
    def _get_available_loans(self, current_loans):

        default_type = 'bookreader'

        loans = []

        # Check if we have a possible loan - may not yet be fulfilled in ACS4
        if current_loans:
            # There is a current loan or offer
            return []

        # Create list of possible loan formats
        resource_pattern = r'acs:(\w+):(.*)'
        for resource_urn in self.get_lending_resources():
            if resource_urn.startswith('acs:'):
                (type, resource_id) = re.match(resource_pattern,
                                               resource_urn).groups()
                loans.append({
                    'resource_id': resource_id,
                    'resource_type': type,
                    'size': None
                })
            elif resource_urn.startswith('bookreader'):
                loans.append({
                    'resource_id': resource_urn,
                    'resource_type': 'bookreader',
                    'size': None
                })

        # Put default type at start of list, then sort by type name
        def loan_key(loan):
            if loan['resource_type'] == default_type:
                return '1-%s' % loan['resource_type']
            else:
                return '2-%s' % loan['resource_type']

        loans = sorted(loans, key=loan_key)

        # For each possible loan, check if it is available We
        # shouldn't be out of sync (we already checked
        # get_edition_loans for current loans) but we fail safe, for
        # example the book may have been borrowed in a dev instance
        # against the live ACS4 server
        for loan in loans:
            if borrow.is_loaned_out(loan['resource_id']):
                # Only a single loan of an item is allowed
                # $$$ log out of sync state
                return []

        return loans
Exemplo n.º 2
0
    def _get_available_loans(self, current_loans):

        default_type = 'bookreader'

        loans = []

        # Check if we have a possible loan - may not yet be fulfilled in ACS4
        if current_loans:
            # There is a current loan or offer
            return []

        # Create list of possible loan formats
        resource_pattern = r'acs:(\w+):(.*)'
        for resource_urn in self.get_lending_resources():
            if resource_urn.startswith('acs:'):
                (type, resource_id) = re.match(resource_pattern, resource_urn).groups()
                loans.append({
                    'resource_id': resource_id,
                    'resource_type': type,
                    'size': None
                })
            elif resource_urn.startswith('bookreader'):
                loans.append({
                    'resource_id': resource_urn,
                    'resource_type': 'bookreader',
                    'size': None
                })

        # Put default type at start of list, then sort by type name
        def loan_key(loan):
            if loan['resource_type'] == default_type:
                return '1-%s' % loan['resource_type']
            else:
                return '2-%s' % loan['resource_type']
        loans = sorted(loans, key=loan_key)

        # For each possible loan, check if it is available We
        # shouldn't be out of sync (we already checked
        # get_edition_loans for current loans) but we fail safe, for
        # example the book may have been borrowed in a dev instance
        # against the live ACS4 server
        for loan in loans:
            if borrow.is_loaned_out(loan['resource_id']):
                # Only a single loan of an item is allowed
                # $$$ log out of sync state
                return []

        return loans
Exemplo n.º 3
0
 def get_available_loans(self):
     """Returns [{'resource_id': uuid, 'resource_type': type, 'size': bytes}]
     
     size may be None"""
     
     default_type = 'bookreader'
     
     loans = []
     
     resource_pattern = r'acs:(\w+):(.*)'
     for resource_urn in self.get_lending_resources():
         print 'RESOURCE %s' % resource_urn
         if resource_urn.startswith('acs:'):
             (type, resource_id) = re.match(resource_pattern, resource_urn).groups()
             loans.append( { 'resource_id': resource_id, 'resource_type': type, 'size': None } )
         elif resource_urn.startswith('bookreader'):
             loans.append( { 'resource_id': resource_urn, 'resource_type': 'bookreader', 'size': None } )
         
     
     # Put default type at start of list, then sort by type name
     def loan_key(loan):
         if loan['resource_type'] == default_type:
             return '1-%s' % loan['resource_type']
         else:
             return '2-%s' % loan['resource_type']        
     loans = sorted(loans, key=loan_key)
     
     # Check if we have a possible loan - may not yet be fulfilled in ACS4
     if borrow.get_edition_loans(self):
         # There is a current loan or offer
         return []
         
     # Check if available - book status server
     # We shouldn't be out of sync but we fail safe
     for loan in loans:
         if borrow.is_loaned_out(loan['resource_id']):
             # Only a single loan of an item is allowed
             # XXX log out of sync state
             return []
     
     # XXX get file size
         
     return loans
Exemplo n.º 4
0
    def _get_available_loans(self, current_loans):

        default_type = "bookreader"

        loans = []

        # Check if we have a possible loan - may not yet be fulfilled in ACS4
        if current_loans:
            # There is a current loan or offer
            return []

        # Create list of possible loan formats
        resource_pattern = r"acs:(\w+):(.*)"
        for resource_urn in self.get_lending_resources():
            if resource_urn.startswith("acs:"):
                (type, resource_id) = re.match(resource_pattern, resource_urn).groups()
                loans.append({"resource_id": resource_id, "resource_type": type, "size": None})
            elif resource_urn.startswith("bookreader"):
                loans.append({"resource_id": resource_urn, "resource_type": "bookreader", "size": None})

        # Put default type at start of list, then sort by type name
        def loan_key(loan):
            if loan["resource_type"] == default_type:
                return "1-%s" % loan["resource_type"]
            else:
                return "2-%s" % loan["resource_type"]

        loans = sorted(loans, key=loan_key)

        # For each possible loan, check if it is available
        # We shouldn't be out of sync (we already checked get_edition_loans for current loans) but we fail safe, for example
        # the book may have been borrowed in a dev instance against the live ACS4 server
        for loan in loans:
            if borrow.is_loaned_out(loan["resource_id"]):
                # Only a single loan of an item is allowed
                # $$$ log out of sync state
                return []

        return loans