Skip to content

Commit

Permalink
Merge pull request #686 from Amsterdam/improvement/admin-interface
Browse files Browse the repository at this point in the history
Updated admin interface
  • Loading branch information
remyvdwereld authored Jun 19, 2024
2 parents f93e9f3 + defa817 commit 2e299ad
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 4 deletions.
44 changes: 44 additions & 0 deletions app/apps/itinerary/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from apps.itinerary.serializers import ItinerarySerializer
from django.contrib import admin
from django.http import JsonResponse
from django.utils import timezone
from datetime import timedelta


class PostalCodeSettingsInline(admin.StackedInline):
Expand Down Expand Up @@ -38,13 +40,51 @@ class ItineraryItemInline(admin.StackedInline):
extra = 0


class CreatedAtFilter(admin.SimpleListFilter):
title = 'created_at'
parameter_name = 'created_at'

def lookups(self, request, model_admin):
return (
('today', 'Today'),
('past_7_days', 'Past 7 days'),
('this_month', 'This month'),
('longer_than_a_month', 'Longer than a month ago'),
)

def queryset(self, request, queryset):
if self.value() == 'today':
today_start = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)
today_end = today_start + timedelta(days=1)
return queryset.filter(created_at__range=(today_start, today_end))

elif self.value() == 'past_7_days':
past_7_days_start = timezone.now() - timedelta(days=7)
return queryset.filter(created_at__gte=past_7_days_start)

elif self.value() == 'this_month':
first_day_of_month = timezone.now().replace(day=1, hour=0, minute=0, second=0, microsecond=0)
next_month = first_day_of_month.replace(month=first_day_of_month.month + 1)
return queryset.filter(created_at__range=(first_day_of_month, next_month))

elif self.value() == 'longer_than_a_month':
one_month_ago = timezone.now() - timedelta(days=30)
return queryset.filter(created_at__lt=one_month_ago)

return queryset


@admin.register(Itinerary)
class ItineraryAdmin(admin.ModelAdmin):
list_display = (
"__str__",
"created_at",
"start_case",
)
search_fields = ["team_members__user__email"]
list_filter = (
CreatedAtFilter,
)

inlines = [
ItineraryTeamMemberInline,
Expand Down Expand Up @@ -76,3 +116,7 @@ class ItineraryItemAdmin(admin.ModelAdmin):
"position",
"external_state_id",
)
list_display = (
"case", "itinerary",
)
search_fields = ["case__case_id"]
42 changes: 41 additions & 1 deletion app/apps/visits/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,51 @@
VisitMetaData,
)
from django.contrib import admin
from django.utils import timezone
from datetime import timedelta


class StartTimeFilter(admin.SimpleListFilter):
title = 'start_time'
parameter_name = 'start_time'

def lookups(self, request, model_admin):
return (
('today', 'Today'),
('past_7_days', 'Past 7 days'),
('this_month', 'This month'),
('longer_than_a_month', 'Longer than a month ago'),
)

def queryset(self, request, queryset):
if self.value() == 'today':
today_start = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)
today_end = today_start + timedelta(days=1)
return queryset.filter(start_time__range=(today_start, today_end))

elif self.value() == 'past_7_days':
past_7_days_start = timezone.now() - timedelta(days=7)
return queryset.filter(start_time__gte=past_7_days_start)

elif self.value() == 'this_month':
first_day_of_month = timezone.now().replace(day=1, hour=0, minute=0, second=0, microsecond=0)
next_month = first_day_of_month.replace(month=first_day_of_month.month + 1)
return queryset.filter(start_time__range=(first_day_of_month, next_month))

elif self.value() == 'longer_than_a_month':
one_month_ago = timezone.now() - timedelta(days=30)
return queryset.filter(start_time__lt=one_month_ago)

return queryset

@admin.register(Visit)
class VisitAdmin(admin.ModelAdmin):
list_display = ("id", "author", "start_time", "case_id")
list_display = ("id", "case_id", "author", "start_time", "completed", "situation", )
search_fields = ("case_id__case_id",)
list_filter = (
StartTimeFilter,
"completed"
)


@admin.register(VisitMetaData)
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.5"

services:
api:
hostname: api
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ docker-compose -f docker-compose.local.yml up
## Importing fixtures dump
The Django project needs some configuration in order to run locally. It's possible to add these manually, but the quickest way is importing using fixtures from the acceptance environment. You can download these at: https://acc.api.top.amsterdam.nl/admin/planner/ by clicking on "DOWNLOAD JSON FIXTURE". You'll need to be logged in using an admin account first to access this url.

Move the json into the app directory on the root of your project, and run the following command
Move the json into the `app` directory on the root of your project, and run the following command

```bash
docker-compose run --rm api python manage.py loaddata <name of fixture>
Expand Down

0 comments on commit 2e299ad

Please sign in to comment.