8000 fix: Remove circular import in `cms.forms.validators` by fsbraun · Pull Request #8225 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

fix: Remove circular import in cms.forms.validators #8225

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 4 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions cms/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

def my_function():
from cms.api import api_function

api_function(...)

instead of:
Expand All @@ -30,10 +31,12 @@ def my_function():

from cms.api import api_function


def my_function():
api_function(...)

"""

import warnings

from django.contrib.auth import get_user_model
Expand All @@ -47,8 +50,7 @@ def my_function():
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from cms.constants import TEMPLATE_INHERITANCE_MAGIC
from cms.forms.validators import validate_url_uniqueness
from cms.models import PageContent, PageUrl
from cms.models import PageContent
from cms.models.pagemodel import Page
from cms.models.permissionmodels import (
ACCESS_PAGE_AND_DESCENDANTS,
Expand Down Expand Up @@ -347,6 +349,8 @@ def create_page_content(
created_by = get_clean_username(created_by)

try:
from cms.forms.validators import validate_url_uniqueness

validate_url_uniqueness(page.site, path, language, exclude_page=page.parent)
except ValidationError as e:
raise IntegrityError(e)
Expand Down
11 changes: 8 additions & 3 deletions cms/forms/validators.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from typing import Optional
from typing import TYPE_CHECKING, Optional

from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator, URLValidator
from django.utils.safestring import mark_safe
from django.utils.translation import gettext

from cms.models.pagemodel import Page
from cms.utils.urlutils import admin_reverse, relative_url_regex

if TYPE_CHECKING:
# Only needed for type hinting - avoid circular import
from cms.models.pagemodel import Page


def validate_relative_url(value):
RegexValidator(regex=relative_url_regex)(value)
Expand All @@ -22,7 +25,9 @@ def validate_url(value):
URLValidator()(value)


def validate_url_uniqueness(site, path: str, language: str, user_language: Optional[str] = None, exclude_page: Optional[Page] = None):
def validate_url_uniqueness(
site, path: str, language: str, user_language: Optional[str] = None, exclude_page: Optional["Page"] = None
):
"""Checks for conflicting urls"""
from cms.models.pagemodel import Page, PageUrl

Expand Down
2 changes: 1 addition & 1 deletion cms/models/pagemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ def get_url_obj(self, language, fallback=True):
if fallback:
languages.extend(self.get_fallbacks(language))

if language not in self.urls_cache:
if self.urls_cache is None or language not 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 = {url.language: url for url in self.urls.all() if url.language in languages}
Expand Down
Loading
0