Skip to content

Commit

Permalink
✨ Allows import and export of users (#1070)
Browse files Browse the repository at this point in the history
  • Loading branch information
damm89 authored Sep 20, 2023
1 parent 40dd5c9 commit 608df0f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion backend/src/zac/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
BlueprintPermissionResource,
RoleResource,
UserAuthorizationProfileResource,
UserResource,
)
from .widgets import PolicyWidget

Expand All @@ -39,7 +40,11 @@ class UserAuthorizationProfileInline(admin.TabularInline):


@admin.register(User)
class _UserAdmin(RelatedLinksMixin, HijackUserAdminMixin, UserAdmin):
class _UserAdmin(
ImportMixin, ExportActionMixin, RelatedLinksMixin, HijackUserAdminMixin, UserAdmin
):
resource_class = UserResource

fieldsets = (
(None, {"fields": ("username", "password")}),
(_("Personal info"), {"fields": ("first_name", "last_name", "email")}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 3.2.12 on 2023-09-05 06:10

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):
Expand Down
18 changes: 18 additions & 0 deletions backend/src/zac/accounts/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
)


class UserResource(resources.ModelResource):
class Meta:
model = User
import_id_fields = ("username",)
fields = (
"date_joined",
"email",
"first_name",
"last_name",
"is_active",
"is_staff",
"recently_viewed",
"uuid",
"username",
)
skip_unchanged = True


class RoleResource(resources.ModelResource):
class Meta:
model = Role
Expand Down

0 comments on commit 608df0f

Please sign in to comment.