From 8c9f02a142b6272724dc9d8b58c714c612a15223 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Thu, 17 Aug 2017 21:46:13 +0200 Subject: [PATCH] Add fetch function for DSI --- club/models.py | 17 +++++++++++++++++ club/templates/club/mailing.jinja | 2 +- club/templates/club/mailing_output.jinja | 3 +++ club/urls.py | 1 + club/views.py | 14 ++++++++++++++ sith/settings.py | 5 +++++ sith/urls.py | 3 +++ 7 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 club/templates/club/mailing_output.jinja diff --git a/club/models.py b/club/models.py index 9484e4e2..90df31a3 100644 --- a/club/models.py +++ b/club/models.py @@ -231,6 +231,11 @@ class Mailing(models.Model): club = models.ForeignKey(Club, verbose_name=_('Club'), related_name="mailings", null=False, blank=False) email = models.EmailField(_('Email address'), unique=True) + def clean(self): + if '@' + settings.SITH_MAILING_ALLOWED_DOMAIN not in self.email: + raise ValidationError(_('Unothorized mailing domain')) + super(Mailing, self).clean() + def is_owned_by(self, user): return user.is_in_group(self) or user.is_root or user.is_board_member @@ -242,6 +247,15 @@ class Mailing(models.Model): sub.delete() super(Mailing, self).delete() + def base_mail(self): + return self.email.split('@')[0] + + def fetch_format(self): + resp = self.base_mail() + ': ' + for sub in self.subscriptions.all(): + resp += sub.fetch_format() + return resp + def __str__(self): return "%s - %s" % (self.club, self.email) @@ -270,6 +284,9 @@ class MailingSubscription(models.Model): def can_be_edited_by(self, user): return self.is_owned_by(user) or (user is not None and user.id == self.user.id) + def fetch_format(self): + return self.email + ' ' + def __str__(self): if self.user: user = str(self.user) diff --git a/club/templates/club/mailing.jinja b/club/templates/club/mailing.jinja index 47f11884..66e57864 100644 --- a/club/templates/club/mailing.jinja +++ b/club/templates/club/mailing.jinja @@ -10,7 +10,7 @@ {% for mailing in object_list %}

{% trans %}Mailing{% endtrans %} {{ mailing.email }} {%- if user.is_owner(mailing) -%} - {% trans %}Delete{% endtrans %} + - {% trans %}Delete{% endtrans %} {%- endif -%}


diff --git a/club/templates/club/mailing_output.jinja b/club/templates/club/mailing_output.jinja new file mode 100644 index 00000000..8a7133a7 --- /dev/null +++ b/club/templates/club/mailing_output.jinja @@ -0,0 +1,3 @@ +{%- for mailing in object_list -%} +{{ mailing.fetch_format() }} +{%- endfor -%} \ No newline at end of file diff --git a/club/urls.py b/club/urls.py index 42074a5c..bfd178a0 100644 --- a/club/urls.py +++ b/club/urls.py @@ -44,5 +44,6 @@ urlpatterns = [ url(r'^(?P[0-9]+)/mailing/new/subscription$', ClubMailingView.as_view(action=MailingFormType.MEMBER), name='mailing_subscription_create'), url(r'^(?P[0-9]+)/mailing/delete$', MailingDeleteView.as_view(), name='mailing_delete'), url(r'^(?P[0-9]+)/mailing/delete/subscription$', MailingSubscriptionDeleteView.as_view(), name='mailing_subscription_delete'), + url(r'^mailing/fetch$', MailingFetchView.as_view(), name='mailing_fetch'), url(r'^membership/(?P[0-9]+)/set_old$', MembershipSetOldView.as_view(), name='membership_set_old'), ] diff --git a/club/views.py b/club/views.py index 6a3b35a0..a283279c 100644 --- a/club/views.py +++ b/club/views.py @@ -44,6 +44,8 @@ from club.models import Club, Membership, Mailing, MailingSubscription from sith.settings import SITH_MAXIMUM_FREE_ROLE from counter.models import Selling, Counter +from django.conf import settings + # Custom forms @@ -505,3 +507,15 @@ class MailingSubscriptionDeleteView(CanEditMixin, DeleteView): def get_success_url(self, **kwargs): return reverse_lazy('club:mailing', kwargs={'club_id': self.club_id}) + + +class MailingFetchView(ListView): + + model = Mailing + template_name = 'club/mailing_output.jinja' + + def dispatch(self, request, *args, **kwargs): + key = request.GET.get('key', '') + if key != settings.SITH_MAILING_FETCH_KEY: + raise PermissionDenied + return super(MailingFetchView, self).dispatch(request, *args, **kwargs) diff --git a/sith/settings.py b/sith/settings.py index ff08d42d..3f492281 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -586,3 +586,8 @@ if DEBUG: SASS_INCLUDE_FOLDERS = [ 'core/static/', ] + +# Mailing related settings + +SITH_MAILING_ALLOWED_DOMAIN = 'utbm.fr' +SITH_MAILING_FETCH_KEY = 'IloveMails' diff --git a/sith/urls.py b/sith/urls.py index 2b744c24..e21a53cb 100644 --- a/sith/urls.py +++ b/sith/urls.py @@ -43,6 +43,7 @@ from django.conf.urls.static import static from django.conf import settings from django.views.i18n import javascript_catalog from ajax_select import urls as ajax_select_urls +from club.views import MailingFetchView js_info_dict = { 'packages': ('sith',), @@ -72,6 +73,8 @@ urlpatterns = [ url(r'^ajax_select/', include(ajax_select_urls)), url(r'^i18n/', include('django.conf.urls.i18n')), url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'), + # This url is for legacy use + url(r'^mailing.php$', MailingFetchView.as_view(), name='mailing_fetch_legacy'), ] if settings.DEBUG: