mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-31 04:12:15 +00:00
FIX: Minor code improvements
This commit is contained in:
@@ -55,8 +55,13 @@ class Profile(AbstractUser):
|
|||||||
def latest_events(self):
|
def latest_events(self):
|
||||||
return self.event_mic.order_by('-start_date').select_related('person', 'organisation', 'venue', 'mic')
|
return self.event_mic.order_by('-start_date').select_related('person', 'organisation', 'venue', 'mic')
|
||||||
|
|
||||||
def users_awaiting_approval_count(self):
|
@classmethod
|
||||||
return self.filter(models.Q(is_approved=False)).count()
|
def admins(cls):
|
||||||
|
return Profile.objects.filter(email__in=[y for x in settings.ADMINS for y in x])
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def users_awaiting_approval_count(cls):
|
||||||
|
return Profile.objects.filter(models.Q(is_approved=False)).count()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from django.conf import settings
|
|||||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||||
from django.core.mail import EmailMessage, EmailMultiAlternatives
|
from django.core.mail import EmailMessage, EmailMultiAlternatives
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from registration.signals import user_activated
|
from registration.signals import user_activated
|
||||||
from premailer import Premailer
|
from premailer import Premailer
|
||||||
@@ -109,13 +110,13 @@ post_save.connect(on_revision_commit, sender=models.EventAuthorisation)
|
|||||||
|
|
||||||
def send_admin_awaiting_approval_email(user, request, **kwargs):
|
def send_admin_awaiting_approval_email(user, request, **kwargs):
|
||||||
# Bit more controlled than just emailing all superusers
|
# Bit more controlled than just emailing all superusers
|
||||||
for admin in models.Profile.objects.filter(email__in=[y for x in settings.ADMINS for y in x]):
|
for admin in models.Profile.admins():
|
||||||
# Check we've ever emailed them before and if so, if cooldown has passed.
|
# Check we've ever emailed them before and if so, if cooldown has passed.
|
||||||
if admin.last_emailed is None or admin.last_emailed + settings.EMAIL_COOLDOWN <= timezone.now():
|
if admin.last_emailed is None or admin.last_emailed + settings.EMAIL_COOLDOWN <= timezone.now():
|
||||||
context = {
|
context = {
|
||||||
'request': request,
|
'request': request,
|
||||||
'link_suffix': '/admin/RIGS/profile/?is_approved__exact=0',
|
'link_suffix': reverse("admin:RIGS_profile_changelist") + '?is_approved__exact=0',
|
||||||
'number_of_users': models.Profile.users_awaiting_approval_count(models.Profile.objects),
|
'number_of_users': models.Profile.users_awaiting_approval_count(),
|
||||||
'to_name': admin.first_name
|
'to_name': admin.first_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user