-
Notifications
You must be signed in to change notification settings - Fork 6
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
Admin for universal update script #4663
base: staging
Are you sure you want to change the base?
Admin for universal update script #4663
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## staging #4663 +/- ##
===========================================
+ Coverage 84.32% 86.02% +1.70%
===========================================
Files 547 556 +9
Lines 35996 36668 +672
===========================================
+ Hits 30352 31542 +1190
+ Misses 5644 5126 -518
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
if value is None and self.allow_multiple_selected: | ||
return [] | ||
elif self.allow_multiple_selected: | ||
processed_value = [v for v in value.split(",")] |
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.
just value.split(",")
elif self.allow_multiple_selected: | ||
processed_value = [v for v in value.split(",")] | ||
|
||
if not isinstance(value, (tuple, list)): |
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.
then value
typing is incorrect
db_count = Individual.objects.filter(unicef_id__in=unicef_ids, program_id=program_id).count() | ||
if db_count != len(unicef_ids): | ||
unicef_ids_from_db = list( # pragma: no cover | ||
Individual.objects.filter(unicef_id__in=unicef_ids, program_id=program_id).values_list( | ||
"unicef_id", flat=True | ||
) | ||
) | ||
diff = set(unicef_ids) - set(unicef_ids_from_db) # pragma: no cover | ||
raise Exception("Some unicef ids are not in the program: " + str(diff)) # pragma: no cover |
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.
there is a lot of pragmas, this case could be tested :D
if self.individual_flex_fields is None: | ||
return [] # pragma: no cover | ||
for field, (name, validator, _handler) in self.individual_flex_fields.items(): | ||
value = row[headers.index(field)] | ||
error = validator(value, name, row, self.business_area, self.program) | ||
if error: # pragma: no cover | ||
errors.append(f"Row: {row_index} - {error}") | ||
return errors | ||
|
||
def validate_household_flex_fields( | ||
self, row: Tuple[Any, ...], headers: List[str], individual: Individual, row_index: int | ||
) -> List[str]: | ||
errors = [] | ||
if self.household_flex_fields is None: | ||
return [] # pragma: no cover | ||
for field, (name, validator, _handler) in self.household_flex_fields.items(): | ||
value = row[headers.index(field)] | ||
error = validator(value, name, row, self.business_area, self.program) | ||
if error: # pragma: no cover | ||
errors.append(f"Row: {row_index} - {error}") | ||
return errors | ||
|
||
def validate_documents( | ||
self, row: Tuple[Any, ...], headers: List[str], individual: Individual, row_index: int | ||
) -> List[str]: | ||
if self.document_fields is None: | ||
return [] # pragma: no cover | ||
errors = [] |
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.
Some of the validations also could be tested not to spam with the pragmas
AB#237765
This pull request introduces significant changes to the
universal_update_script
functionality, including new models, admin configurations, and Celery tasks. The most important changes include the addition of theUniversalUpdate
model, the creation of admin forms and views for managing universal updates, and the implementation of Celery tasks for handling update processes.Universal Update Script Enhancements:
New Model:
src/hct_mis_api/apps/universal_update_script/models.py
: Added theUniversalUpdate
model to manage universal update processes, including fields for individual and household data, document types, and delivery mechanisms.Admin Configuration:
src/hct_mis_api/apps/universal_update_script/admin.py
: Created admin forms and views for theUniversalUpdate
model, including dynamic field choices and custom buttons for generating templates and starting update tasks.Celery Tasks:
src/hct_mis_api/apps/universal_update_script/celery_tasks.py
: Implemented Celery tasks for running universal individual updates and generating update templates, with logging and error handling.Other Changes:
App Configuration:
src/hct_mis_api/apps/universal_update_script/apps.py
: Added theAppConfig
for theuniversal_update_script
app.Database Migration:
src/hct_mis_api/apps/universal_update_script/migrations/0001_migration.py
: Created the initial migration for theUniversalUpdate
model, setting up the database schema.