refactor(core): improve type checking and fix password handling in demo data
Replaced `pyright:ignore` with `ty:ignore` for better compatibility and accuracy in type annotations. Removed inline passwords during user creation and updated logic to securely set and save passwords afterward.
This commit is contained in:
parent
72a54de707
commit
6311993b14
2 changed files with 7 additions and 7 deletions
|
|
@ -97,7 +97,6 @@ class Command(BaseCommand):
|
||||||
def staff_user(self):
|
def staff_user(self):
|
||||||
user, _ = User.objects.get_or_create(
|
user, _ = User.objects.get_or_create(
|
||||||
email=f"staff@{DEMO_EMAIL_DOMAIN}",
|
email=f"staff@{DEMO_EMAIL_DOMAIN}",
|
||||||
password="Staff!Demo888",
|
|
||||||
first_name="Alice",
|
first_name="Alice",
|
||||||
last_name="Schon",
|
last_name="Schon",
|
||||||
is_staff=True,
|
is_staff=True,
|
||||||
|
|
@ -106,6 +105,7 @@ class Command(BaseCommand):
|
||||||
)
|
)
|
||||||
if _:
|
if _:
|
||||||
user.set_password("Staff!Demo888")
|
user.set_password("Staff!Demo888")
|
||||||
|
user.save()
|
||||||
if not user.groups.filter(name="E-Commerce Admin").exists():
|
if not user.groups.filter(name="E-Commerce Admin").exists():
|
||||||
user.groups.add(Group.objects.get(name="E-Commerce Admin"))
|
user.groups.add(Group.objects.get(name="E-Commerce Admin"))
|
||||||
return user
|
return user
|
||||||
|
|
@ -114,7 +114,6 @@ class Command(BaseCommand):
|
||||||
def super_user(self):
|
def super_user(self):
|
||||||
user, _ = User.objects.get_or_create(
|
user, _ = User.objects.get_or_create(
|
||||||
email=f"super@{DEMO_EMAIL_DOMAIN}",
|
email=f"super@{DEMO_EMAIL_DOMAIN}",
|
||||||
password="Super!Demo888",
|
|
||||||
first_name="Bob",
|
first_name="Bob",
|
||||||
last_name="Schon",
|
last_name="Schon",
|
||||||
is_superuser=True,
|
is_superuser=True,
|
||||||
|
|
@ -124,6 +123,7 @@ class Command(BaseCommand):
|
||||||
)
|
)
|
||||||
if _:
|
if _:
|
||||||
user.set_password("Super!Demo888")
|
user.set_password("Super!Demo888")
|
||||||
|
user.save()
|
||||||
return user
|
return user
|
||||||
|
|
||||||
def _load_demo_data(self) -> None:
|
def _load_demo_data(self) -> None:
|
||||||
|
|
@ -644,11 +644,11 @@ class Command(BaseCommand):
|
||||||
is_static_page=post_data.get("is_static_page", False),
|
is_static_page=post_data.get("is_static_page", False),
|
||||||
)
|
)
|
||||||
if "title_ru" in post_data:
|
if "title_ru" in post_data:
|
||||||
post.title_ru_ru = post_data["title_ru"]
|
post.title_ru_ru = post_data["title_ru"] # ty:ignore[unresolved-attribute]
|
||||||
if content_ru:
|
if content_ru:
|
||||||
post.content_ru_ru = content_ru
|
post.content_ru_ru = content_ru # ty:ignore[unresolved-attribute]
|
||||||
if "meta_description_ru" in post_data:
|
if "meta_description_ru" in post_data:
|
||||||
post.meta_description_ru_ru = post_data["meta_description_ru"]
|
post.meta_description_ru_ru = post_data["meta_description_ru"] # ty:ignore[unresolved-attribute]
|
||||||
post.save()
|
post.save()
|
||||||
|
|
||||||
for tag_name in post_data.get("tags", []):
|
for tag_name in post_data.get("tags", []):
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ def sitemap_index(request, *args, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyTypeChecker
|
# noinspection PyTypeChecker
|
||||||
sitemap_index.__doc__ = _( # pyright: ignore[reportUnknownVariableType]
|
sitemap_index.__doc__ = _( # ty:ignore[invalid-assignment]
|
||||||
"Handles the request for the sitemap index and returns an XML response. "
|
"Handles the request for the sitemap index and returns an XML response. "
|
||||||
"It ensures the response includes the appropriate content type header for XML."
|
"It ensures the response includes the appropriate content type header for XML."
|
||||||
)
|
)
|
||||||
|
|
@ -112,7 +112,7 @@ def sitemap_detail(request, *args, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyTypeChecker
|
# noinspection PyTypeChecker
|
||||||
sitemap_detail.__doc__ = _( # pyright: ignore[reportUnknownVariableType]
|
sitemap_detail.__doc__ = _( # ty:ignore[invalid-assignment]
|
||||||
"Handles the detailed view response for a sitemap. "
|
"Handles the detailed view response for a sitemap. "
|
||||||
"This function processes the request, fetches the appropriate "
|
"This function processes the request, fetches the appropriate "
|
||||||
"sitemap detail response, and sets the Content-Type header for XML."
|
"sitemap detail response, and sets the Content-Type header for XML."
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue