#
import json
from django.contrib import admin
+from django.db.models.functions import Now
+from django.db.models import Q
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
+from django.utils.translation import gettext_lazy as _
from modeltranslation.admin import TranslationAdmin
+from wolnelektury.utils import YesNoFilter
from . import models
return False
+class PayedFilter(YesNoFilter):
+ title = _('payment complete')
+ parameter_name = 'payed'
+ q = ~Q(payed_at=None)
+
+
+class ExpiredFilter(YesNoFilter):
+ title = _('schedule expired')
+ parameter_name = 'expired'
+ q = Q(expires_at__isnull=False, expires_at__lt=Now())
+
+
class ScheduleAdmin(admin.ModelAdmin):
list_display = ['email', 'started_at', 'payed_at', 'expires_at', 'amount', 'monthly', 'yearly', 'is_cancelled']
search_fields = ['email']
- list_filter = ['is_cancelled']
+ list_filter = ['is_cancelled', 'monthly', 'yearly', PayedFilter, ExpiredFilter]
date_hierarchy = 'started_at'
raw_id_fields = ['membership']
inlines = [PayUOrderInline, PayUCardTokenInline]
import re
from django.conf import settings
+from django.contrib import admin
from django.core.cache import cache
from django.core.mail import send_mail
from django.http import HttpResponse
from django.utils.translation import get_language
from django.conf import settings
from django.utils.safestring import mark_safe
-from django.utils.translation import ugettext
+from django.utils.translation import gettext as _
tz = pytz.timezone(settings.TIME_ZONE)
def send_noreply_mail(subject, message, recipient_list, **kwargs):
send_mail(
'[WolneLektury] ' + subject,
- message + "\n\n-- \n" + ugettext('Message sent automatically. Please do not reply.'),
+ message + "\n\n-- \n" + _('Message sent automatically. Please do not reply.'),
'no-reply@wolnelektury.pl', recipient_list, **kwargs)
lc
)
)
+
+
+class YesNoFilter(admin.SimpleListFilter):
+ def lookups(self, request, model_admin):
+ return (
+ ('yes', _('Yes')),
+ ('no', _('No')),
+ )
+
+ def queryset(self, request, queryset):
+ if self.value() == 'yes':
+ return queryset.filter(self.q)
+ elif self.value() == 'no':
+ return queryset.exclude(self.q)