-
-
Notifications
You must be signed in to change notification settings - Fork 212
Code cleanup 160 #565
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
Open
reenu153
wants to merge
12
commits into
TreyWW:main
Choose a base branch
from
LaraMerdol:code-cleanup-160
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Code cleanup 160 #565
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
379c265
Code refactoring
LaraMerdol d319124
Code cleanup: rename functions
LaraMerdol d471406
Remone unnecessary constant definition
LaraMerdol 1391f6c
code cleanup
LaraMerdol a1a2fba
Merge branch 'code-cleanup-160' of https://github.com/LaraMerdol/MyFi…
LaraMerdol 1cf4e18
new changes after debug add unchanged entries
LaraMerdol 025fd48
Test pass
LaraMerdol 197d4f6
Refactored env read
Siddhant-Mhapankar 5e01067
Added blank = False for name fields
Siddhant-Mhapankar db01529
lint cleaning addition
LaraMerdol 76dba11
delete commented lines
LaraMerdol 3062c90
Merge pull request #1 from LaraMerdol/code-cleanup-160-unstable
LaraMerdol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Backend core cosntant.py | ||
| """ | ||
| Constants used across the application for model field attributes. | ||
| """ | ||
|
|
||
| # Field length constants | ||
| MAX_LENGTH_STANDARD = 100 # Most commonly used max_length | ||
| MAX_LENGTH_NAME = 64 # Used for name fields | ||
| MAX_LENGTH_DESCRIPTION = 500 # Used for description fields | ||
|
|
||
| # Decimal field constants | ||
| DECIMAL_MAX_DIGITS = 15 | ||
| DECIMAL_PLACES = 2 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,27 +16,25 @@ | |||||
| from storages.backends.s3 import S3Storage | ||||||
|
|
||||||
|
|
||||||
| def _public_storage(): | ||||||
| def get_public_storage(): | ||||||
| return storages["public_media"] | ||||||
|
|
||||||
|
|
||||||
| def _private_storage() -> FileSystemStorage | S3Storage: | ||||||
| def get_private_storage() -> FileSystemStorage | S3Storage: | ||||||
| return storages["private_media"] | ||||||
|
|
||||||
|
|
||||||
| def RandomCode(length=6): | ||||||
| def generate_verification_code(length=6): | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| return get_random_string(length=length).upper() | ||||||
|
|
||||||
|
|
||||||
| def RandomAPICode(length=89): | ||||||
| def generate_api_key(length=89): | ||||||
| return get_random_string(length=length).lower() | ||||||
|
|
||||||
|
|
||||||
| def upload_to_user_separate_folder(instance, filename, optional_actor=None) -> str: | ||||||
| def get_file_upload_path(instance, filename: str, optional_actor=None) -> str: | ||||||
| instance_name = instance._meta.verbose_name.replace(" ", "-") | ||||||
|
|
||||||
| print(instance, filename) | ||||||
|
|
||||||
| if optional_actor: | ||||||
| if isinstance(optional_actor, User): | ||||||
| return f"{instance_name}/users/{optional_actor.id}/{filename}" | ||||||
|
|
@@ -81,7 +79,7 @@ class User(AbstractUser): | |||||
| require_change_password = models.BooleanField(default=False) # does user need to change password upon next login | ||||||
|
|
||||||
| class Role(models.TextChoices): | ||||||
| # NAME DJANGO ADMIN NAME | ||||||
| # NAME DJANGO ADMIN NAME | ||||||
| DEV = "DEV", "Developer" | ||||||
| STAFF = "STAFF", "Staff" | ||||||
| USER = "USER", "User" | ||||||
|
|
@@ -172,7 +170,7 @@ class ServiceTypes(models.TextChoices): | |||||
| RESET_PASSWORD = "reset_password", "Reset Password" | ||||||
|
|
||||||
| uuid = models.UUIDField(default=uuid4, editable=False, unique=True) # This is the public identifier | ||||||
| token = models.TextField(default=RandomCode, editable=False) # This is the private token (should be hashed) | ||||||
| token = models.TextField(default=generate_verification_code, editable=False) # This is the private token (should be hashed) | ||||||
|
|
||||||
| user = models.ForeignKey(User, on_delete=models.CASCADE) | ||||||
| created = models.DateTimeField(auto_now_add=True) | ||||||
|
|
@@ -216,7 +214,7 @@ class CoreFeatures(models.TextChoices): | |||||
| ) | ||||||
| profile_picture = models.ImageField( | ||||||
| upload_to="profile_pictures/", | ||||||
| storage=_public_storage, | ||||||
| storage=get_public_storage, | ||||||
| blank=True, | ||||||
| null=True, | ||||||
| ) | ||||||
|
|
@@ -294,7 +292,7 @@ def set_expires(self): | |||||
|
|
||||||
| def save(self, *args, **kwargs): | ||||||
| if not self.code: | ||||||
| self.code = RandomCode(10) | ||||||
| self.code = generate_verification_code(10) | ||||||
| self.set_expires() | ||||||
| super().save() | ||||||
|
|
||||||
|
|
@@ -509,14 +507,17 @@ def get_quota_limit(self, user: User, quota_limit: QuotaLimit | None = None): | |||||
| return self.value | ||||||
|
|
||||||
| def get_period_usage(self, user: User): | ||||||
| if self.limit_type == "forever": | ||||||
| return self.quota_usage.filter(user=user, quota_limit=self).count() | ||||||
| elif self.limit_type == "per_month": | ||||||
| return self.quota_usage.filter(user=user, quota_limit=self, created_at__month=datetime.now().month).count() | ||||||
| elif self.limit_type == "per_day": | ||||||
| return self.quota_usage.filter(user=user, quota_limit=self, created_at__day=datetime.now().day).count() | ||||||
| else: | ||||||
| return "Not available" | ||||||
| base_query = self.quota_usage.filter(user=user, quota_limit=self) | ||||||
|
|
||||||
| period_filters = { | ||||||
| "forever": {}, | ||||||
| "per_month": {"created_at__month": timezone.now().month}, | ||||||
| "per_day": {"created_at__day": timezone.now().day}, | ||||||
| } | ||||||
|
|
||||||
| if filters := period_filters.get(self.limit_type): | ||||||
| return base_query.filter(**filters).count() | ||||||
| return "Not available" | ||||||
|
|
||||||
| def strict_goes_above_limit(self, user: User, extra: str | int | None = None, add: int = 0) -> bool: | ||||||
| current: Union[int, None, QuerySet[QuotaUsage], Literal["Not Available"]] | ||||||
|
|
@@ -697,7 +698,7 @@ class Meta: | |||||
|
|
||||||
|
|
||||||
| class FileStorageFile(OwnerBase): | ||||||
| file = models.FileField(upload_to=upload_to_user_separate_folder, storage=_private_storage) | ||||||
| file = models.FileField(upload_to=get_file_upload_path, storage=get_private_storage) | ||||||
| file_uri_path = models.CharField(max_length=500) # relative path not including user folder/media | ||||||
| last_edited_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True, editable=False, related_name="files_edited") | ||||||
| created_at = models.DateTimeField(auto_now_add=True) | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in comment: "cosntant.py" should be "constants.py".
Proposed fix
📝 Committable suggestion