|
|
|
@ -1,5 +1,6 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
"""Forms for emencia.django.newsletter""" |
|
|
|
"""Forms for emencia.django.newsletter""" |
|
|
|
|
|
|
|
from datetime import datetime, date, timedelta |
|
|
|
from django import forms |
|
|
|
from django import forms |
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
from django.http import Http404 |
|
|
|
from django.http import Http404 |
|
|
|
@ -8,8 +9,7 @@ from django.core.exceptions import ValidationError |
|
|
|
from django.utils import translation |
|
|
|
from django.utils import translation |
|
|
|
from haystack.query import SearchQuerySet |
|
|
|
from haystack.query import SearchQuerySet |
|
|
|
from functions.search_forms import get_by_lang |
|
|
|
from functions.search_forms import get_by_lang |
|
|
|
from emencia.django.newsletter.models import Contact, ContactSettings |
|
|
|
from emencia.django.newsletter.models import Contact, ContactSettings, MailingList, PopupCount |
|
|
|
from emencia.django.newsletter.models import MailingList |
|
|
|
|
|
|
|
from functions.form_check import translit_with_separator as tr |
|
|
|
from functions.form_check import translit_with_separator as tr |
|
|
|
from theme.models import Theme |
|
|
|
from theme.models import Theme |
|
|
|
from country.models import Country, Area |
|
|
|
from country.models import Country, Area |
|
|
|
@ -19,7 +19,7 @@ from city.models import City |
|
|
|
class MailingListSubscriptionForm(forms.ModelForm): |
|
|
|
class MailingListSubscriptionForm(forms.ModelForm): |
|
|
|
"""Form for subscribing to a mailing list""" |
|
|
|
"""Form for subscribing to a mailing list""" |
|
|
|
# Notes : This form will not check the uniquess of |
|
|
|
# Notes : This form will not check the uniquess of |
|
|
|
# the 'email' field, by defining it explictly and setting |
|
|
|
# the 'email' field, by defining it explictly and setting6 |
|
|
|
# it the Meta.exclude list, for allowing registration |
|
|
|
# it the Meta.exclude list, for allowing registration |
|
|
|
# to a mailing list even if the contact already exists. |
|
|
|
# to a mailing list even if the contact already exists. |
|
|
|
# Then the contact is always added to the subscribers field |
|
|
|
# Then the contact is always added to the subscribers field |
|
|
|
@ -94,7 +94,7 @@ class ContactSettingsForm(forms.ModelForm): |
|
|
|
return Theme.objects.none() |
|
|
|
return Theme.objects.none() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from datetime import datetime |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ContactFilterForm(forms.Form): |
|
|
|
class ContactFilterForm(forms.Form): |
|
|
|
email = forms.EmailField( |
|
|
|
email = forms.EmailField( |
|
|
|
@ -335,3 +335,27 @@ class SubscribeSettingsForm(AbstractSubscribeForm): |
|
|
|
|
|
|
|
|
|
|
|
def clean_email(self): |
|
|
|
def clean_email(self): |
|
|
|
return self.cleaned_data['email'] |
|
|
|
return self.cleaned_data['email'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from django.db.models import Sum |
|
|
|
|
|
|
|
class PopupCountFilter(forms.Form): |
|
|
|
|
|
|
|
fr = forms.DateField(required=False) |
|
|
|
|
|
|
|
to = forms.DateField(required=False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def filter(self): |
|
|
|
|
|
|
|
fr = self.cleaned_data.get('fr') |
|
|
|
|
|
|
|
to = self.cleaned_data.get('to') |
|
|
|
|
|
|
|
if not fr and not to: |
|
|
|
|
|
|
|
fr = date.today() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qs = PopupCount.objects.filter(date__gte=fr) |
|
|
|
|
|
|
|
contacts = Contact.objects.filter(creation_date__gte=fr) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if to: |
|
|
|
|
|
|
|
contacts = contacts.filter(creation_date__lte=to+timedelta(days=1)) |
|
|
|
|
|
|
|
qs = qs.filter(date__lte=to) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subscribed = contacts.count() |
|
|
|
|
|
|
|
activated = contacts.filter(activated=True).count() |
|
|
|
|
|
|
|
popups = qs.aggregate(count=Sum('cnt'))['count'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {'subscribed': subscribed, 'activated': activated, 'popups': popups} |