Skip to content

Commit

Permalink
Merge pull request #144 from swiftss-org/csv-download-admin
Browse files Browse the repository at this point in the history
CSV export in admin and remove permissions for only admins
  • Loading branch information
diogenis-si authored Sep 22, 2023
2 parents 7fe716f + 5bb1d69 commit 2d55d55
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"rest_framework",
"rest_framework.authtoken",
"corsheaders",
"import_export"
]

LOCAL_APPS = [
Expand Down Expand Up @@ -266,8 +267,7 @@
"rest_framework.authentication.BasicAuthentication",
),
"DEFAULT_PERMISSION_CLASSES": (
"rest_framework.permissions.IsAdminUser",
"tmh_registry.users.api.permissions.IsMedicalPersonnel"
"tmh_registry.users.api.permissions.IsMedicalPersonnel",
),
'EXCEPTION_HANDLER': 'tmh_registry.common.error_handling.error_handler',
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
Expand Down
10 changes: 0 additions & 10 deletions config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1"] # nosec

# CACHES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "",
}
}

# EMAIL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
Expand Down
3 changes: 1 addition & 2 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@
"rest_framework.authentication.TokenAuthentication",
),
"DEFAULT_PERMISSION_CLASSES": (
"rest_framework.permissions.IsAdminUser",
"tmh_registry.users.api.permissions.IsMedicalPersonnel"
"tmh_registry.users.api.permissions.IsMedicalPersonnel",
),
'EXCEPTION_HANDLER': 'tmh_registry.common.error_handling.error_handler',
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
Expand Down
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ django-cors-headers==3.7.0 # https://github.com/adamchainz/django-cors-headers
django-csp==3.7 # https://github.com/mozilla/django-csp
whitenoise==5.2.0 # https://github.com/evansd/whitenoise
django-filter==2.4.0
django-import-export

# Django REST Framework
djangorestframework==3.12.2 # https://github.com/encode/django-rest-framework
Expand Down
34 changes: 28 additions & 6 deletions tmh_registry/registry/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from django.contrib import admin
from import_export.admin import ExportMixin
from import_export import resources
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User


from tmh_registry.registry.models import (
Episode,
Expand All @@ -7,29 +12,46 @@
PatientHospitalMapping, Discharge, FollowUp,
)


@admin.register(Discharge)
class DischargeAdmin(admin.ModelAdmin):
class DischargeAdmin(ExportMixin, admin.ModelAdmin):
model = Discharge

@admin.register(FollowUp)
class FollowUpAdmin(admin.ModelAdmin):
class FollowUpAdmin(ExportMixin, admin.ModelAdmin):
model = FollowUp

@admin.register(Hospital)
class HospitalAdmin(admin.ModelAdmin):
class HospitalAdmin(ExportMixin, admin.ModelAdmin):
model = Hospital


@admin.register(Patient)
class PatientAdmin(admin.ModelAdmin):
class PatientAdmin(ExportMixin, admin.ModelAdmin):
model = Patient


@admin.register(PatientHospitalMapping)
class PatientHospitalMappingAdmin(admin.ModelAdmin):
class PatientHospitalMappingAdmin(ExportMixin, admin.ModelAdmin):
model = PatientHospitalMapping


@admin.register(Episode)
class EpisodeAdmin(admin.ModelAdmin):
class EpisodeAdmin(ExportMixin, admin.ModelAdmin):
model = Episode


"""
To allow CSV export on User model
"""
class UserResource(resources.ModelResource):
class Meta:
model = User
fields = ('first_name', 'last_name', 'email')

class UserAdmin(ExportMixin, UserAdmin):
resource_class = UserResource
pass

admin.site.unregister(User)
admin.site.register(User, UserAdmin)
4 changes: 3 additions & 1 deletion tmh_registry/users/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.contrib import admin
from import_export.admin import ExportMixin


from tmh_registry.users.models import MedicalPersonnel


@admin.register(MedicalPersonnel)
class MedicalPersonnelAdmin(admin.ModelAdmin):
class MedicalPersonnelAdmin(ExportMixin ,admin.ModelAdmin):
model = MedicalPersonnel

0 comments on commit 2d55d55

Please sign in to comment.