コード例 #1
0
 def send_sms_reminder(self, citizen, office_obj):
     if (citizen.notification_phone):
         sms_sent = False
         validate_check = True
         # code/function call to send sms notification,
         if citizen.reminder_flag and (citizen.reminder_flag == 2):
             validate_check = False
         if validate_check:
             sms_sent = send_walkin_reminder_sms(
                 citizen, office_obj,
                 request.headers['Authorization'].replace('Bearer ', ''))
             if (sms_sent):
                 flag_value = 1
                 if citizen.reminder_flag == 1:
                     flag_value = 2
                 citizen.reminder_flag = flag_value
                 citizen.notification_sent_time = datetime.utcnow()
     return citizen
コード例 #2
0
    def put(self, id):
        json_data = request.get_json()

        if 'counter_id' not in json_data:
            json_data['counter_id'] = counter_id

        if not json_data:
            return {'message': 'No input data received for updating citizen'}, 400

        csr = CSR.find_by_username(g.jwt_oidc_token_info['username'])
        citizen = Citizen.query.filter_by(citizen_id=id).first()
        my_print("==> PUT /citizens/" + str(citizen.citizen_id) + '/, Ticket: ' + str(citizen.ticket_number))
        if not ((json_data.get('is_first_reminder', False) or json_data.get('is_second_reminder', False))):
            try:
                citizen = self.citizen_schema.load(json_data, instance=citizen, partial=True)
            except ValidationError as err:
                return {'message': err.messages}, 422
        else:
            try:
                office_obj = Office.find_by_id(citizen.office_id)
                if (citizen.notification_phone):
                    sms_sent = False
                    # code/function call to send sms notification,
                    sms_sent = send_walkin_reminder_sms(citizen, office_obj, request.headers['Authorization'].replace('Bearer ', ''))
                    if (json_data.get('is_first_reminder', False)):
                        if (sms_sent):
                            citizen.reminder_flag = 1
                            citizen.notification_sent_time = datetime.utcnow()
                    if (json_data.get('is_second_reminder', False)):
                        if (sms_sent):
                            citizen.reminder_flag = 2
                            citizen.notification_sent_time = datetime.utcnow()
                if (citizen.notification_email):
                    # code/function call to send first email notification,
                    email_sent = False
                    email_sent = get_walkin_reminder_email_contents(citizen, office_obj)
                    if email_sent:
                        send_email(request.headers['Authorization'].replace('Bearer ', ''), *email_sent)
                    if (json_data.get('is_first_reminder', False)):
                        if email_sent:
                            citizen.reminder_flag = 1
                            citizen.notification_sent_time = datetime.utcnow()
                    if (json_data.get('is_second_reminder', False)):
                        if email_sent:
                            citizen.reminder_flag = 2
                            citizen.notification_sent_time = datetime.utcnow()
                    
            except ValidationError as err:
                return {'message': err.messages}, 422

        db.session.add(citizen)
        db.session.commit()

        #  If this put request is the result of an appointment checkin, make a Snowplow call.
        if ('snowplow_addcitizen' in json_data) and (json_data['snowplow_addcitizen'] == True):
            SnowPlow.add_citizen(citizen, csr)

        result = self.citizen_schema.dump(citizen)
        citizen = Citizen.query.filter_by(citizen_id=citizen.citizen_id).first()
        socketio.emit('update_active_citizen', result, room=csr.office.office_name)

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