3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-25 04:43:11 +00:00
coope/users/admin.py

61 lines
2.3 KiB
Python
Raw Normal View History

2018-08-31 12:46:35 +00:00
from django.contrib import admin
2018-11-22 21:52:15 +00:00
from django.contrib.auth.models import Permission
2018-11-27 08:07:12 +00:00
from simple_history.admin import SimpleHistoryAdmin
2019-02-27 07:59:41 +00:00
from django.db.models import F
from .models import School, Profile, CotisationHistory, WhiteListHistory
class CotisationHistoryAdmin(SimpleHistoryAdmin):
2019-02-28 12:18:41 +00:00
"""
The admin class for :class:`Consumptions <users.models.CotisationHistory>`.
"""
2019-02-27 07:59:41 +00:00
list_display = ('user', 'amount', 'duration', 'paymentDate', 'endDate', 'paymentMethod')
ordering = ('user', 'amount', 'duration', 'paymentDate', 'endDate')
2019-06-23 09:02:37 +00:00
search_fields = ('user__username', 'user__first_name', 'user__last_name')
2019-02-27 07:59:41 +00:00
list_filter = ('paymentMethod', )
class BalanceFilter(admin.SimpleListFilter):
2019-02-28 12:18:41 +00:00
"""
A filter which filters according to the sign of the balance
"""
2019-02-27 07:59:41 +00:00
title = 'Solde'
parameter_name = 'solde'
def lookups(self, request, model_admin):
return (
('po', '>0'),
('nu', '=0'),
('ne', '<0'),
)
def queryset(self, request, queryset):
if self.value() == 'po':
return queryset.filter(credit__gt=F('debit'))
elif self.value() == 'nu':
return queryset.filter(credit=F('debit'))
elif self.value() == 'ne':
return queryset.filter(credit__lt=F('debit'))
2018-08-31 12:46:35 +00:00
2018-12-23 20:48:49 +00:00
class ProfileAdmin(SimpleHistoryAdmin):
2019-02-28 12:18:41 +00:00
"""
The admin class for :class:`Consumptions <users.models.Profile>`.
"""
2019-02-27 07:59:41 +00:00
list_display = ('user', 'credit', 'debit', 'balance', 'school', 'cotisationEnd', 'is_adherent')
ordering = ('user', '-credit', '-debit')
2019-06-23 09:02:37 +00:00
search_fields = ('user__username', 'user__first_name', 'user__last_name')
2019-02-27 07:59:41 +00:00
list_filter = ('school', BalanceFilter)
class WhiteListHistoryAdmin(SimpleHistoryAdmin):
2019-02-28 12:18:41 +00:00
"""
The admin class for :class:`Consumptions <users.models.WhiteListHistory>`.
"""
2019-06-23 09:06:39 +00:00
list_display = ('user', 'paymentDate', 'endDate', 'duration', 'reason')
2019-02-27 07:59:41 +00:00
ordering = ('user', 'duration', 'paymentDate', 'endDate')
2019-06-23 09:06:39 +00:00
search_fields = ('user__username', 'user__first_name', 'user__last_name', 'reason')
2018-12-23 20:48:49 +00:00
2018-11-27 08:07:12 +00:00
admin.site.register(Permission, SimpleHistoryAdmin)
admin.site.register(School, SimpleHistoryAdmin)
2019-02-27 07:59:41 +00:00
admin.site.register(WhiteListHistory, WhiteListHistoryAdmin)
2018-12-23 20:48:49 +00:00
admin.site.register(Profile, ProfileAdmin)
2019-02-27 07:59:41 +00:00
admin.site.register(CotisationHistory, CotisationHistoryAdmin)