Skip to content

Commit

Permalink
Modifications cosmétiques des fichiers Python
Browse files Browse the repository at this point in the history
  • Loading branch information
Situphen committed Mar 7, 2022
1 parent d2bddd7 commit c8df573
Show file tree
Hide file tree
Showing 30 changed files with 68 additions and 74 deletions.
2 changes: 1 addition & 1 deletion zds/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
def sub_tag(tag):
start = tag.group("start")
end = tag.group("end")
return "{}".format(start + end)
return f"{start + end}"


class ForumCategory(models.Model):
Expand Down
4 changes: 2 additions & 2 deletions zds/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def test_success_edit_topic_solved_by_author(self):
self.assertEqual(302, response.status_code)
topic = Topic.objects.get(pk=topic.pk)
self.assertTrue(topic.is_solved)
self.assertEquals(topic.solved_by, profile.user)
self.assertEqual(topic.solved_by, profile.user)

def test_success_edit_topic_solved_by_staff(self):
staff = StaffProfileFactory()
Expand All @@ -576,7 +576,7 @@ def test_success_edit_topic_solved_by_staff(self):
self.assertEqual(302, response.status_code)
topic = Topic.objects.get(pk=topic.pk)
self.assertTrue(topic.is_solved)
self.assertEquals(topic.solved_by, staff.user)
self.assertEqual(topic.solved_by, staff.user)

def test_failure_edit_topic_lock_by_user(self):
profile = ProfileFactory()
Expand Down
2 changes: 1 addition & 1 deletion zds/gallery/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def image_path(instance, filename):
:rtype: unicode
"""
ext = filename.split(".")[-1].lower()
filename = "{}.{}".format(str(uuid4()), ext)
filename = f"{str(uuid4())}.{ext}"

return os.path.join("galleries", str(instance.gallery.pk), filename)

Expand Down
4 changes: 2 additions & 2 deletions zds/gallery/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Meta:
model = Image

title = factory.Sequence("titre de l'image {}".format)
slug = factory.LazyAttribute(lambda o: "{}".format(old_slugify(o.title)))
slug = factory.LazyAttribute(lambda o: f"{old_slugify(o.title)}")
legend = factory.Sequence("legende de l'image {}".format)
physical = factory.django.ImageField(color="blue")

Expand All @@ -31,7 +31,7 @@ class Meta:

title = factory.Sequence("titre de la gallerie {}".format)
subtitle = factory.Sequence("Sous-titre de la gallerie {}".format)
slug = factory.LazyAttribute(lambda o: "{}".format(old_slugify(o.title)))
slug = factory.LazyAttribute(lambda o: f"{old_slugify(o.title)}")

@classmethod
def _generate(cls, create, attrs):
Expand Down
2 changes: 1 addition & 1 deletion zds/notification/tests/tests_tricky.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_edit_with_more_than_max_ping(self):
{
"title": "Super sujet",
"subtitle": "Pour tester les notifs",
"text": "@{} @{} are pinged".format(pinged_users[1].user.username, pinged_users[3].user.username),
"text": f"@{pinged_users[1].user.username} @{pinged_users[3].user.username} are pinged",
"tags": "",
},
follow=False,
Expand Down
2 changes: 1 addition & 1 deletion zds/searchv2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SearchForm(forms.Form):
)

choices = sorted(
[(k, v[0]) for k, v in settings.ZDS_APP["search"]["search_groups"].items()], key=lambda pair: pair[1]
((k, v[0]) for k, v in settings.ZDS_APP["search"]["search_groups"].items()), key=lambda pair: pair[1]
)

models = forms.MultipleChoiceField(
Expand Down
2 changes: 1 addition & 1 deletion zds/searchv2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def es_bulk_indexing_of_model(self, model, force_reindexing=False):
if abs(1 - ratio) > 0.1:
objects_per_batch = int(objects_per_batch * ratio)
if force_reindexing:
print(" {}x, new batch size: {}".format(round(ratio, 2), objects_per_batch))
print(f" {round(ratio, 2)}x, new batch size: {objects_per_batch}")
prev_obj_per_sec = obj_per_sec

# fetch next batch
Expand Down
2 changes: 1 addition & 1 deletion zds/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _get_version():
if git_version is None:
return __version__
else:
return "{}/{}".format(__version__, git_version[:7])
return f"{__version__}/{git_version[:7]}"


sentry_sdk.init(
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorialv2/management/commands/migrate_to_zep25.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def update_categories(self):
sub = SubCategory()
sub.title = subcategory[0]
sub.subtitle = subcategory[1]
sub.slug = slugify("{}".format(subcategory[0]))
sub.slug = slugify(f"{subcategory[0]}")
sub.save()
self.stdout.write(f'[ZEP-25] : New subcategory "{sub}" added')
catsubcat = CategorySubCategory()
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorialv2/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __get_list(self, subcategories=None, tags=None, content_type=None, with_comm
if not isinstance(content_type, list):
content_type = [content_type]
content_type = filter(None, content_type)
queryset = queryset.filter(content_type__in=list([c.upper() for c in content_type]))
queryset = queryset.filter(content_type__in=list(c.upper() for c in content_type))

# prefetch:
queryset = (
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorialv2/models/versioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def get_tree_level(self):
elif isinstance(self.children[0], Extract):
return 2
else:
return 1 + max([i.get_tree_level() for i in self.children])
return 1 + max(i.get_tree_level() for i in self.children)

def has_child_with_path(self, child_path):
"""Return ``True`` if this container has a child matching the given
Expand Down
6 changes: 3 additions & 3 deletions zds/tutorialv2/publish_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def publish_container_new(
rendered,
template="tutorialv2/export/chapter.html",
file_ext="html",
**ctx
**ctx,
):
"""
Generate the browser-diplay or epub of a content and its possible hierarchy
Expand Down Expand Up @@ -128,7 +128,7 @@ def publish_container(
template="tutorialv2/export/chapter.html",
file_ext="html",
image_callback=None,
**ctx
**ctx,
):
"""'Publish' a given container, in a recursive way
Only here for epub publication (complexity of image/path traversal for the archive to be built)
Expand Down Expand Up @@ -221,7 +221,7 @@ def publish_container(
file_ext=file_ext,
image_callback=image_callback,
template=template,
**ctx
**ctx,
)
path_to_title_dict.update(result)
if container.conclusion and container.get_conclusion():
Expand Down
4 changes: 2 additions & 2 deletions zds/tutorialv2/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ContainerFactory(factory.Factory):
class Meta:
model = Container

title = factory.Sequence(lambda n: "Mon container No{}".format(n + 1))
title = factory.Sequence(lambda n: f"Mon container No{n + 1}")

@classmethod
def _generate(cls, create, attrs):
Expand Down Expand Up @@ -139,7 +139,7 @@ class ExtractFactory(factory.Factory):
class Meta:
model = Extract

title = factory.Sequence(lambda n: "Mon extrait No{}".format(n + 1))
title = factory.Sequence(lambda n: f"Mon extrait No{n + 1}")

@classmethod
def _generate(cls, create, attrs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_authenticated_outsider(self):
"""Test that on form submission, unauthorized users get a 403."""
self.client.force_login(self.outsider)
response = self.client.post(self.form_url, self.form_data)
self.assertEquals(response.status_code, 403)
self.assertEqual(response.status_code, 403)


@override_for_contents()
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorialv2/tests/tests_views/tests_editcontenttags.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_authenticated_outsider(self):
"""Test that on form submission, unauthorized users get a 403."""
self.client.force_login(self.outsider)
response = self.client.post(self.form_url, self.form_data)
self.assertEquals(response.status_code, 403)
self.assertEqual(response.status_code, 403)


@override_for_contents()
Expand Down
8 changes: 3 additions & 5 deletions zds/tutorialv2/tests/tests_views/tests_published.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def test_add_note(self):

# test quoting (without JS)
result = self.client.get(
reverse("content:add-reaction") + "?pk={}&cite={}".format(self.published.content.pk, reactions[0].pk)
reverse("content:add-reaction") + f"?pk={self.published.content.pk}&cite={reactions[0].pk}"
)
self.assertEqual(result.status_code, 200)

Expand All @@ -565,7 +565,7 @@ def test_add_note(self):

# test quoting (with JS)
result = self.client.get(
reverse("content:add-reaction") + "?pk={}&cite={}".format(self.published.content.pk, reactions[0].pk),
reverse("content:add-reaction") + f"?pk={self.published.content.pk}&cite={reactions[0].pk}",
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
)

Expand Down Expand Up @@ -1151,9 +1151,7 @@ def test_quote_note(self):
self.assertEqual(404, result.status_code)

# cite not existing note just gives the form empty
result = self.client.get(
reverse("content:add-reaction") + "?pk={}&cite={}".format(tuto.pk, 99999999), follow=True
)
result = self.client.get(reverse("content:add-reaction") + f"?pk={tuto.pk}&cite={99999999}", follow=True)
self.assertEqual(200, result.status_code)

self.assertTrue("text" not in result.context["form"]) # nothing quoted, so no text cited
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorialv2/views/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _create_beta_topic(self, msg, beta_version, _type, tags):
max_len = Topic._meta.get_field("title").max_length

while i < len(tags) and len(topic_title) + len(_tags) + len(tags[i].title) + 2 < max_len:
_tags += "[{}]".format(tags[i])
_tags += f"[{tags[i]}]"
i += 1
forum = get_object_or_404(Forum, pk=settings.ZDS_APP["forum"]["beta_forum_id"])
topic = create_topic(
Expand Down
2 changes: 1 addition & 1 deletion zds/tutorialv2/views/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def get_form_kwargs(self):
def form_valid(self, form):
user = self.request.user
authors = list(Profile.objects.contactable_members().filter(user__in=self.object.authors.all()))
authors = list([author.user for author in authors])
authors = list(author.user for author in authors)

# check if the warn is done on a public or beta version :
is_public = False
Expand Down
2 changes: 1 addition & 1 deletion zds/utils/context_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_version():
Retrieve version informations from `zds/_version.py`.
"""
if git_version is not None:
name = "{}/{}".format(__version__, git_version[:7])
name = f"{__version__}/{git_version[:7]}"
url = get_repository_url(settings.ZDS_APP["github_projects"]["default_repository"], "base_url")
return {"name": name, "url": f"{url}/tree/{git_version}"}
else:
Expand Down
4 changes: 2 additions & 2 deletions zds/utils/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, *args, **kwargs):
HTML("</div>"),
HTML("</div>"),
*args,
**kwargs
**kwargs,
)


Expand All @@ -52,7 +52,7 @@ def __init__(self, *args, send_label="Envoyer", display_save=False, **kwargs):
),
),
*args,
**kwargs
**kwargs,
)


Expand Down
6 changes: 3 additions & 3 deletions zds/utils/management/commands/clean_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def title_pk(tag):
return f'"{tag.title}" ({tag.pk})'

def replace(tag_to_delete, tag_to_use_instead):
self.stdout.write("Replacing {} with {}".format(title_pk(tag_to_delete), title_pk(tag_to_use_instead)))
self.stdout.write(f"Replacing {title_pk(tag_to_delete)} with {title_pk(tag_to_use_instead)}")

topics = Topic.objects.filter(tags__pk=tag_to_delete["pk"])
for topic in topics:
Expand All @@ -29,7 +29,7 @@ def replace(tag_to_delete, tag_to_use_instead):
content.tags.add(tag_to_use_instead.pk)
content.tags.remove(tag_to_delete["pk"])

self.stdout.write(" Deleting {}".format(title_pk(tag_to_delete)))
self.stdout.write(f" Deleting {title_pk(tag_to_delete)}")
Tag.objects.get(pk=tag_to_delete["pk"]).delete()

self.stdout.write(self.help)
Expand Down Expand Up @@ -57,4 +57,4 @@ def replace(tag_to_delete, tag_to_use_instead):
stripped = Tag.objects.get(pk=tag["pk"])
stripped.name = tag["stripped"]
stripped.save()
self.stdout.write("Stripped {} to {}".format(title_pk(tag), title_pk(stripped)))
self.stdout.write(f"Stripped {title_pk(tag)} to {title_pk(stripped)}")
Loading

0 comments on commit c8df573

Please sign in to comment.