8000 fix: Replaced `languages` field from `Page` which used to become inconsistent by fsbraun · Pull Request #8080 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

fix: Replaced languages field from Page which used to become inconsistent #8080

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

Merged
merged 8 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix: sourcery complexity reduction recommendation
  • Loading branch information
Github Release Action committed Nov 20, 2024
commit be640fb7729e38ee36f551d834d70612f869f7c1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def remove_pageurl_duplicates(apps, schema_editor):
PageUrl = apps.get_model("cms", "PageUrl")
non_unique = PageUrl.objects.values("page_id", "language").annotate(total=Count("language")).filter(total__gt=1)
for item in non_unique:
for url in PageUrl.objects.filter(page_id=item["page_id"], language=item["language"])[1:]:
for url in PageUrl.objects.filter(page_id=item["page_id"], language=item["language"]).order_by("-pk")[1:]:
url.delete()


Expand Down
18 changes: 6 additions & 12 deletions cms/models/pagemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,26 +811,20 @@ def get_page_content_obj_attribute(self, attrname, language=None, fallback=True,
def get_url_obj(self, language, fallback=True):
"""Get the path of the page depending on the given language"""
languages = [language]

if fallback:
languages.extend(self.get_fallbacks(language))

for _language in languages:
if _language in self.urls_cache:
language = _language
break
else:
if not language in self.urls_cache:
# `get_page_from_request` will fill the cache only for the current language
# Here, we fully fill it and try again
self.urls_cache ={
self.urls_cache = {
url.language: url for url in self.urls.all() if url.language in languages
}
for _language in languages:
if _language in self.urls_cache:
language = _language
break

return self.urls_cache.get(language)
return next(
(self.urls_cache[lang] for lang in languages if lang in self.urls_cache),
None
)

def get_path(self, language, fallback=True):
url = self.get_url_obj(language, fallback)
Expand Down
Loading
0