Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chloend committed Oct 3, 2024
1 parent 783502c commit 6fff870
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
8 changes: 4 additions & 4 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@


sitemaps = {
'flatpages': FlatPageSitemap,
'staticpages': StaticPageSitemap,
'wagtail': WagtailSitemap,
"flatpages": FlatPageSitemap,
"staticpages": StaticPageSitemap,
"wagtail": WagtailSitemap,
}


Expand All @@ -41,7 +41,7 @@
path("", include("lemarche.www.pages.urls")),
path("", include(wagtail_urls)),
# sitemap
path('sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='sitemap'),
path("sitemap.xml", sitemap, {"sitemaps": sitemaps}, name="sitemap"),
]

if settings.DEBUG and "debug_toolbar" in settings.INSTALLED_APPS:
Expand Down
11 changes: 5 additions & 6 deletions lemarche/www/pages/sitemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FlatPageSitemap(Sitemap):
def items(self):
return Page.objects.all()


def lastmod(self, obj):
return obj.updated_at

Expand All @@ -35,13 +36,11 @@ def _is_included_view(self, callback):
callback: The view callable.
Returns:
bool: True if the callback is a is a ContactView,
bool: True if the callback is a is a ContactView,
HomeView, PageView, or SitemapView, False otherwise.
"""
return (
hasattr(callback, 'view_class') and issubclass(
callback.view_class, (ContactView, PageView, SitemapView)
)
return hasattr(callback, "view_class") and issubclass(
callback.view_class, (ContactView, PageView, SitemapView)
)

def items(self):
Expand All @@ -59,7 +58,7 @@ def items(self):
# Handle nested URLResolver patterns (e.g., 'pages' namespace)
if isinstance(pattern, URLResolver):
static_pages.extend(
f'pages:{sub_pattern.name}'
f"pages:{sub_pattern.name}"
for sub_pattern in pattern.url_patterns
if isinstance(sub_pattern, URLPattern)
and self._is_included_view(sub_pattern.callback)
Expand Down
4 changes: 2 additions & 2 deletions lemarche/www/pages/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_sitemap_contains_wagtail_page(self):
def test_wagtail_page_contains_lastmod_tag(self):
"""Test the sitemap contains the lastmod tag for the wagtail page."""
response = self.client.get(reverse("sitemap"))
lastmod = self.wagtail_page.last_published_at.strftime('%Y-%m-%d')
lastmod = self.wagtail_page.last_published_at.strftime("%Y-%m-%d")

self.assertContains(response, f"<lastmod>{lastmod}</lastmod>")

Expand All @@ -218,6 +218,6 @@ def test_sitemap_contains_flatpage(self):
def test_flatpage_contains_lastmod_tag(self):
"""Test the sitemap contains the lastmod tag for the flatpage."""
response = self.client.get(reverse("sitemap"))
lastmod = self.flat_page.updated_at.strftime('%Y-%m-%d')
lastmod = self.flat_page.updated_at.strftime("%Y-%m-%d")

self.assertContains(response, f"<lastmod>{lastmod}</lastmod>")
10 changes: 5 additions & 5 deletions lemarche/www/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def trigger_error(request):
class SitemapView(View):
def get(self, request):
# Get sitemap.xml content
sitemap_url = request.build_absolute_uri('/sitemap.xml')
sitemap_url = request.build_absolute_uri("/sitemap.xml")
response = requests.get(sitemap_url)

urls = []
Expand All @@ -413,13 +413,13 @@ def get(self, request):
root = ElementTree.fromstring(response.content)

# Define namespace to find URLs
namespace = {'ns': 'http://www.sitemaps.org/schemas/sitemap/0.9'}
namespace = {"ns": "http://www.sitemaps.org/schemas/sitemap/0.9"}

for url in root.findall('ns:url', namespaces=namespace):
loc = url.find('ns:loc', namespaces=namespace)
for url in root.findall("ns:url", namespaces=namespace):
loc = url.find("ns:loc", namespaces=namespace)
if loc is not None:
urls.append(loc.text.strip())
except ElementTree.ParseError as e:
print("Erreur d'analyse XML:", e)

return render(request, 'pages/plan_du_site.html', {'sitemap_urls': urls})
return render(request, "pages/plan_du_site.html", {"sitemap_urls": urls})

0 comments on commit 6fff870

Please sign in to comment.