コード例 #1
0
    def post(self):
        y = 0
        key = "DR->" + get_key()
        y = y + 1
        csr = csr_find_by_user()
        lock = FileLock("lock/invite_citizen_{}.lock".format(csr.office_id))
        with lock:

            active_citizen_state = citizen_state

            waiting_period_state = find_wait()
            citizen = None
            json_data = request.get_json()

            if json_data and 'counter_id' in json_data:
                counter_id = int(json_data.get('counter_id'))
            else:
                counter_id = int(csr.counter_id)

            citizen = find_citizen(counter_id,active_citizen_state, csr, waiting_period_state)

            # If no matching citizen with the same counter type, get next one
            if citizen is None:
                citizen = find_citizen2(active_citizen_state, csr, waiting_period_state)

            if citizen is None:
                return {"message": "There is no citizen to invite"}, 400

            my_print("==> POST /citizens/invite/ Citizen: " + str(citizen.citizen_id) + ', Ticket: ' + citizen.ticket_number)

            db.session.refresh(citizen)

            active_service_request = find_active_sr(citizen)

            try:
                invite_active_sr(active_service_request,csr,citizen)

            except TypeError:
                return {"message": "Error inviting citizen. Please try again."}, 400


            active_service_state = find_active_ss()
            active_service_request.sr_state_id = active_service_state.sr_state_id
            db.session.add(citizen)
            db.session.commit()

            socketio.emit('update_customer_list', {}, room=csr.office.office_name)
            socketio.emit('citizen_invited', {}, room='sb-%s' % csr.office.office_number)
            result = self.citizen_schema.dump(citizen)
            socketio.emit('update_active_citizen', result, room=csr.office.office_name)

        return {'citizen': result,
                'errors': self.citizen_schema.validate(citizen)}, 200
コード例 #2
0
    def post(self):
        #print("==> In Python /citizens/invitetest")
        y = 0
        #for x in range(0, 25):
        key = "DR->" + get_key()
        #print("")
        y = y + 1
        #print("DATETIME:", datetime.now(), "starting loop:", y, "==>Key : ", key)
        csr = csr_find_by_user()
        #print("DATETIME:", datetime.now(), "==>Key : ", key,"===>AFTER CALL TO csr_find_by_user:"******"lock/invite_citizen_{}.lock".format(csr.office_id))
        with lock:

            #active_citizen_state = find_active()
            active_citizen_state = citizen_state
            #print("DATETIME:", datetime.now(), "==>Key : ", key, "===>AFTER CALL TO find_Active:", active_citizen_state)

            waiting_period_state = find_wait()
            #print("DATETIME:", datetime.now(), "==>Key : ", key, "===>AFTER CALL TO find_wait:", waiting_period_state)
            citizen = None
            json_data = request.get_json()

            if json_data and 'counter_id' in json_data:
                counter_id = int(json_data.get('counter_id'))
            else:
                counter_id = int(csr.counter_id)

            citizen = find_citizen(counter_id, active_citizen_state, csr,
                                   waiting_period_state)

            # If no matching citizen with the same counter type, get next one
            if citizen is None:
                citizen = find_citizen2(active_citizen_state, csr,
                                        waiting_period_state)

            if citizen is None:
                return {"message": "There is no citizen to invite"}, 400

            my_print("==> POST /citizens/invite/ Citizen: " +
                     str(citizen.citizen_id) + ', Ticket: ' +
                     citizen.ticket_number)

            db.session.refresh(citizen)

            active_service_request = find_active_sr(citizen)
            #print("DATETIME:", datetime.now(), "==>Key : ", key, "===>AFTER CALL TO find_active_sr:", citizen)

            try:
                invite_active_sr(active_service_request, csr, citizen)
                #print("DATETIME:", datetime.now(), "==>Key : ", key, "===>AFTER CALL TO invite_active_sr:")

            except TypeError:
                return {
                    "message": "Error inviting citizen. Please try again."
                }, 400

            active_service_state = find_active_ss()
            #print("DATETIME:", datetime.now(), "==>Key : ", key, "===>AFTER CALL TO find_active_ss:", active_service_state)
            active_service_request.sr_state_id = active_service_state.sr_state_id
            db.session.add(citizen)
            db.session.commit()

            socketio.emit('update_customer_list', {},
                          room=csr.office.office_name)
            socketio.emit('citizen_invited', {},
                          room='sb-%s' % csr.office.office_number)
            result = self.citizen_schema.dump(citizen)
            socketio.emit('update_active_citizen',
                          result,
                          room=csr.office.office_name)

            #print("DATETIME:", datetime.now(), "end loop:     ", y , "==>Key : ", key)

        return {
            'citizen': result,
            'errors': self.citizen_schema.validate(citizen)
        }, 200
コード例 #3
0
        except ValidationError as err:
            print(err)
            return {"message": err.messages}, 422

        citizen.cs_id = active_id
        citizen.service_count = 1
        db.session.add(citizen)
        db.session.commit()

        SnowPlow.add_citizen(citizen, csr)

        result = self.citizen_schema.dump(citizen)

        return {
            'citizen': result,
            'errors': self.citizen_schema.validate(citizen)
        }, 201


try:
    key = get_key()
    citizen_state = CitizenState.query.filter_by(
        cs_state_name="Active").first()
    active_id = citizen_state.cs_id
except:
    active_id = 1
    print("==> In citizen_list.py")
    print(
        "    --> NOTE!!  You should only see this if doing a 'python3 manage.py db upgrade'"
    )