Skip to content
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

Merged
merged 15 commits into from
Feb 10, 2025

Conversation

simonkagwi
Copy link
Contributor

@simonkagwi simonkagwi commented Feb 4, 2025

This PR adds import and export functionality in the App Users tab, using django-import-export.

Import and Export Buttons

2025-02-05_20-23

Export page

2025-02-05_20-24

Import page

2025-02-05_20-24_1

@simonkagwi simonkagwi marked this pull request as ready for review February 5, 2025 17:28
@simonkagwi simonkagwi requested a review from copelco February 5, 2025 17:28
Copy link
Member

@copelco copelco left a 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.

@@ -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
Copy link
Member

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

Here's an example.

Comment on lines 30 to 32
run: |
export DATABASE_URL=postgresql://postgres@localhost:9062/odk_publish
pytest
Copy link
Member

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:

Suggested change
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):
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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

Comment on lines +202 to +212
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))
Copy link
Member

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.

Copy link
Contributor Author

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.

@simonkagwi simonkagwi requested a review from copelco February 7, 2025 16:17
@simonkagwi simonkagwi merged commit 4e52596 into main Feb 10, 2025
1 check passed
@simonkagwi simonkagwi deleted the app-user-import-export branch February 10, 2025 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants