-
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
Add import and export functionality for App Users. #4
Conversation
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.
Looks great! Thanks for working on this. Added a few suggestions.
.github/workflows/tests.yaml
Outdated
@@ -21,4 +21,12 @@ jobs: | |||
sudo apt-get install -y --no-install-recommends postgresql-client | |||
pip install -U -q pip-tools | |||
pip-sync requirements/base/base.txt requirements/dev/dev.txt | |||
- run: pytest | |||
- name: Bring up auxiliary services |
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.
I recommend using a service for this:
services:
postgres:
# From:
# https://docs.github.com/en/actions/guides/creating-postgresql-service-containers
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
.github/workflows/tests.yaml
Outdated
run: | | ||
export DATABASE_URL=postgresql://postgres@localhost:9062/odk_publish | ||
pytest |
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.
DATABASE_URL
can be in an env
block:
run: | | |
export DATABASE_URL=postgresql://postgres@localhost:9062/odk_publish | |
pytest | |
run: pytest | |
env: | |
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres |
from .models import AppUser, AppUserTemplateVariable | ||
|
||
|
||
class AppUserTemplateVariableWidget(widgets.ForeignKeyWidget): |
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.
I think it could be helpful to add comments to the classes/methods in this file, to help provide context of when methods are called.
def do_instance_save(self, instance, is_create): | ||
instance.save() | ||
for template_variable in instance._template_variables_to_save: | ||
template_variable.app_user = instance |
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.
Maybe we could add logging here and in the delete loop below to log when certain actions occur.
form.dataset, use_transactions=True, rollback_on_validation_errors=True | ||
) | ||
if not (result.has_validation_errors() or result.has_errors()): | ||
return redirect("odk_publish:app-user-list", odk_project_pk=odk_project_pk) |
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.
Adding a success message might be nice for the user to know the import was successful
for row in result.invalid_rows: | ||
for field, errors in row.error_dict.items(): | ||
if field == "__all__": | ||
field = "id" | ||
for error in errors: | ||
messages.error(request, f"Row {row.number}, Column '{field}': {error}") | ||
for row in result.error_rows: | ||
for error in row.errors: | ||
messages.error(request, f"Row {row.number}: {error.error!r}") | ||
for error in result.base_errors: | ||
messages.error(request, repr(error.error)) |
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.
I wonder how this'll behave if we have 50+ app users all with the same error.
Thinking on this, since rows can be deleted, getting the review screen implemented does sound helpful, since errors could be displayed inline. I'll open a ticket for it.
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.
True, a review screen would be helpful. I'll look into it.
This PR adds import and export functionality in the App Users tab, using
django-import-export
.Import and Export Buttons
Export page
Import page