Example #1
0
    def outstanding_request(self, doc, user):
        """Places outstanding request for certain document for list of users.
        Returns (code, history entry (if there was free copy after queue abandon) or request entry)"""
        if (user.group == group_manager.Group.get(
                group_manager.Group.name == 'Deleted')):
            return 4  # User is deleted
        if doc.active == False:
            return 3  # Document is inactive
        if 'reference' in doc.keywords:
            return 2  # Document is reference

        for entry in user.operations:
            if (entry.date_return == None and entry.copy.get_doc() == doc):
                return 6  # User already has copy of this document

        # If any request for this document exists, cancel it
        entry = Request.get_user(doc)
        if (entry != None):
            entry.active = False
            entry.save()
            if (Request.get_user(doc) != None):
                #print('Houston, we have a problems. Outstanding request, booking system')
                logging.error(
                    'booking_system.Booking_system.outstanding_request(), 2 users in outstanding request'
                )
        # Check if there is available copy
        copies = doc.get_document_copies()
        for copy in copies:
            if (copy.active == True and copy.checked_out == 0):
                return (2, None)  # There is free copy
        Queue.red_button(doc)
        copies = doc.get_document_copies()  # update copies
        # if we have free copies after deleting queue, check out to users who are in request
        for copy in copies:
            if (copy.active == True and copy.checked_out == 0):
                res = self.check_out(doc, user)
                # One of copies became free after flushing the queue
                return (1, res)
        # Placing request
        res = Request.place_request(doc, user, self.librarian)
        return (0, res)  # Request is placed
Example #2
0
 def _check_out_reserved(self, doc, user):
     """Checks out reserved copy of document (Supposed to be called only from check_out method)
     """
     # Get Queue entry and check out assigned copy
     entry = Queue.get_to_remove(doc, user)
     if (entry == None):
         return (1, None)
     copy = entry.assigned_copy
     copy.checked_out = 2
     copy.save()
     current_date = datetime.date.today()
     res = History.create(user=user,
                          copy=copy,
                          librarian_co=self.librarian,
                          date_check_out=current_date)
     entry.delete_instance()  # Delete entry after check out
     return (0, res)  # successfully checked out
 def proceed_free_copy(self, copy, librarian):
     """Proceed free copy. Assign to people in the queue or check out if it is requested
     """
     if (copy.get_doc().requested == True):
         doc = copy.get_doc()
         user = Request.get_user(doc)
         self.check_out(doc, user, librarian)
         Request.close_request(user, doc, librarian)
         return 5  # Checked out to user in outstanding request
     queue_next = Queue.get_user_from_queue(copy)
     if queue_next == None:
         return 0  # Successfully returned
     # Inform user about free copy here <-
     text = "Dear %s,\nQueued document \"%s\" for you is ready.\n" \
            % (queue_next.name + " " + queue_next.surname, copy.get_doc().title)
     managers.notifier.send_message(queue_next.email, "Document is ready",
                                    text)
     return 4  # Assigned to someone in the queue
Example #4
0
    def check_out(self, doc, user):
        """Check outs copy by document and user entries. If there is no available copy, user is placed in queue
        """
        if (user.group == group_manager.Group.get(
                group_manager.Group.name == 'Deleted')):
            return (4, None)  # User is deleted
        if doc.active == False:
            return (3, None)  # Inactive document
        if 'reference' in doc.keywords:
            return (2, None)  # Document is reference

        for entry in self.get_user_history(user):
            if (entry.date_return == None and entry.copy.get_doc() == doc):
                return (6, None)  # User has a copy of this document

        # Check if copy reserved. If it is not reserved, method check_out_reserved returns error
        # and checks out document otherwise
        reserved = self._check_out_reserved(doc, user)
        if (reserved[0] == 0):
            return reserved

        # find copy that is not checked out
        copy_query = doc_manager.Copy.select().where(
            doc_manager.Copy.active == True, doc_manager.Copy.checked_out == 0,
            doc_manager.Copy.docClass == doc_manager.class_to_name()[type(
                doc)], doc_manager.Copy.docId == doc.DocumentID)
        if (len(copy_query) != 0):
            copy = copy_query.get()
            copy.checked_out = 2
            copy.save()
            current_date = datetime.date.today()
            res = History.create(user=user,
                                 copy=copy,
                                 librarian_co=self.librarian,
                                 date_check_out=current_date)
            return (0, res)  # successfully checked out

        # Push to the queue if there is no free copy
        res = Queue.push_to_queue(doc, user)
        if (res == None):
            return (7, None)  # Already is in the queue
        return (1, None)  # Placed in the queue
Example #5
0
    def get_result(self):
        self.list, self.number = Queue.get_list(self.doc, 15, self.page_num, self.active)

        for i in range(0, len(self.list)):
            self.result_table.item(i, 0).setText(str(self.list[i].user_id))
            self.result_table.item(i, 1).setText(str(self.list[i].priority))
            if self.list[i].assigned_copy is None:
                self.result_table.item(i, 2).setText("")
                self.result_table.item(i, 3).setText("")
            else:
                self.result_table.item(i, 2).setText(str(self.list[i].assigned_copy.CopyID))
                self.result_table.item(i, 3).setText(str(self.list[i].time_out))

            for j in range(self.result_table.columnCount()):
                if self.list[i].active:
                    self.result_table.item(i, j).setBackground(self.__active_color)
                else:
                    self.result_table.item(i, j).setBackground(self.__inactive_color)

        for i in range(len(self.list), 15):
            for j in range(self.result_table.columnCount()):
                self.result_table.item(i, j).setText("")
                self.result_table.item(i, j).setBackground(self.__active_color)
        self.page_num_label.setText(str(self.page_num) + "/" + str(self.number))