This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from DemocracyClub/unique-emails
Lower case emails to filter on unique
- Loading branch information
Showing
1 changed file
with
11 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import sys | ||
import time | ||
from django.core.management.base import BaseCommand | ||
from django.db.models import Q | ||
from django.db.models import Q, Func, F | ||
from dc_signup_form.signup_server.models import SignupQueue | ||
from dc_signup_form.signup_server.wrappers import DCSendGridWrapper | ||
|
||
|
@@ -16,15 +16,18 @@ def get_unique_mailing_lists(self): | |
) | ||
|
||
def get_new_users(self, mailing_lists): | ||
return SignupQueue.objects.all().filter( | ||
~Q(email="[email protected]"), | ||
added=False, | ||
mailing_lists=mailing_lists, | ||
).distinct("email") | ||
|
||
return ( | ||
SignupQueue.objects.all() | ||
.filter( | ||
~Q(email="[email protected]"), | ||
added=False, | ||
mailing_lists=mailing_lists, | ||
) | ||
.annotate(email_lower=Func(F("email"), function="lower")) | ||
.distinct("email_lower") | ||
) | ||
|
||
def handle(self, *args, **kwargs): | ||
|
||
# Assume we're going to finish sucessfully. | ||
# If any errors happen, we'll set an error code | ||
exit_code = 0 | ||
|