-
Notifications
You must be signed in to change notification settings - Fork 9
[OSDEV-2122][Climate Trace] Allow users to PATCH v1/production-locations without 'name', 'address', 'country' #728
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
Merged
VadimKovalenkoSNF
merged 53 commits into
main
from
OSDEV-2122-patch-v1-allow-name-address-country
Sep 15, 2025
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
74c726a
Add can_partially_update_production_location field to User model
VadimKovalenkoSNF b4651eb
Merge branch 'main' into OSDEV-2122-patch-v1-allow-name-address-country
VadimKovalenkoSNF 68a60c0
Apply unit tests
VadimKovalenkoSNF c86aa50
Fix lint issues
VadimKovalenkoSNF 951332a
Merge branch 'main' into OSDEV-2122-patch-v1-allow-name-address-country
VadimKovalenkoSNF edbe34f
Add condition depending on contributor verification status
VadimKovalenkoSNF 603e020
Add signal to disable can_partially_update_production_location field
VadimKovalenkoSNF 6390470
Disable cursor for prohibited Can partially update production locatio…
VadimKovalenkoSNF 8e4d1d5
Merge branch 'main' into OSDEV-2122-patch-v1-allow-name-address-country
VadimKovalenkoSNF a44fa9f
Add test for unverified user
VadimKovalenkoSNF f2b19da
Fix flake8 issues
VadimKovalenkoSNF 2de94eb
Merge branch 'main' into OSDEV-2122-patch-v1-allow-name-address-country
VadimKovalenkoSNF a168162
Remove can_patch checkbox from admin panel
VadimKovalenkoSNF 3b2dba6
Inherit ProductionLocationSchemaSerializer
VadimKovalenkoSNF 189066e
Create location productions lookup
VadimKovalenkoSNF 8ec07b6
Remove redundant test cases
VadimKovalenkoSNF 123365d
Add tests for production locations lookup service
VadimKovalenkoSNF 6fa08e1
Bring back tests for parent company field
VadimKovalenkoSNF 2c9ba7f
Remove leftovers
VadimKovalenkoSNF 605093f
Minor fixes
VadimKovalenkoSNF 13c23a7
Replace serializer init into static private method
VadimKovalenkoSNF 8fa5fcb
Fix flake8 issue
VadimKovalenkoSNF 6060304
Remove redundant comment
VadimKovalenkoSNF 68fbe84
Add logs for lookup service
VadimKovalenkoSNF ea6fe03
Add error handling for missing fields if partly applied
VadimKovalenkoSNF 613b76e
Separate method for required field error throwing
VadimKovalenkoSNF 425357a
Handle coordinates field (partial impl)
VadimKovalenkoSNF 6c13448
Add coordinates check
VadimKovalenkoSNF e35fc64
Refactor serializer preparation method and lookup helper functions
VadimKovalenkoSNF e9ec054
Merge branch 'main' into OSDEV-2122-patch-v1-allow-name-address-country
VadimKovalenkoSNF d0705d2
Add Python cursor rules, update lookup tests
VadimKovalenkoSNF 1541b08
Add tests for handling required fields
VadimKovalenkoSNF 88c2be8
Update release notes
VadimKovalenkoSNF bb23361
Refactor backfill condition
VadimKovalenkoSNF c078829
Update cursor rules
VadimKovalenkoSNF 8d380bf
Fix tests
VadimKovalenkoSNF 06e3721
Fix flake8 issues
VadimKovalenkoSNF 06ed969
Use raw_data to handle errors
VadimKovalenkoSNF a109819
Return deep copy of backfilled data
VadimKovalenkoSNF cf5e11f
Refactor backfill processing
VadimKovalenkoSNF df957c6
Remove cursor-rules
VadimKovalenkoSNF 6ce8f57
Remove failed tests
VadimKovalenkoSNF 90ea656
Fix flake8 issues
VadimKovalenkoSNF 335591f
Minor fix
VadimKovalenkoSNF 4a3e135
Remove redundant error checks
VadimKovalenkoSNF 0986538
Make ProductionLocationSchemaSerializer as abstract class
VadimKovalenkoSNF f6e6ff6
Remove redundant test attachments
VadimKovalenkoSNF 5c29c72
Merge branch 'main' into OSDEV-2122-patch-v1-allow-name-address-country
VadimKovalenkoSNF ac545f3
Pass only request type instead of entire dto
VadimKovalenkoSNF 37c1440
Fix flake8 issue
VadimKovalenkoSNF 5c9ddbd
Handle empty PATCH body error
VadimKovalenkoSNF 9c79f93
Remove redundant try-catch, minor refactoring
VadimKovalenkoSNF 8a56423
Merge branch 'main' into OSDEV-2122-patch-v1-allow-name-address-country
VadimKovalenkoSNF 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
21 changes: 21 additions & 0 deletions
21
src/django/api/serializers/v1/production_location_patch_schema_serializer.py
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,21 @@ | ||
| from rest_framework import serializers | ||
| from api.serializers.v1.production_location_schema_serializer \ | ||
| import ProductionLocationSchemaSerializer | ||
|
|
||
|
|
||
| class ProductionLocationPatchSchemaSerializer( | ||
| ProductionLocationSchemaSerializer | ||
| ): | ||
| def __init__(self, *args, **kwargs): | ||
| super().__init__(*args, **kwargs) | ||
| self._set_core_required(False) | ||
|
|
||
| def validate(self, data): | ||
| if not data: | ||
| raise serializers.ValidationError([ | ||
| { | ||
| 'field': 'non_field_errors', | ||
| 'detail': 'No fields provided.' | ||
| } | ||
| ]) | ||
| return super().validate(data) |
10 changes: 10 additions & 0 deletions
10
src/django/api/serializers/v1/production_location_post_schema_serializer.py
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,10 @@ | ||
| from api.serializers.v1.production_location_schema_serializer \ | ||
| import ProductionLocationSchemaSerializer | ||
|
|
||
|
|
||
| class ProductionLocationPostSchemaSerializer( | ||
| ProductionLocationSchemaSerializer | ||
| ): | ||
| def __init__(self, *args, **kwargs): | ||
| super().__init__(*args, **kwargs) | ||
| self._set_core_required(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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| from typing import Dict, List | ||
| from api.models.facility.facility import Facility | ||
| from api.models.facility.facility_list_item import FacilityListItem | ||
|
|
||
|
|
||
| def fetch_required_fields(os_id: str) -> Dict[str, str]: | ||
| promoted = ( | ||
| FacilityListItem.objects | ||
| .filter(facility_id=os_id) | ||
| .filter( | ||
| processing_results__contains=[{'action': 'promote_match'}] | ||
| ) | ||
| .order_by('-created_at') | ||
| .first() | ||
| ) | ||
| if promoted and promoted.name: | ||
| return { | ||
| 'name': promoted.name, | ||
| 'address': promoted.address or '', | ||
| 'country': promoted.country_code or '', | ||
| } | ||
|
|
||
| latest = ( | ||
| FacilityListItem.objects | ||
| .filter(facility_id=os_id) | ||
| .order_by('-created_at') | ||
| .first() | ||
| ) | ||
| if latest: | ||
| return { | ||
| 'name': latest.name or '', | ||
| 'address': latest.address or '', | ||
| 'country': latest.country_code or '', | ||
| } | ||
|
|
||
| os = Facility.objects.get(id=os_id) | ||
| return { | ||
| 'name': os.name, | ||
| 'address': os.address, | ||
| 'country': os.country_code, | ||
| } | ||
|
|
||
|
|
||
| def has_coordinates(data: Dict) -> bool: | ||
| return bool(data.get('coordinates')) | ||
|
|
||
|
|
||
| def get_missing_required_fields(data: Dict) -> List[str]: | ||
| required_fields = ('name', 'address', 'country') | ||
| return [field for field in required_fields if not data.get(field)] | ||
|
|
||
|
|
||
| def has_all_required_fields(data: Dict) -> bool: | ||
| return len(get_missing_required_fields(data)) == 0 | ||
|
|
||
|
|
||
| def has_some_required_fields(data: Dict) -> bool: | ||
| missing_count = len(get_missing_required_fields(data)) | ||
| return 0 < missing_count < 3 | ||
|
|
||
|
|
||
| def is_coordinates_without_all_required_fields(data: Dict) -> bool: | ||
| return has_coordinates(data) and not has_all_required_fields(data) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.