Skip to content
Snippets Groups Projects
Commit 45fc241e authored by Carlos Vega's avatar Carlos Vega
Browse files

C0209 Formatting a regular string which could be an f-string. Fixed for those files

parent 0c103f04
No related branches found
No related tags found
1 merge request!445Support for Python 3.11
Showing
with 52 additions and 56 deletions
......@@ -187,7 +187,7 @@ def serialize_appointment(appointment: Appointment):
nd_number = screening_number = phone_numbers = appointment_type_names = None
status = appointment.status
if appointment.visit is not None:
title = "Visit {}".format(display_visit_number(appointment.visit.visit_number))
title = f"Visit {display_visit_number(appointment.visit.visit_number)}"
study_subject = appointment.visit.subject
subject_string = study_subject.subject.last_name + " " + study_subject.subject.first_name
first_name = study_subject.subject.first_name
......
......@@ -15,32 +15,32 @@ from web.views.notifications import get_filter_locations
logger = logging.getLogger(__name__)
RANDOM_COLORS = [
'#%02X%02X%02X' % (8, 218, 217),
'#%02X%02X%02X' % (8, 8, 101),
'#%02X%02X%02X' % (8, 218, 3),
'#%02X%02X%02X' % (247, 137, 156),
'#%02X%02X%02X' % (183, 96, 2),
'#%02X%02X%02X' % (20, 106, 55),
'#%02X%02X%02X' % (8, 119, 217),
'#%02X%02X%02X' % (16, 76, 27),
'#%02X%02X%02X' % (85, 7, 162),
'#%02X%02X%02X' % (157, 7, 2),
'#%02X%02X%02X' % (49, 65, 68),
'#%02X%02X%02X' % (112, 124, 98),
'#%02X%02X%02X' % (8, 8, 215),
'#%02X%02X%02X' % (85, 7, 98),
'#%02X%02X%02X' % (16, 76, 100),
'#%02X%02X%02X' % (85, 7, 50),
'#%02X%02X%02X' % (183, 5, 2),
'#%02X%02X%02X' % (183, 156, 2),
'#%02X%02X%02X' % (112, 82, 38),
f'#{8:02X}{218:02X}{217:02X}',
f'#{8:02X}{8:02X}{101:02X}',
f'#{8:02X}{218:02X}{3:02X}',
f'#{247:02X}{137:02X}{156:02X}',
f'#{183:02X}{96:02X}{2:02X}',
f'#{20:02X}{106:02X}{55:02X}',
f'#{8:02X}{119:02X}{217:02X}',
f'#{16:02X}{76:02X}{27:02X}',
f'#{85:02X}{7:02X}{162:02X}',
f'#{157:02X}{7:02X}{2:02X}',
f'#{49:02X}{65:02X}{68:02X}',
f'#{112:02X}{124:02X}{98:02X}',
f'#{8:02X}{8:02X}{215:02X}',
f'#{85:02X}{7:02X}{98:02X}',
f'#{16:02X}{76:02X}{100:02X}',
f'#{85:02X}{7:02X}{50:02X}',
f'#{183:02X}{5:02X}{2:02X}',
f'#{183:02X}{156:02X}{2:02X}',
f'#{112:02X}{82:02X}{38:02X}',
]
def build_duration(duration):
number_of_hours = duration // 60
minutes = duration - number_of_hours * 60
return "{0:02d}:{1:02d}".format(number_of_hours, minutes)
return f"{number_of_hours:02d}:{minutes:02d}"
def get_holidays(worker, date):
......@@ -254,7 +254,7 @@ def get_generic_appointment_events(request: HttpRequest, date: str, include_all:
'short_title': appointment.title(),
'status': appointment.status,
'duration': build_duration(appointment.length),
'id': 'app-{}'.format(appointment.id),
'id': f'app-{appointment.id}',
'appointment_id': appointment.id,
'link_when': link_when,
'link_who': appointment.worker_assigned_id,
......@@ -330,7 +330,7 @@ def events(request: HttpRequest, date: str, include_all=False):
'short_title': link.appointment_type.code,
'duration': build_duration(link.appointment_type.default_duration),
'subject': str(appointment_subject),
'id': '{}-{}'.format(i, j),
'id': f'{i}-{j}',
'link_id': link.id,
'link_when': link_when,
'link_who': link.worker_id,
......
......@@ -157,8 +157,8 @@ def get_subject_columns(request: HttpRequest, subject_list_type: str) -> JsonRes
add_column(result, "Edit", "edit", study_subject_list, None, sortable=False)
for one_based_idx, visit_number in enumerate(visit_numbers, 1):
visit_key = "visit_{}".format(one_based_idx) # always starts in 1
add_column(result, "Visit {}".format(visit_number), visit_key, None,
visit_key = f"visit_{one_based_idx}" # always starts in 1
add_column(result, f"Visit {visit_number}", visit_key, None,
"visit_filter", visible_param=study_subject_list.visits)
return JsonResponse({"columns": result})
......@@ -531,7 +531,7 @@ def serialize_subject(study_subject: StudySubject):
else:
status = "UPCOMING"
appointment_types = ['{} ({})'.format(at.code, at.description) for at in visit.appointment_types.all()]
appointment_types = [f'{at.code} ({at.description})' for at in visit.appointment_types.all()]
if len(appointment_types) == 0:
appointment_types = ['No appointment types set.']
......
......@@ -50,7 +50,7 @@ def workers_for_daily_planning(request):
'id': worker.id,
'flags': [language.image.url for language in worker.languages.all() if language.image],
'availability': worker.availability_percentage(start_date=start_date),
'title': "{} ({})".format(str(worker), role[:1].upper()),
'title': f"{str(worker)} ({role[:1].upper()})",
'role': role
}
workers_list_for_json.append(worker_dict_for_json)
......
......@@ -15,7 +15,7 @@ def timeit(method):
name = kw.get('log_name', method.__name__.upper())
kw['log_time'][name] = int((end_time - start_time) * 1000)
else:
print('%r %2.2f ms' % (method.__name__, (end_time - start_time) * 1000))
print(f'{method.__name__!r} {(end_time - start_time) * 1000:2.2f} ms')
return result
return timed
......@@ -64,7 +64,7 @@ class AppointmentForm(ModelForm):
old_human_values = ''
previous_value = ''
# description
description = '{} changed from "{}" to "{}"'.format(field, old_human_values, new_human_values)
description = f'{field} changed from "{old_human_values}" to "{new_human_values}"'
else:
if self.instance.id: # update instance
previous_value = getattr(self.instance, field)
......@@ -72,7 +72,7 @@ class AppointmentForm(ModelForm):
previous_value = ''
if isinstance(new_value, QuerySet):
new_value = ','.join([str(element.id) for element in new_value]) # overwrite variable
description = '{} changed from "{}" to "{}"'.format(field, previous_value, new_value)
description = f'{field} changed from "{previous_value}" to "{new_value}"'
p = Provenance(modified_table=Appointment._meta.db_table,
modified_table_id=self.instance.id,
......
......@@ -76,10 +76,10 @@ def create_field_for_custom_study_subject_field(study_subject_field: CustomStudy
url = ''
def __str__(self):
return "%s" % self.url
return f"{self.url}"
def __unicode__(self):
return "%s" % self.url
return f"{self.url}"
initial = CustomFileField()
initial.url = val
......
......@@ -54,7 +54,7 @@ class EtlCommon:
def create_provenance(self, field_name: str, new_value: object, object_to_change: models.Model,
object_type: Type[models.Model], old_value: object) -> Provenance:
description = '{} changed from "{}" to "{}"'.format(field_name, old_value, new_value)
description = f'{field_name} changed from "{old_value}" to "{new_value}"'
p = Provenance(modified_table=object_type._meta.db_table,
modified_table_id=object_to_change.id,
modification_author=self.etl_data.import_worker,
......
......@@ -58,8 +58,7 @@ class SubjectImporterCronJob(CronJobBase):
importer.execute()
email_body = importer.get_summary()
EmailSender.send_email(email_title,
"<h3>Data was successfully imported from file: {}</h3>{}".format(filename,
email_body),
f"<h3>Data was successfully imported from file: {filename}</h3>{email_body}",
email_recipients)
backup_file(filename)
return "import is successful"
......@@ -67,10 +66,10 @@ class SubjectImporterCronJob(CronJobBase):
except BaseException:
tb = traceback.format_exc()
EmailSender.send_email(email_title,
"<h3><font color='red'>There was a problem with importing data from file: "
"{}</font></h3><pre>{}</pre>".format(filename, tb),
f"<h3><font color='red'>There was a problem with importing data from file: "
"{filename}</font></h3><pre>{tb}</pre>",
email_recipients)
logger.exception('There was a problem with importing data from file: %s', filename)
logger.exception(f'There was a problem with importing data from file: {filename}')
return "import crashed"
......@@ -113,8 +112,7 @@ class VisitImporterCronJob(CronJobBase):
importer.load_data()
email_body = importer.get_summary()
EmailSender.send_email(email_title,
"<h3>Data was successfully imported from file: {}</h3>{}".format(filename,
email_body),
f"<h3>Data was successfully imported from file: {filename}</h3>{email_body}",
email_recipients)
backup_file(filename)
return "import is successful"
......@@ -123,9 +121,9 @@ class VisitImporterCronJob(CronJobBase):
tb = traceback.format_exc()
EmailSender.send_email(email_title,
"<h3><font color='red'>There was a problem with importing data from file: "
"{}</font></h3><pre>{}</pre>".format(filename, tb),
f"{filename}</font></h3><pre>{tb}</pre>",
email_recipients)
logger.exception("There was a problem with importing data from file: %s", filename)
logger.exception(f"There was a problem with importing data from file: {filename}")
return "import crashed"
......
......@@ -22,7 +22,7 @@ class Command(BaseCommand):
def handle(self, *args, **options):
for location in Location.objects.exclude(name="Flying Team").all():
for year in options['year']:
self.stdout.write("importing holidays for year {} and location {}".format(year, location))
self.stdout.write(f"importing holidays for year {year} and location {location}")
# new years day
self.create_holiday(year, 1, 1, "New Years Day", location)
# easter monday
......@@ -53,7 +53,7 @@ class Command(BaseCommand):
location=location, comment=comment).count()
if count != 0:
self.stdout.write(
'an holiday with the same description already exists for the same day: {}'.format(comment))
f'an holiday with the same description already exists for the same day: {comment}')
return
holiday = Appointment()
holiday.datetime_when = datetime.datetime(year=year, month=month, day=day, hour=9)
......
......@@ -8,7 +8,6 @@ import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
......
......@@ -25,7 +25,7 @@ class Availability(models.Model):
def __str__(self):
day_of_week = self.get_day_of_week_as_string()
return "%s %s %s" % (day_of_week, self.person.last_name, self.person.first_name)
return f"{day_of_week} {self.person.last_name} {self.person.first_name}"
def get_day_of_week_as_string(self):
day_of_week = "N/A"
......
......@@ -44,7 +44,7 @@ class ConfigurationItem(models.Model):
)
def __str__(self):
return "%s %s" % (self.name, self.value)
return f"{self.name} {self.value}"
@staticmethod
def is_valid(item: 'ConfigurationItem') -> bool:
......@@ -67,7 +67,7 @@ class ConfigurationItem(models.Model):
if item.type == KIT_RECIPIENT_EMAIL_CONFIGURATION_TYPE:
for email in item.value.split(";"):
if email != '' and not is_valid_email(email):
return "Email {} address is invalid".format(email)
return f"Email {email} address is invalid"
if item.type == DEFAULT_FROM_EMAIL:
if not is_valid_email(item.value):
......
......@@ -22,4 +22,4 @@ class ContactAttempt(models.Model):
comment = models.TextField(max_length=1024, null=True, blank=True)
def __str__(self):
return "%s %s" % (self.subject, self.worker)
return f"{self.subject} {self.worker}"
......@@ -9,4 +9,4 @@ class FlyingTeam(models.Model):
place = models.CharField(max_length=255, verbose_name='Place')
def __str__(self):
return "%s" % self.place
return f"{self.place}"
......@@ -29,4 +29,4 @@ class Holiday(models.Model):
help_text='Defines the kind of availability. Either Holiday or Extra Availability.')
def __str__(self):
return "%s %s" % (self.person.first_name, self.person.last_name)
return f"{self.person.first_name} {self.person.last_name}"
......@@ -40,7 +40,7 @@ class Language(models.Model):
def image_img(self):
if self.image:
return '<img class="flag-icon" src="%s" />' % self.image.url
return f'<img class="flag-icon" src="{self.image.url}" />'
else:
return 'No image'
......
......@@ -20,4 +20,4 @@ class Location(models.Model):
)
def __str__(self):
return "%s" % self.name
return f"{self.name}"
......@@ -334,8 +334,7 @@ class MailTemplate(models.Model):
voucher_type += ' (' + voucher.activity_type + ")"
return {
"##C_NUMBER##": voucher.number,
"##C_PATIENT_NAME##": '{} {}'.format(voucher.study_subject.subject.first_name,
voucher.study_subject.subject.last_name),
"##C_PATIENT_NAME##": f'{voucher.study_subject.subject.first_name} {voucher.study_subject.subject.last_name}',
"##C_VOUCHER_TYPE##": voucher_type,
"##C_ISSUE_DATE_SHORT##": voucher.issue_date.strftime(DATE_FORMAT_SHORT),
"##C_EXPIRY_START_SHORT##": voucher.expiry_date.strftime(DATE_FORMAT_SHORT),
......
......@@ -31,4 +31,4 @@ class Room(models.Model):
)
def __str__(self):
return "%d %s %s" % (self.room_number, self.address, self.city)
return f"{self.room_number} {self.address} {self.city}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment