Beispiel #1
0
 def delete_from_db(self):
     # TODO: Add listener onto the SQLALchemy event to block deletes
     raise BusinessException({
         "code": "cannot_delete_nr",
         "description":
             "NRs cannot be deleted, maybe try cancelling instead"
     }, 403)
Beispiel #2
0
    def get_queued_oldest(cls, userObj):
        """
        Gets the Next NR# from the database
        It sets the STATUS == INPROGRESS
        and then returns the NR or
        error out with a SQLAlchemy Error type
        """
        existing_nr = Request.get_inprogress(userObj)

        if existing_nr:
            current_app.logger.info('Existing NR found, returning: {}'.format(
                existing_nr.nrNum))
            return existing_nr, False

        # this will error if there's nothing in the queue - likelihood ~ 0
        r = db.session.query(Request). \
            filter(
                Request.stateCd.in_([State.DRAFT]),
                Request.nrNum.notlike('NR L%')). \
            order_by(Request.priorityCd.desc(), Request.submittedDate.asc()). \
            with_for_update().first()
        # this row is now locked

        if not r:
            raise BusinessException(None, 404)

        # mark this as assigned to the user, masking it from others.
        r.stateCd = State.INPROGRESS
        r.userId = userObj.id

        db.session.add(r)
        db.session.commit()
        return r, True
Beispiel #3
0
 def delete_from_db(self):
     raise BusinessException()