-
Notifications
You must be signed in to change notification settings - Fork 0
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
[#163] Update User and Food Request Models, Serializers, and Views #164
Conversation
Signed-off-by: delano <delano@cpan.org>
This commit makes the following changes to the pet model: - Removed the following fields: `name`, `dob`, `size`, `weight`, `usual_food_brands`, `allergies`, `allergy_types`, and `pictures` - Added the following new fields: - `pet_type` (e.g. "Dog", "Cat", etc.) - `pet_name` - `pet_dob` - `food_details` (a JSON field for storing pet food info) - `dog_details` (a JSON field for storing additional dog-specific info) - Removed the `profile` foreign key, as pets will now be directly associated with a `FoodRequest` instead of a `Profile` The primary goals of these changes are to: 1. Simplify the pet data model by focusing only on the essential information needed for the food delivery service, rather than trying to capture a comprehensive pet profile. 2. Make the pet data more flexible and extensible by using JSON fields for food and dog details, rather than having predefined fields. 3. Directly associate pets with a specific food request, rather than having them linked to a user profile which may have multiple requests. These changes should reduce complexity, improve maintainability, and provide more flexibility for future enhancements to the pet data handling.
- Moved the FoodRequestViewSet class to a separate module `food_request.py` to improve code organization and maintainability - This change separates the view logic from the main `__init__.py` file, making the codebase more modular and easier to navigate - The core functionality of the FoodRequestViewSet remains unchanged, but the restructuring will facilitate future additions or modifications to the food request handling
…request serializers to dedicated package Subject: Restructure user and request serializers for enhanced functionality - Moved the `FoodRequestCreateSerializer` and `FoodRequestUpdateSerializer` to a new `request` package to better organize the serializers - Added a new `RegisterSerializer` that extends the base `UserSerializer` and generates a random password for new users - Refactored the `UserSerializer` to handle password hashing and generation of a random password for new users - These changes improve the structure and functionality of the user and request serializer modules, making the codebase more maintainable and extensible
- Enhance the login page error handling to better differentiate between different types of errors - Add a new flow to redirect users to the welcome/clients page when the login response indicates the user needs to create an account - This change improves the user experience by providing more specific error messages and a clear path forward when a new account is required
…oint The changes made in this commit have the following key objectives: 1. Disable the automatic registration of new users in the Passwordless authentication system. This is done by setting the `PASSWORDLESS_REGISTER_NEW_USERS` configuration option to `False`. 2. Add a new custom `RegisterUserAPIView` that provides an API endpoint for user registration. This endpoint allows users to register by providing the necessary information, which is then used to create a new user account. The registered user is also issued an authentication token. These changes were made to give more control over the user registration process and to provide a dedicated API endpoint for this functionality, rather than relying solely on the automatic registration feature of the Passwordless authentication system.
Clearer field labels and responsive design. - Update the login page to include a more specific link for the sign-up page, directing users to the "clients" sign-up flow - Improve the layout and field labels of the "clients" sign-up page, making it more user-friendly and accessible - Add icons, placeholders, and help text to the form fields - Mark required fields with an asterisk - Make the "name" field autofocus - Add a footer link for users to sign up as a volunteer instead
The changes in this commit improve the user registration flow and error handling in the application: 1. **Fetch API using $fetch instead of useFetch**: The code has been updated to use the more modern and recommended `$fetch` function from Nuxt.js instead of the older `useFetch`. This provides a more streamlined and consistent API for making HTTP requests. 2. **Handle registration errors properly**: The error handling has been enhanced to better display any validation errors returned from the API. Specifically: - If the API returns validation errors (e.g., for the email field), these are now displayed to the user using the `useSnackbar` utility. - If the API returns a 404 error (page not found), the code now correctly throws a `createError` to trigger the Nuxt.js error handling mechanism. 3. **Redirect to the dashboard on successful registration**: After a successful registration, the user is now automatically redirected to the dashboard page, providing a smoother user experience. 4. **Remove unnecessary code comments**: Some commented-out code has been removed, as it was no longer necessary. These changes improve the overall user experience and robustness of the registration flow in the application.
- Refactor `User` model to remove redundant fields - Introduce `HasDetails` mixin for models with JSON details - Create `CurrentUserAPIView` for authenticated user access - Add post_save signal to create `Profile` upon user creation - Simplify `UserSerializer` and remove obsolete tests - Update Nuxt client for new API endpoints and authentication flow Benefits: - Improved security by eliminating plain-text password storage - Streamlined user model and reduced duplication - Centralized handling of user details through model mixin - Dedicated API endpoint for current user, restricting access to other users - Automated profile creation upon user registration - Modernized client integration with new authentication mechanism Considerations: - Ensure thorough testing of authentication and registration flows - Update documentation and provide guidance for developers
Allows running tests via `python manage.py test` using pytest instead of the default Django test runner. This provides more flexible testing capabilities and allows using pytest features like `--reuse-db` to speed up test runs. The changes include: - Add `TEST_RUNNER` setting to use the new `PytestTestRunner` class - Disable rich logging and use standard StreamHandler in tests - Add `PytestTestRunner` class to run pytest and translate Django test options
The HasDetails abstract model mixin, used for models that require a details JSONField, has been moved from the base.py file to the mixins.py file. This reorganizes the model mixins into a dedicated file, separating them from the base model classes, promoting better code organization and maintainability.
Abstract user profile details into a dedicated serializer. This separates profile information from core user attributes, improving code organization and maintainability. Additionally: - Refactor UserSerializer to use the new ProfileSerializer - Remove obsolete phone field from UserSerializer - Simplify user registration by generating a random UUID as the initial password - Add explanatory comments on password hashing and UUID usage for registration
The `Profile` model's `user` foreign key was changed from `on_delete=models.DO_NOTHING` to `on_delete=models.CASCADE` to maintain data integrity by automatically deleting associated profiles when a user is deleted. Additionally: - Made `phone_number` nullable to handle scenarios where a phone number is not provided - Refactored `create_user_profile` signal to dynamically build params for `Profile.objects.create`, ensuring `role` is only included if a value is present These changes improve data consistency, remove unused code, and make the profile creation more robust.
The key changes made in this commit are: 1. Restructured the User model fields - Added `name` and `terms_agreement` fields 2. Modified the Profile model - Added `details`, `created`, `modified`, and `is_removed` fields - Made `phone_number` nullable - Removed `user` foreign key field (moved to the end) - Added `user` foreign key with `CASCADE` delete behavior and related name 3. Reorganized Branch model fields - Moved `ext_id`, `id`, and `display_name` fields within the model Overall, this commit reorganizes and consolidates fields across the User, Profile, and Branch models for better structure and clarity.
- Update `User` model to use `name` instead of `username`, `first_name`, `last_name` - Remove `Role` model and associated tests - Update user registration serializer and tests - Remove redundant tests for `Profile` model - Add signal tests to ensure `Profile` creation on `User` creation - Refactor food request views tests Rationale: - Simplify user model by consolidating name fields into single `name` field - Remove unused `Role` model and associated tests - Update user registration serializer and tests to match model changes - Remove redundant profile model tests that are no longer relevant - Add tests for signals to ensure correct profile creation behavior - Refactor food request views tests for better code organization and maintainability Considerations: - Ensure all affected areas of the codebase are updated to use the new `name` field - Update any references to the removed `Role` model and associated logic - Verify user registration and authentication flows work as expected with the updated serializer - Double-check that profile creation behavior is consistent across different scenarios
PR Review 🔍
|
PR Code Suggestions ✨
💡 Tool usage guide:Overview:
See the improve usage page for a comprehensive guide on using this tool. |
Signed-off-by: delano <delano@cpan.org>
Signed-off-by: delano <delano@cpan.org>
Signed-off-by: delano <delano@cpan.org>
Signed-off-by: delano <delano@cpan.org>
Signed-off-by: delano <delano@cpan.org>
Signed-off-by: delano <delano@cpan.org>
Signed-off-by: delano <delano@cpan.org>
Signed-off-by: delano <delano@cpan.org>
From the Nuxt release notes: > This will refresh your lockfile as well, and ensures that you pull in updates from other dependencies that Nuxt relies on, particularly in the unjs ecosystem. Signed-off-by: delano <delano@cpan.org>
Signed-off-by: delano <delano@cpan.org>
Signed-off-by: delano <delano@cpan.org>
Signed-off-by: delano <delano@cpan.org>
Signed-off-by: delano <delano@cpan.org>
Signed-off-by: delano <delano@cpan.org>
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.
Thank you 😊
Addresses #163
This update introduces significant changes across multiple files, focusing on enhancing the food request submission process, user management, and overall code structure. Key changes include:
Migration Updates:
DeliveryRegion
model.Pet
model by removing redundant fields and adding JSON fields forfood_details
anddog_details
.User
model to include adetails
JSON field and madeusername
optional.details
JSON field to theProfile
model and removed theRole
model.Branch
model to include more detailed address fields and updated default values for some fields.FoodRequest
model to include apets
ManyToManyField.Serializer Enhancements:
FoodRequest
,Pet
, andProfile
.UserSerializer
to handle user registration and profile creation.RegisterSerializer
for user registration with automatic password generation.View and API Enhancements:
UserViewSet
toCurrentUserAPIView
andRegisterUserAPIView
for better user management.FoodRequestViewSet
for handling food request operations.Testing Enhancements:
Frontend Enhancements:
Configuration and Documentation:
.codiumai.toml
andpyproject.toml
for better test configuration and dependency management.