mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 02:24:26 +00:00
Add fetch function for DSI
This commit is contained in:
parent
9cb88a878d
commit
8c9f02a142
@ -231,6 +231,11 @@ class Mailing(models.Model):
|
|||||||
club = models.ForeignKey(Club, verbose_name=_('Club'), related_name="mailings", null=False, blank=False)
|
club = models.ForeignKey(Club, verbose_name=_('Club'), related_name="mailings", null=False, blank=False)
|
||||||
email = models.EmailField(_('Email address'), unique=True)
|
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):
|
def is_owned_by(self, user):
|
||||||
return user.is_in_group(self) or user.is_root or user.is_board_member
|
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()
|
sub.delete()
|
||||||
super(Mailing, self).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):
|
def __str__(self):
|
||||||
return "%s - %s" % (self.club, self.email)
|
return "%s - %s" % (self.club, self.email)
|
||||||
|
|
||||||
@ -270,6 +284,9 @@ class MailingSubscription(models.Model):
|
|||||||
def can_be_edited_by(self, user):
|
def can_be_edited_by(self, user):
|
||||||
return self.is_owned_by(user) or (user is not None and user.id == self.user.id)
|
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):
|
def __str__(self):
|
||||||
if self.user:
|
if self.user:
|
||||||
user = str(self.user)
|
user = str(self.user)
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
{% for mailing in object_list %}
|
{% for mailing in object_list %}
|
||||||
<h2>{% trans %}Mailing{% endtrans %} {{ mailing.email }}
|
<h2>{% trans %}Mailing{% endtrans %} {{ mailing.email }}
|
||||||
{%- if user.is_owner(mailing) -%}
|
{%- if user.is_owner(mailing) -%}
|
||||||
<a href="{{ url('club:mailing_delete', mailing_id=mailing.id) }}">{% trans %}Delete{% endtrans %}</a>
|
<a href="{{ url('club:mailing_delete', mailing_id=mailing.id) }}"> - {% trans %}Delete{% endtrans %}</a>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</h2>
|
</h2>
|
||||||
<hr>
|
<hr>
|
||||||
|
3
club/templates/club/mailing_output.jinja
Normal file
3
club/templates/club/mailing_output.jinja
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{%- for mailing in object_list -%}
|
||||||
|
{{ mailing.fetch_format() }}
|
||||||
|
{%- endfor -%}
|
@ -44,5 +44,6 @@ urlpatterns = [
|
|||||||
url(r'^(?P<club_id>[0-9]+)/mailing/new/subscription$', ClubMailingView.as_view(action=MailingFormType.MEMBER), name='mailing_subscription_create'),
|
url(r'^(?P<club_id>[0-9]+)/mailing/new/subscription$', ClubMailingView.as_view(action=MailingFormType.MEMBER), name='mailing_subscription_create'),
|
||||||
url(r'^(?P<mailing_id>[0-9]+)/mailing/delete$', MailingDeleteView.as_view(), name='mailing_delete'),
|
url(r'^(?P<mailing_id>[0-9]+)/mailing/delete$', MailingDeleteView.as_view(), name='mailing_delete'),
|
||||||
url(r'^(?P<mailing_subscription_id>[0-9]+)/mailing/delete/subscription$', MailingSubscriptionDeleteView.as_view(), name='mailing_subscription_delete'),
|
url(r'^(?P<mailing_subscription_id>[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<membership_id>[0-9]+)/set_old$', MembershipSetOldView.as_view(), name='membership_set_old'),
|
url(r'^membership/(?P<membership_id>[0-9]+)/set_old$', MembershipSetOldView.as_view(), name='membership_set_old'),
|
||||||
]
|
]
|
||||||
|
@ -44,6 +44,8 @@ from club.models import Club, Membership, Mailing, MailingSubscription
|
|||||||
from sith.settings import SITH_MAXIMUM_FREE_ROLE
|
from sith.settings import SITH_MAXIMUM_FREE_ROLE
|
||||||
from counter.models import Selling, Counter
|
from counter.models import Selling, Counter
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
# Custom forms
|
# Custom forms
|
||||||
|
|
||||||
|
|
||||||
@ -505,3 +507,15 @@ class MailingSubscriptionDeleteView(CanEditMixin, DeleteView):
|
|||||||
|
|
||||||
def get_success_url(self, **kwargs):
|
def get_success_url(self, **kwargs):
|
||||||
return reverse_lazy('club:mailing', kwargs={'club_id': self.club_id})
|
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)
|
||||||
|
@ -586,3 +586,8 @@ if DEBUG:
|
|||||||
SASS_INCLUDE_FOLDERS = [
|
SASS_INCLUDE_FOLDERS = [
|
||||||
'core/static/',
|
'core/static/',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Mailing related settings
|
||||||
|
|
||||||
|
SITH_MAILING_ALLOWED_DOMAIN = 'utbm.fr'
|
||||||
|
SITH_MAILING_FETCH_KEY = 'IloveMails'
|
||||||
|
@ -43,6 +43,7 @@ from django.conf.urls.static import static
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.views.i18n import javascript_catalog
|
from django.views.i18n import javascript_catalog
|
||||||
from ajax_select import urls as ajax_select_urls
|
from ajax_select import urls as ajax_select_urls
|
||||||
|
from club.views import MailingFetchView
|
||||||
|
|
||||||
js_info_dict = {
|
js_info_dict = {
|
||||||
'packages': ('sith',),
|
'packages': ('sith',),
|
||||||
@ -72,6 +73,8 @@ urlpatterns = [
|
|||||||
url(r'^ajax_select/', include(ajax_select_urls)),
|
url(r'^ajax_select/', include(ajax_select_urls)),
|
||||||
url(r'^i18n/', include('django.conf.urls.i18n')),
|
url(r'^i18n/', include('django.conf.urls.i18n')),
|
||||||
url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'),
|
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:
|
if settings.DEBUG:
|
||||||
|
Loading…
Reference in New Issue
Block a user