aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2017-09-09 14:56:17 +0200
committerAlban Gruin2017-09-09 14:56:17 +0200
commitc7fce37ad4c8dee76f5d58eafefd0c73a03ea00c (patch)
treef86af8322495101ce11e187f8145f8f4d9519236
parent9aaa19a62b36e1b0981233785e150f50449c78e3 (diff)
Suppression de l’envoi des mails
-rw-r--r--admin.py8
-rw-r--r--forms.py20
-rw-r--r--management/commands/sendmails.py67
-rw-r--r--models.py24
-rw-r--r--templates/mail/mail_confirm.txt9
-rw-r--r--templates/mail/mail_footer.txt2
-rw-r--r--templates/mail/mail_timetable.txt7
-rw-r--r--templates/mail/mail_unsubscribed.txt2
-rw-r--r--templates/subscribe.html15
-rw-r--r--templates/timetable.html5
-rw-r--r--urls.py3
-rw-r--r--views.py51
12 files changed, 4 insertions, 209 deletions
diff --git a/admin.py b/admin.py
index 66da316..2fc0e78 100644
--- a/admin.py
+++ b/admin.py
@@ -14,7 +14,7 @@
# along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>.
from django.contrib import admin
-from .models import Timetable, LastUpdate, Group, Subscription, Room, Course, Year
+from .models import Timetable, LastUpdate, Group, Room, Course, Year
@admin.register(Year)
@@ -46,12 +46,6 @@ class GroupAdmin(admin.ModelAdmin):
readonly_fields = ("celcat_name", "mention", "subgroup", "td", "tp",)
-@admin.register(Subscription)
-class SubscriptionAdmin(admin.ModelAdmin):
- list_display = ("email", "group", "active",)
- readonly_fields = ("token",)
-
-
@admin.register(Room)
class RoomAdmin(admin.ModelAdmin):
pass
diff --git a/forms.py b/forms.py
deleted file mode 100644
index edf584b..0000000
--- a/forms.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright (C) 2017 Alban Gruin
-#
-# celcatsanitizer is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# celcatsanitizer is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>.
-
-from django import forms
-
-
-class SubscribeForm(forms.Form):
- email = forms.EmailField(label="Adresse email")
diff --git a/management/commands/sendmails.py b/management/commands/sendmails.py
deleted file mode 100644
index 3c0fab0..0000000
--- a/management/commands/sendmails.py
+++ /dev/null
@@ -1,67 +0,0 @@
-# Copyright (C) 2017 Alban Gruin
-#
-# celcatsanitizer is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# celcatsanitizer is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>.
-
-from django.core.management.base import BaseCommand
-from django.core.mail import send_mass_mail
-from django.utils import translation
-from django.template import Context, loader
-from django.conf import settings
-
-from edt.models import Course, Subscription
-from edt.utils import get_current_or_next_week, get_week, group_courses
-
-
-class Command(BaseCommand):
- help = "Sends emails to subscribed users"
-
- def add_arguments(self, parser):
- parser.add_argument("--test", help="Print the content of mails instead of sending them", action="store_true")
-
- def handle(self, *args, **options):
- translation.activate(settings.LANGUAGE_CODE)
-
- year, week = get_current_or_next_week()
- start, end = get_week(year, week)
-
- subscriptions = Subscription.objects.filter(active=True)
- content = {}
- mails = []
-
- footer = loader.get_template("mail/mail_footer.txt")
- timetable = loader.get_template("mail/mail_timetable.txt")
-
- print("Generating messages...")
- for subscription in subscriptions:
- if subscription.group.id not in content:
- courses = Course.objects.get_courses_for_group(subscription.group, begin__gte=start, begin__lt=end)
-
- grouped_courses = group_courses(courses)
- context = Context({"courses": grouped_courses, "group": subscription.group, "week": week})
- content[subscription.group.id] = timetable.render(context)
-
- if options["test"]:
- print(subscription.group)
- print(content[subscription.group.id])
-
- if not options["test"]:
- context = Context({"admins": settings.ADMINS, "token": subscription.token, "domain": settings.DEFAULT_DOMAIN})
- mail_content = content[subscription.group.id] + footer.render(context)
- mails.append(("{0} - {1} - Semaine {2}".format(subscription.group.timetable, subscription.group, week), mail_content, settings.DEFAULT_FROM_EMAIL, [subscription.email],))
-
- if not options["test"]:
- print("Sending mails...")
- send_mass_mail(mails)
-
- self.stdout.write(self.style.SUCCESS("Done."))
diff --git a/models.py b/models.py
index 8fbd1da..6bb9733 100644
--- a/models.py
+++ b/models.py
@@ -20,9 +20,6 @@ from django.utils.text import slugify
from .utils import parse_group
-import hashlib
-import os
-
class Year(models.Model):
name = models.CharField(max_length=16, verbose_name="année")
@@ -118,27 +115,6 @@ class Group(models.Model):
verbose_name_plural = "groupes"
-class Subscription(models.Model):
- email = models.EmailField(verbose_name="adresse")
- group = models.ForeignKey(Group, on_delete=models.CASCADE, verbose_name="groupe")
- active = models.BooleanField(verbose_name="activé", default=False, db_index=True)
- token = models.CharField(max_length=64, unique=True, default="")
-
- def __str__(self):
- return "{0} - {1}".format(self.email, self.group)
-
- def save(self, *args, **kwargs):
- if self.token == "":
- self.token = hashlib.sha1(os.urandom(128)).hexdigest()
- super(Subscription, self).save(*args, **kwargs)
-
-
- class Meta:
- unique_together = ("email", "group",)
- verbose_name = "abonnement"
- verbose_name_plural = "abonnements"
-
-
class Room(models.Model):
name = models.CharField(max_length=255, unique=True, verbose_name="nom")
diff --git a/templates/mail/mail_confirm.txt b/templates/mail/mail_confirm.txt
deleted file mode 100644
index 14fe33c..0000000
--- a/templates/mail/mail_confirm.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-Vous avez été abonné à l’emploi du temps {{ group.timetable }} - {{ group }}
-
-Pour valider l’abonnement, suivez ce lien : {{ domain }}{% url "confirm" token %}
-
-Si vous pensez que vous avez été abonné par erreur, suivez ce lien : {{ domain }}{% url "cancel" token %}
-
-Vous ne recevrez aucun mail tant que vous n'avez pas validé votre abonnement.
-
-{% include "mail/mail_footer.txt" %}
diff --git a/templates/mail/mail_footer.txt b/templates/mail/mail_footer.txt
deleted file mode 100644
index b39f738..0000000
--- a/templates/mail/mail_footer.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-Pour vous désinscrire de cet emploi du temps, suivez ce lien : {{ domain }}{% url "cancel" token %}
-Pour contacter l’administrateur du service, envoyez un mail à cette adresse : {{ admins|first|last }}
diff --git a/templates/mail/mail_timetable.txt b/templates/mail/mail_timetable.txt
deleted file mode 100644
index 524611e..0000000
--- a/templates/mail/mail_timetable.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-{% load rooms %}{% autoescape off %}{% for day in courses %}{% filter title %}{{ day.0.begin|date:"l j F o" }}{% endfilter %} - de {{ day.0.begin|date:"H:i" }} à {% with day|last as last %}{{ last.end|date:"H:i" }}{% endwith %}
-{% for course in day %} * {{ course }} ({{ course.type }}), de {{ course.begin|date:"H:i" }} à {{ course.end|date:"H:i" }}{% if course.rooms.all|length > 0 %}
- {{ course.rooms.all|format_rooms }}{% endif %}{% if course.notes != "" and course.notes is not None %}
- Remarques : {{ course.notes }}{% endif %}
-
-{% endfor %}{% empty %}Aucun cours pour le groupe {{ group }} pendant la semaine {{ week }}.
-{% endfor %}{% endautoescape %}
diff --git a/templates/mail/mail_unsubscribed.txt b/templates/mail/mail_unsubscribed.txt
deleted file mode 100644
index 8d75ccf..0000000
--- a/templates/mail/mail_unsubscribed.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-Vous avez été désabonné de l’emploi du temps {{ group.timetable.name }} - {{ group.name }}
-Notez que si vous vous êtes abonné à un autre emploi du temps, vous recevrez toujours les mails de ceux-ci.
diff --git a/templates/subscribe.html b/templates/subscribe.html
deleted file mode 100644
index 08b27a8..0000000
--- a/templates/subscribe.html
+++ /dev/null
@@ -1,15 +0,0 @@
-{% extends "index.html" %}
-
-{% block title %}S’abonner à {{ group.timetable }} &ndash; {{ group }}{% endblock %}
-
-{% block body %}
- <h2>S'abonner à {{ group.timetable }} &ndash; {{ group }}</h2>
- <form action="{% url "subscribe" group.timetable.year.slug group.timetable.slug group.slug year week %}" method="post">
- {% csrf_token %}
- {{ form }}
- <input type="submit" value="S'abonner" />
- </form>
- <p>Après l’abonnement, vous allez recevoir un mail avec un lien de confirmation. Aucun autre mail ne vous sera envoyé si vous n'avez pas validé votre abonnement.<br />
- Vous pouvez vous désabonner à tout moment à l’aide d'un lien contenu dans tout les mails que nous vous enverrons.<br />
- Nous ne partageons votre adresse à qui que se soit. Lorsque vous vous désabonnez, votre adresse est effacée de nos serveurs.</p>
-{% endblock %}
diff --git a/templates/timetable.html b/templates/timetable.html
index 5428942..f4b8719 100644
--- a/templates/timetable.html
+++ b/templates/timetable.html
@@ -6,7 +6,4 @@
<h2>{{ group.timetable }} &ndash; {{ group }} &ndash; Semaine {{ week }}</h2>
<p>Dernière mise à jour le {{ last_update|date:"l j F o" }} à {{ last_update|date:"H:i" }}</p>
{% include "timetable_common.html" %}
- <p class="subscribe">
- <a href="{% url "ics" group.timetable.year.slug group.timetable.slug group.slug %}">ICS</a> &ndash; <a href="{% url "atom" group.timetable.year.slug group.timetable.slug group.slug %}">Atom</a><br />
- <a href="{% url "subscribe" group.timetable.year.slug group.timetable.slug group.slug year week %}">S’abonner à cet emploi du temps</a>
- </p>{% endblock %}
+ <p class="subscribe"><a href="{% url "ics" group.timetable.year.slug group.timetable.slug group.slug %}">ICS</a> &ndash; <a href="{% url "atom" group.timetable.year.slug group.timetable.slug group.slug %}">Atom</a><br /></p>{% endblock %}
diff --git a/urls.py b/urls.py
index 7f313c1..aaf9b67 100644
--- a/urls.py
+++ b/urls.py
@@ -24,7 +24,4 @@ urlpatterns = [
url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/calendar.ics$", feeds.IcalFeed(), name="ics"),
url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/feed.atom$", feeds.AtomFeed(), name="atom"),
url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/(?P<year>[0-9]{4})/(?P<week>[0-4]?[0-9]|5[0-3])/$", views.timetable, name="timetable"),
- url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/(?P<year>[0-9]{4})/(?P<week>[0-4]?[0-9]|5[0-3])/subscribe$", views.subscribe, name="subscribe"),
- url(r"^subscriptions/confirm/(?P<token>[0-9a-f]{40})$", views.confirm_subscription, name="confirm"),
- url(r"^subscriptions/cancel/(?P<token>[0-9a-f]{40})$", views.cancel_subscription, name="cancel"),
]
diff --git a/views.py b/views.py
index 2101a21..f445725 100644
--- a/views.py
+++ b/views.py
@@ -13,13 +13,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>.
-from django.shortcuts import get_object_or_404, redirect, render
-from django.core.mail import send_mail
-from django.conf import settings
-from django.template import Context, loader
+from django.shortcuts import get_object_or_404, render
-from .forms import SubscribeForm
-from .models import Timetable, LastUpdate, Group, Subscription, Course, Year
+from .models import Timetable, LastUpdate, Group, Course, Year
from .utils import get_current_week, get_week, group_courses
def index(request):
@@ -69,46 +65,3 @@ def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=No
grouped_courses = group_courses(courses)
return render(request, "timetable.html", {"group": group, "courses": grouped_courses, "last_update": last_update.date, "year": year, "week": int(week)})
-
-def subscribe(request, year_slug, timetable_slug, group_slug, year, week):
- group = get_object_or_404(Group, slug=group_slug, timetable__slug=timetable_slug, timetable__year__slug=year_slug)
-
- if request.method == "POST":
- form = SubscribeForm(request.POST)
- if form.is_valid():
- if not Subscription.objects.filter(email=request.POST["email"], group=group).exists():
- subscription = Subscription(email=request.POST["email"], group=group)
- subscription.save()
-
- template = loader.get_template("mail/mail_confirm.txt")
- context = Context({"group": group, "admins": settings.ADMINS, "token": subscription.token, "domain": settings.DEFAULT_DOMAIN})
- send_mail("Confirmation de l’abonnemenent", template.render(context), settings.DEFAULT_FROM_EMAIL, [request.POST["email"]])
-
- return redirect("timetable", year_slug=year_slug, timetable_slug=timetable_slug, group_slug=group_slug, year=year, week=int(week))
- else:
- form = SubscribeForm()
-
- return render(request, "subscribe.html", {"year": year, "week": week, "group": group, "form": form})
-
-def confirm_subscription(request, token):
- subscription = Subscription.objects.filter(token=token).first()
- year, week = get_current_week()
-
- if subscription is not None and not subscription.active:
- subscription.active = True
- subscription.save()
-
- return redirect("timetable", timetable_slug=subscription.group.timetable.slug, group_slug=subscription.group.slug, year=year, week=week)
-
-def cancel_subscription(request, token):
- subscription = Subscription.objects.filter(token=token).first()
-
- if subscription is not None:
- group = subscription.group
- subscription.delete()
-
- template = loader.get_template("mail/mail_unsubscribed.txt")
- context = Context({"group": group})
- send_mail("Confirmation de la désinscription", template.render(context), settings.DEFAULT_FROM_EMAIL, [subscription.email])
-
- return redirect("index")