Skip to content

Commit

Permalink
Merge pull request #1731 from He3lixxx/dependencies
Browse files Browse the repository at this point in the history
Update python dependencies (except django)
  • Loading branch information
he3lixxx authored Mar 28, 2022
2 parents 82e04df + 6c0b161 commit 1da41f7
Show file tree
Hide file tree
Showing 36 changed files with 142 additions and 160 deletions.
12 changes: 4 additions & 8 deletions evap/contributor/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def test_direct_delegation_request(self):

self.assertContains(
page,
"{} was added as a contributor for evaluation "{}" and was sent an email with further information.".format(
str(self.non_editor), str(self.evaluation)
),
f"{self.non_editor} was added as a contributor for evaluation "{self.evaluation}" and was sent an email with further information.",
)

contribution = Contribution.objects.get(contributor=self.non_editor)
Expand All @@ -63,9 +61,7 @@ def test_direct_delegation_request_with_existing_contribution(self):

self.assertContains(
page,
"{} was added as a contributor for evaluation "{}" and was sent an email with further information.".format(
str(self.non_editor), str(self.evaluation)
),
f"{self.non_editor} was added as a contributor for evaluation "{self.evaluation}" and was sent an email with further information.",
)

self.assertEqual(Contribution.objects.count(), old_contribution_count)
Expand Down Expand Up @@ -133,7 +129,7 @@ def test_wrong_state(self):


class TestContributorEvaluationEditView(WebTest):
url = "/contributor/evaluation/%s/edit" % TESTING_EVALUATION_ID
url = f"/contributor/evaluation/{TESTING_EVALUATION_ID}/edit"

@classmethod
def setUpTestData(cls):
Expand All @@ -147,7 +143,7 @@ def test_not_authenticated(self):
Asserts that an unauthorized user gets redirected to the login page.
"""
response = self.app.get(self.url)
self.assertRedirects(response, "/?next=/contributor/evaluation/%s/edit" % TESTING_EVALUATION_ID)
self.assertRedirects(response, f"/?next=/contributor/evaluation/{TESTING_EVALUATION_ID}/edit")

def test_wrong_usergroup(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion evap/contributor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def evaluation_direct_delegation(request, evaluation_id):


def export_contributor_results(contributor):
filename = "Evaluation_{}.xls".format(contributor.full_name)
filename = f"Evaluation_{contributor.full_name}.xls"
response = FileResponse(filename, content_type="application/vnd.ms-excel")
ResultsExporter().export(
response,
Expand Down
2 changes: 1 addition & 1 deletion evap/development/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def development_components(request):

def development_rendered(request, filename):
fixtures_directory = os.path.join(settings.STATICFILES_DIRS[0], "ts", "rendered")
with open(os.path.join(fixtures_directory, filename)) as fixture:
with open(os.path.join(fixtures_directory, filename), encoding="utf-8") as fixture:
return HttpResponse(fixture)
3 changes: 1 addition & 2 deletions evap/evaluation/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ def create_user(self, claims):
)
return user

@staticmethod
def update_user(user, claims):
def update_user(self, user, claims):
if not user.first_name:
user.first_name = claims.get("given_name", "")
user.save()
Expand Down
2 changes: 1 addition & 1 deletion evap/evaluation/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ def __init__(self, *args, **kwargs):

def save(self, *args, **kw):
super().save(*args, **kw)
logger.info('User "{}" edited the settings.'.format(self.instance.email))
logger.info('User "%s" edited the settings.', self.instance.email)
6 changes: 3 additions & 3 deletions evap/evaluation/management/commands/anonymize.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def anonymize_data(self):
abs_data_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), Command.data_dir)

# load placeholders
with open(os.path.join(abs_data_dir, Command.firstnames_filename)) as firstnames_file:
with open(os.path.join(abs_data_dir, Command.firstnames_filename), encoding="utf-8") as firstnames_file:
first_names = firstnames_file.read().strip().split("\n")
with open(os.path.join(abs_data_dir, Command.lastnames_filename)) as lastnames_file:
with open(os.path.join(abs_data_dir, Command.lastnames_filename), encoding="utf-8") as lastnames_file:
last_names = lastnames_file.read().strip().split("\n")
with open(os.path.join(abs_data_dir, Command.lorem_ipsum_filename)) as lorem_ipsum_file:
with open(os.path.join(abs_data_dir, Command.lorem_ipsum_filename), encoding="utf-8") as lorem_ipsum_file:
lorem_ipsum = lorem_ipsum_file.read().strip().split(" ")

try:
Expand Down
2 changes: 1 addition & 1 deletion evap/evaluation/management/commands/send_reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def send_student_reminders():
EmailTemplate.send_reminder_to_user(
recipient, first_due_in_days=first_due_in_days, due_evaluations=due_evaluations
)
logger.info("sent due evaluation reminders to {} people.".format(len(recipients)))
logger.info("sent due evaluation reminders to %d people.", len(recipients))

@staticmethod
def send_textanswer_reminders():
Expand Down
2 changes: 1 addition & 1 deletion evap/evaluation/management/commands/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def handle(self, *args, **options):
try:
super().handle(args, options)
except Exception:
logger.exception("Management command '{}' failed. Traceback follows: ".format(sys.argv[1]))
logger.exception("Management command '%s' failed. Traceback follows: ", sys.argv[1])
raise

return NewClass
8 changes: 4 additions & 4 deletions evap/evaluation/migrations/0076_add_semester_short_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def populate_semester_short_names(apps, _schema_editor):

for semester in Semester.objects.all():
if semester.name_de.startswith("Sommersemester"):
semester.short_name_de = "SS {}".format(semester.name_de[-2:])
semester.short_name_en = "ST {}".format(semester.name_de[-2:])
semester.short_name_de = f"SS {semester.name_de[-2:]}"
semester.short_name_en = f"ST {semester.name_de[-2:]}"
elif semester.name_de.startswith("Wintersemester"):
semester.short_name_de = "WS {}/{}".format(semester.name_de[-7:-5], semester.name_de[-2:])
semester.short_name_en = "WT {}/{}".format(semester.name_de[-7:-5], semester.name_de[-2:])
semester.short_name_de = f"WS {semester.name_de[-7:-5]}/{semester.name_de[-2:]}"
semester.short_name_en = f"WT {semester.name_de[-7:-5]}/{semester.name_de[-2:]}"
else:
semester.short_name_de = semester.name_de[-20:]
semester.short_name_en = semester.name_en[-20:]
Expand Down
4 changes: 2 additions & 2 deletions evap/evaluation/migrations/0100_clear_evaluation_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def name_evaluations(apps, _schema_editor):
else:
for i in range(0, course.evaluations.count()):
evaluation = Evaluation.objects.get(pk=course.evaluations.all()[i].pk)
evaluation.name_de = "{} ({})".format(course.name_de, i)
evaluation.name_en = "{} ({})".format(course.name_en, i)
evaluation.name_de = f"{course.name_de} ({i})"
evaluation.name_en = f"{course.name_en} ({i})"
evaluation.save()


Expand Down
39 changes: 20 additions & 19 deletions evap/evaluation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,19 +508,19 @@ def state_changed_from(self, state_set):
@property
def full_name(self):
if self.name:
return "{} – {}".format(self.course.name, self.name)
return f"{self.course.name}{self.name}"
return self.course.name

@property
def full_name_de(self):
if self.name_de:
return "{} – {}".format(self.course.name_de, self.name_de)
return f"{self.course.name_de}{self.name_de}"
return self.course.name_de

@property
def full_name_en(self):
if self.name_en:
return "{} – {}".format(self.course.name_en, self.name_en)
return f"{self.course.name_en}{self.name_en}"
return self.course.name_en

@property
Expand Down Expand Up @@ -927,9 +927,7 @@ def update_evaluations(cls):
evaluation.save()
except Exception: # pylint: disable=broad-except
logger.exception(
'An error occured when updating the state of evaluation "{}" (id {}).'.format(
evaluation, evaluation.id
)
'An error occured when updating the state of evaluation "%s" (id %d).', evaluation, evaluation.id
)

template = EmailTemplate.objects.get(name=EmailTemplate.EVALUATION_STARTED)
Expand Down Expand Up @@ -989,9 +987,12 @@ def evaluation_state_change(instance, source, **_kwargs):
@receiver(post_transition, sender=Evaluation)
def log_state_transition(instance, name, source, target, **_kwargs):
logger.info(
'Evaluation "{}" (id {}) moved from state "{}" to state "{}", caused by transition "{}".'.format(
instance, instance.pk, source, target, name
)
'Evaluation "%s" (id %d) moved from state "%s" to state "%s", caused by transition "%s".',
instance,
instance.pk,
source,
target,
name,
)


Expand Down Expand Up @@ -1121,7 +1122,7 @@ def answer_class(self):
if self.is_rating_question:
return RatingAnswerCounter

raise Exception("Unknown answer type: %r" % self.type)
raise Exception(f"Unknown answer type: {self.type!r}")

@property
def is_likert_question(self):
Expand Down Expand Up @@ -1528,7 +1529,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
is_proxy_user = models.BooleanField(default=False, verbose_name=_("Proxy user"))

# key for url based login of this user
MAX_LOGIN_KEY = 2 ** 31 - 1
MAX_LOGIN_KEY = 2**31 - 1

login_key = models.IntegerField(verbose_name=_("Login Key"), unique=True, blank=True, null=True)
login_key_valid_until = models.DateField(verbose_name=_("Login Key Validity"), blank=True, null=True)
Expand Down Expand Up @@ -1829,7 +1830,7 @@ def send_to_users_in_evaluations(self, evaluations, recipient_groups, use_cc, re

for user, user_evaluations in user_evaluation_map.items():
subject_params = {}
evaluations_with_date = dict()
evaluations_with_date = {}
for evaluation in user_evaluations:
evaluations_with_date[evaluation] = (evaluation.vote_end_date - date.today()).days
evaluations_with_date = sorted(evaluations_with_date.items(), key=lambda tup: tup[0].full_name)
Expand All @@ -1842,8 +1843,8 @@ def send_to_users_in_evaluations(self, evaluations, recipient_groups, use_cc, re

def send_to_user(self, user, subject_params, body_params, use_cc, additional_cc_users=(), request=None):
if not user.email:
warning_message = "{} has no email address defined. Could not send email.".format(
user.full_name_with_additional_info
warning_message = (
f"{user.full_name_with_additional_info} has no email address defined. Could not send email."
)
# If this method is triggered by a cronjob changing evaluation states, the request is None.
# In this case warnings should be sent to the admins via email (configured in the settings for logger.error).
Expand Down Expand Up @@ -1879,14 +1880,14 @@ def send_to_user(self, user, subject_params, body_params, use_cc, additional_cc_

try:
mail.send(False)
logger.info(('Sent email "{}" to {}.').format(mail.subject, user.full_name_with_additional_info))
logger.info('Sent email "%s" to %s.', mail.subject, user.full_name_with_additional_info)
if send_separate_login_url:
self.send_login_url_to_user(user)
except Exception: # pylint: disable=broad-except
logger.exception(
'An exception occurred when sending the following email to user "{}":\n{}\n'.format(
user.full_name_with_additional_info, mail.message()
)
'An exception occurred when sending the following email to user "%s":\n%s\n',
user.full_name_with_additional_info,
mail.message(),
)

def construct_mail(self, to_email, cc_addresses, subject_params, body_params):
Expand Down Expand Up @@ -1928,7 +1929,7 @@ def send_login_url_to_user(cls, user):
body_params = {"user": user}

template.send_to_user(user, subject_params, body_params, use_cc=False)
logger.info(("Sent login url to {}.").format(user.email))
logger.info("Sent login url to %s.", user.email)

@classmethod
def send_contributor_publish_notifications(cls, evaluations, template=None):
Expand Down
2 changes: 1 addition & 1 deletion evap/evaluation/models_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def _get_change_data(self, action_type: InstanceActionType):
for field_name, related_objects in model_to_dict(self, m2m_field_names).items():
changes[field_name] = {FieldActionType.INSTANCE_DELETE: [obj.pk for obj in related_objects]}
else:
raise ValueError("Unknown action type: '{}'".format(action_type))
raise ValueError(f"Unknown action type: '{action_type}'")

return changes

Expand Down
6 changes: 3 additions & 3 deletions evap/evaluation/templatetags/evaluation_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def ordering_index(evaluation):
@register.filter
def percentage(fraction, population):
try:
return "{0:.0f}%".format(int(float(fraction) / float(population) * 100))
return f"{int(float(fraction) / float(population) * 100):.0f}%"
except ValueError:
return None
except ZeroDivisionError:
Expand All @@ -107,7 +107,7 @@ def percentage(fraction, population):
@register.filter
def percentage_one_decimal(fraction, population):
try:
return "{0:.1f}%".format((float(fraction) / float(population)) * 100)
return f"{float(fraction) / float(population) * 100:.1f}%"
except ValueError:
return None
except ZeroDivisionError:
Expand Down Expand Up @@ -201,7 +201,7 @@ def message_class(level):
def hours_and_minutes(time_left_for_evaluation):
hours = time_left_for_evaluation.seconds // 3600
minutes = (time_left_for_evaluation.seconds // 60) % 60
return "{:02}:{:02}".format(hours, minutes)
return f"{hours:02}:{minutes:02}"


@register.filter
Expand Down
4 changes: 2 additions & 2 deletions evap/evaluation/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def setUpTestData(cls):
@override_settings(PAGE_URL="https://example.com")
def test_login_url_generation(self):
generated_url = self.external_user.login_url
self.assertEqual(generated_url, "https://example.com/key/{}".format(self.external_user.login_key))
self.assertEqual(generated_url, f"https://example.com/key/{self.external_user.login_key}")

reversed_url = reverse("evaluation:login_key_authentication", args=[self.external_user.login_key])
self.assertEqual(reversed_url, "/key/{}".format(self.external_user.login_key))
self.assertEqual(reversed_url, f"/key/{self.external_user.login_key}")

def test_login_url_works(self):
self.assertRedirects(self.app.get(reverse("contributor:index")), "/?next=/contributor/")
Expand Down
2 changes: 1 addition & 1 deletion evap/evaluation/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def test_responsibles_names(self):
user1 = baker.make(UserProfile, last_name="Doe")
user2 = baker.make(UserProfile, last_name="Meyer")
course = baker.make(Course, responsibles=[user1, user2])
self.assertEqual(course.responsibles_names, ("{}, {}").format(user1.full_name, user2.full_name))
self.assertEqual(course.responsibles_names, f"{user1.full_name}, {user2.full_name}")


class TestUserProfile(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion evap/evaluation/tests/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __eq__(self, other):
return self.lowest <= other <= self.highest

def __repr__(self):
return "[%d..%d]" % (self.lowest, self.highest)
return f"[{self.lowest}..{self.highest}]"


def let_user_vote_for_evaluation(user, evaluation, create_answers=False):
Expand Down
10 changes: 4 additions & 6 deletions evap/evaluation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def faq(request):

@no_login_required
def legal_notice(request):
return render(request, "legal_notice.html", dict())
return render(request, "legal_notice.html")


@require_POST
Expand All @@ -168,18 +168,16 @@ def contact(request):
if message:
mail = EmailMessage(
subject=subject,
body="{}\n{}\n\n{}".format(title, request.user.email, message),
body=f"{title}\n{request.user.email}\n\n{message}",
to=[settings.CONTACT_EMAIL],
reply_to=[request.user.email],
)
try:
mail.send()
logger.info("Sent contact email: \n{}\n".format(mail.message()))
logger.info("Sent contact email: \n%s\n", mail.message())
return HttpResponse()
except Exception:
logger.exception(
"An exception occurred when sending the following contact email:\n{}\n".format(mail.message())
)
logger.exception("An exception occurred when sending the following contact email:\n%s\n", mail.message())
raise

return HttpResponseBadRequest()
Expand Down
2 changes: 1 addition & 1 deletion evap/grades/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def helper_upload_path(instance, filename):
return "grades/{}/{}".format(instance.course.id, filename)
return f"grades/{instance.course.id}/{filename}"


class GradeDocument(models.Model):
Expand Down
6 changes: 2 additions & 4 deletions evap/grades/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def helper_upload_grades(self, course, final_grades):

final = "?final=true" if final_grades else ""
response = self.app.post(
"/grades/semester/{}/course/{}/upload{}".format(course.semester.id, course.id, final),
f"/grades/semester/{course.semester.id}/course/{course.id}/upload{final}",
params={"description_en": "Grades", "description_de": "Grades"},
user=self.grade_publisher,
content_type="multipart/form-data",
Expand All @@ -69,9 +69,7 @@ def helper_check_final_grade_upload(self, course, expected_number_of_emails):
self.assertIn("Successfully", response)
self.assertEqual(course.final_grade_documents.count(), 1)
self.assertEqual(len(mail.outbox), expected_number_of_emails)
self.app.get(
"/grades/download/{}".format(course.final_grade_documents.first().id), user=self.student, status=200
)
self.app.get(f"/grades/download/{course.final_grade_documents.first().id}", user=self.student, status=200)

# tear down
course.final_grade_documents.first().file.delete()
Expand Down
Loading

0 comments on commit 1da41f7

Please sign in to comment.