style: standardize string formatting and improve readability across multiple files

- Refactored string formatting in various files to use consistent double quotes.
- Improved readability by adding newlines in function definitions and method calls.
- Cleaned up unnecessary imports and ensured proper spacing for better code clarity.
- Updated management commands and context processors for consistent formatting.
- Enhanced the overall maintainability of the codebase by adhering to PEP 8 guidelines.
- Applied Ruff linting and formatting
This commit is contained in:
badblocks 2025-06-12 20:53:38 -07:00
parent 4b9e4f651e
commit 39a002e394
No known key found for this signature in database
43 changed files with 1661 additions and 1159 deletions

View file

@ -3,24 +3,28 @@ from django.db import models
from django.core.exceptions import ValidationError
import re
def validate_friend_code(value):
"""Validate that friend code follows the format XXXX-XXXX-XXXX-XXXX where X is a digit."""
if not re.match(r'^\d{4}-\d{4}-\d{4}-\d{4}$', value):
if not re.match(r"^\d{4}-\d{4}-\d{4}-\d{4}$", value):
raise ValidationError(
'Friend code must be in format XXXX-XXXX-XXXX-XXXX where X is a digit.'
"Friend code must be in format XXXX-XXXX-XXXX-XXXX where X is a digit."
)
class CustomUser(AbstractUser):
default_friend_code = models.ForeignKey("FriendCode", on_delete=models.SET_NULL, null=True, blank=True)
default_friend_code = models.ForeignKey(
"FriendCode", on_delete=models.SET_NULL, null=True, blank=True
)
show_friend_code_on_link_previews = models.BooleanField(
default=False,
verbose_name="Show Friend Code on Link Previews",
help_text="This will primarily affect share link previews on X, Discord, etc."
help_text="This will primarily affect share link previews on X, Discord, etc.",
)
enable_email_notifications = models.BooleanField(
default=True,
verbose_name="Enable Email Notifications",
help_text="Receive trade notifications via email."
help_text="Receive trade notifications via email.",
)
reputation_score = models.IntegerField(default=0)
@ -47,10 +51,13 @@ class CustomUser(AbstractUser):
self.default_friend_code = other_codes.first()
self.save(update_fields=["default_friend_code"])
class FriendCode(models.Model):
friend_code = models.CharField(max_length=19, validators=[validate_friend_code])
in_game_name = models.CharField(max_length=14, null=False, blank=False)
user = models.ForeignKey(CustomUser, on_delete=models.PROTECT, related_name='friend_codes')
user = models.ForeignKey(
CustomUser, on_delete=models.PROTECT, related_name="friend_codes"
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
@ -67,4 +74,4 @@ class FriendCode(models.Model):
self.user.save(update_fields=["default_friend_code"])
def __str__(self):
return self.friend_code
return self.friend_code