Skip to content

Commit

Permalink
Merge pull request #689 from FJNR-inc/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
RignonNoel authored Sep 17, 2020
2 parents c21242b + f852b10 commit 3f0a778
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
77 changes: 75 additions & 2 deletions retirement/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from admin_auto_filters.filters import AutocompleteFilter
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.utils.translation import ugettext_lazy as _
from import_export.admin import ExportActionModelAdmin
from modeltranslation.admin import TranslationAdmin
Expand Down Expand Up @@ -30,6 +31,8 @@
WaitQueueResource
)

User = get_user_model()


class RetreatFilter(AutocompleteFilter):
title = 'Retreat'
Expand All @@ -52,6 +55,34 @@ class PictureAdminInline(admin.TabularInline):
readonly_fields = ('picture_tag', )


class ReservationUserFilter(AutocompleteFilter):
title = 'User'
field_name = 'user'
rel_model = Reservation

@property
def parameter_name(self):
return "reservation__user"

@parameter_name.setter
def parameter_name(self, value):
pass


class ReservationRetreatFilter(AutocompleteFilter):
title = 'Retreat'
field_name = 'retreat'
rel_model = Reservation

@property
def parameter_name(self):
return "reservation__retreat"

@parameter_name.setter
def parameter_name(self, value):
pass


def make_reservation_refundable(self, request, queryset):

Reservation.objects.filter(
Expand Down Expand Up @@ -268,13 +299,55 @@ class RetreatDateAdmin(admin.ModelAdmin):
'start_time',
'end_time',
)
list_filter = (
RetreatFilter,
)


class AutomaticEmailLogAdmin(admin.ModelAdmin):
list_display = (
'id',
'user',
'retreat',
'template_id',
'sent_at',
)
list_filter = (
ReservationUserFilter,
ReservationRetreatFilter,
'sent_at'
)
search_fields = ['reservation__user__email', 'email__template_id',
'reservation__user__first_name',
'reservation__user__last_name']

def lookup_allowed(self, lookup, value):
if lookup == "reservation__user":
return True
if lookup == "reservation__retreat":
return True
return super().lookup_allowed(lookup, value)


class AutomaticEmailAdmin(admin.ModelAdmin):
list_display = (
'id',
'retreat_type',
'time_base',
'minutes_delta',
'template_id',
)
list_filter = (
'retreat_type',
'template_id',
)


admin.site.register(Retreat, RetreatAdmin)
admin.site.register(RetreatType)
admin.site.register(RetreatDate, RetreatDateAdmin)
admin.site.register(AutomaticEmail)
admin.site.register(AutomaticEmailLog)
admin.site.register(AutomaticEmail, AutomaticEmailAdmin)
admin.site.register(AutomaticEmailLog, AutomaticEmailLogAdmin)
admin.site.register(Picture, PictureAdmin)
admin.site.register(Reservation, ReservationAdmin)
admin.site.register(WaitQueue, WaitQueueAdmin)
Expand Down
12 changes: 12 additions & 0 deletions retirement/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,18 @@ class AutomaticEmailLog(models.Model):
auto_now_add=True,
)

@property
def template_id(self):
return self.email.template_id

@property
def retreat(self):
return self.reservation.retreat

@property
def user(self):
return self.reservation.user

class Meta:
verbose_name = _("Automatic email log")
verbose_name_plural = _("Automatic email logs")
Expand Down

0 comments on commit 3f0a778

Please sign in to comment.