Code cleanup 160
Description
This pull request refactors the code primarily to address the code cleanup tasks outlined in issue #160. The refactoring addresses several code smells and aims to improve the readability, maintainability, and structure of the codebase.
Refactoring Details:
-
Magic Numbers/Constants:
- Issue: Magic numbers and hardcoded values were scattered across the codebase, making the code harder to maintain.
- Refactoring:
- Created a
backend/core/constants.pyfile to define named constants for recurring numerical values (e.g.,MAX_LENGTH_STANDARD,MAX_LENGTH_NAME,MAX_LENGTH_DESCRIPTION,DECIMAL_MAX_DIGITS,DECIMAL_PLACES). - Replaced hardcoded
max_lengthanddecimalconstraints in models with the defined constants.
- Created a
-
Inappropriate/Unclear Naming:
- Issue: Some variable and function names were ambiguous and did not clearly convey their purpose.
- Refactoring:
- Renamed functions to be more descriptive and Pythonic:
_public_storage→get_public_storage_private_storage→get_private_storageRandomCode→generate_verification_codeRandomAPICode→generate_api_keyupload_to_user_separate_folder→get_file_upload_path
- These changes enhance clarity by explicitly describing the functionality of each function.
- Renamed functions to be more descriptive and Pythonic:
-
Set blank=False for name fields: Ensures name and related fields (e.g., description, event_name) are required across multiple models to prevent missing data.
Checklist
- [x] Ran the Black Formatter and djLint-er on any new code (checks will fail without)
- [ ] Made any changes or additions to the documentation where required
- [x] Changes generate no new warnings/errors
- [x] New and existing unit tests pass locally with my changes
What type of PR is this?
- ♻️ Code Refactor
Added/updated tests?
- 🙅 no, because they aren't needed
Related PRs, Issues etc
- Related Issue #160
Hey @reenu153 / @LaraMerdol,
Thank you for these changes! There's currently a fairly big queue in PRs so I wont be able to merge this right away, but I do appreciate the effort! I'll let you know when I get round to testing and merging this :)