Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Minor level code smells from backend (CS8) #662

Merged
merged 6 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion api/app/admin/csr.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ def check_uservalues(updated_csr):
if update_data:
db.session.add(updated_csr)
db.session.commit()
return


def request_redirect(self, return_url, model, request_parameter):
Expand Down
2 changes: 1 addition & 1 deletion api/app/models/theq/office.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def build_cache(cls):
office.timeslots
office.timezone
cache.set(key, office)
except Exception as e:
except Exception:
print('Error on building cache')

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ class AppointmentDraftDelete(Resource):

def delete(self, id):

appointment = Appointment.query.filter_by(appointment_id=id)\
.first_or_404()

Appointment.delete_draft([id])
if not application.config['DISABLE_AUTO_REFRESH']:
socketio.emit('appointment_delete', id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class BookingRecurringDelete(Resource):
def delete(self, id):

today = datetime.today()
string_today = today.strftime('%Y-%m-%d')

print("==> In the python DELETE /bookings/recurring/<id> endpoint")

Expand Down Expand Up @@ -66,7 +65,6 @@ class BookingRecurringDelete(Resource):
def delete(self, id):

today = datetime.today()
string_today = today.strftime('%Y-%m-%d')

print("==> In the python DELETE /bookings/recurring/<id> endpoint")

Expand Down
1 change: 0 additions & 1 deletion api/app/resources/bookings/exam/exam_bulk_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ExamList(Resource):

@jwt.requires_auth
def post(self):
csr = CSR.find_by_username(g.jwt_oidc_token_info['username'])

try:
exams = Exam.query.filter_by(upload_received_ind=0).filter(Exam.bcmp_job_id.isnot(None))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class InvigilatorListOffsiteGet(Resource):
@jwt.requires_auth
def get(self):

csr = CSR.find_by_username(g.jwt_oidc_token_info['username'])

pesticide_office = Office.query.filter_by(office_name="Pesticide Offsite").first()

try:
Expand Down
18 changes: 8 additions & 10 deletions api/app/resources/bookings/walkin/walkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ def get_all_app_from_agenda_panel(self, citizen=False, office=False):
if office:
office_id = office.office_id
if office_id:
time_now = datetime.utcnow()
past_hour = datetime.utcnow() - timedelta(minutes=15)
future_hour = datetime.utcnow() + timedelta(minutes=15)
local_past = pytz.utc.localize(past_hour)
Expand Down Expand Up @@ -237,12 +236,12 @@ def post(self):
if nth_app['citizen_id']:
citizen = Citizen.query.filter_by(citizen_id=nth_app['citizen_id']).first()
if (not (citizen.automatic_reminder_flag) or (citizen.automatic_reminder_flag == 0)):
officeObj = Office.find_by_id(citizen.office_id)
office_obj = Office.find_by_id(citizen.office_id)
if citizen.notification_phone:
citizen = self.send_sms_reminder(citizen, officeObj)
citizen = self.send_sms_reminder(citizen, office_obj)
citizen.automatic_reminder_flag = 1
if citizen.notification_email:
citizen = self.send_email_reminder(citizen, officeObj)
citizen = self.send_email_reminder(citizen, office_obj)
citizen.automatic_reminder_flag = 1
db.session.add(citizen)
db.session.commit()
Expand Down Expand Up @@ -294,8 +293,7 @@ def process_all_citizen_in_q(self, result):
break
return booked_check_app, walkin_app

def send_sms_reminder(self, citizen, officeObj):
data_values = {}
def send_sms_reminder(self, citizen, office_obj):
if (citizen.notification_phone):
sms_sent = False
validate_check = True
Expand All @@ -304,7 +302,7 @@ def send_sms_reminder(self, citizen, officeObj):
if (citizen.reminder_flag == 2):
validate_check = False
if validate_check:
sms_sent = send_walkin_reminder_sms(citizen, officeObj, request.headers['Authorization'].replace('Bearer ', ''))
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:
Expand All @@ -314,7 +312,7 @@ def send_sms_reminder(self, citizen, officeObj):
return citizen


def send_email_reminder(self, citizen, officeObj):
def send_email_reminder(self, citizen, office_obj):
if (citizen.notification_email):
# code/function call to send first email notification,
email_sent = False
Expand All @@ -323,9 +321,9 @@ def send_email_reminder(self, citizen, officeObj):
if (citizen.reminder_flag == 2):
validate_check = False
if validate_check:
email_sent = get_walkin_reminder_email_contents(citizen, officeObj)
email_sent = get_walkin_reminder_email_contents(citizen, office_obj)
if email_sent:
status = send_email(request.headers['Authorization'].replace('Bearer ', ''), *email_sent)
send_email(request.headers['Authorization'].replace('Bearer ', ''), *email_sent)
flag_value = 1
if citizen.reminder_flag == 1:
flag_value = 2
Expand Down
6 changes: 3 additions & 3 deletions api/app/resources/theq/citizen/citizen_add_to_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ def post(self, id):
# email
email_sent = False
if citizen.notification_email:
officeObj = Office.find_by_id(citizen.office_id)
office_obj = Office.find_by_id(citizen.office_id)
print('Sending email for walk in spot confirmations to')
email_sent = get_walkin_spot_confirmation_email_contents(citizen, url, officeObj)
email_sent = get_walkin_spot_confirmation_email_contents(citizen, url, office_obj)
# SMS
sms_sent = False
if citizen.notification_phone:
sms_sent = send_walkin_spot_confirmation_sms(citizen, url, request.headers['Authorization'].replace('Bearer ', ''))
if email_sent:
status = send_email(request.headers['Authorization'].replace('Bearer ', ''), *email_sent)
send_email(request.headers['Authorization'].replace('Bearer ', ''), *email_sent)
update_table = True
if sms_sent:
update_table = True
Expand Down
9 changes: 4 additions & 5 deletions api/app/resources/theq/citizen/citizen_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ def put(self, id):
return {'message': err.messages}, 422
else:
try:
data_values = {}
officeObj = Office.find_by_id(citizen.office_id)
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, officeObj, request.headers['Authorization'].replace('Bearer ', ''))
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
Expand All @@ -85,9 +84,9 @@ def put(self, id):
if (citizen.notification_email):
# code/function call to send first email notification,
email_sent = False
email_sent = get_walkin_reminder_email_contents(citizen, officeObj)
email_sent = get_walkin_reminder_email_contents(citizen, office_obj)
if email_sent:
status = send_email(request.headers['Authorization'].replace('Bearer ', ''), *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
Expand Down
1 change: 0 additions & 1 deletion api/app/resources/theq/citizen/citizen_generic_invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class CitizenGenericInvite(Resource):
@jwt.has_one_of_roles([Role.internal_user.value])
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))
Expand Down
2 changes: 1 addition & 1 deletion api/app/resources/theq/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def post(self):

try:
feedback_message = json_data['feedback_message']
except KeyError as err:
except KeyError:
return {"message": "Must provide message to send as feedback"}, 422

teams_result = None
Expand Down
2 changes: 1 addition & 1 deletion api/app/resources/theq/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def post(self):

try:
slack_message = json_data['slack_message']
except KeyError as err:
except KeyError:
return {"message": "Must provide message to send to slack"}, 422

print(slack_message)
Expand Down
3 changes: 0 additions & 3 deletions api/app/utilities/bcmp_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ def create_individual_exam(self, exam, exam_fees, invigilator, pesticide_office,
def create_group_exam_bcmp(self, exam, booking, candiate_list, invigilator, pesticide_office, oidc_token_info):
url = "%s/auth=%s;%s/JSON/create:BCMD-EXAM-GROUP" % (self.base_url, self.bcmp_user, self.auth_token)
my_print(" ==> create_group_exam_bcmp url: %s" % url)
invigilator_name = None
if invigilator:
invigilator_name = invigilator.invigilator_name

office_name = None
time_zone = pytz.timezone('America/Vancouver')
Expand Down
1 change: 1 addition & 0 deletions api/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ def run(self):
day_of_week="{Tuesday,Wednesday,Thursday}",
office_id=office_100.office_id
)
# Shouldn't these be added to the DB? Nov18/21 - CRG

#-- CSR values ------------------------------------------------------
print("--> CSRs")
Expand Down