From 2e602019ae2d939789faf38b483ac60f209a9436 Mon Sep 17 00:00:00 2001 From: yomguy Date: Sun, 8 Jul 2012 15:37:39 +0200 Subject: [PATCH] add account init email script --- ...teleforma-reset-all-passwords-with-mail.py | 40 +++++++++++++++++++ teleforma/models.py | 2 +- teleforma/templates/postman/archives.html | 2 +- .../templates/postman/email_user_init.txt | 19 +++++++++ .../postman/email_user_subject_init.txt | 1 + .../teleforma/inc/document_list.html | 10 +---- 6 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 teleforma/management/commands/teleforma-reset-all-passwords-with-mail.py create mode 100644 teleforma/templates/postman/email_user_init.txt create mode 100644 teleforma/templates/postman/email_user_subject_init.txt diff --git a/teleforma/management/commands/teleforma-reset-all-passwords-with-mail.py b/teleforma/management/commands/teleforma-reset-all-passwords-with-mail.py new file mode 100644 index 00000000..431d8273 --- /dev/null +++ b/teleforma/management/commands/teleforma-reset-all-passwords-with-mail.py @@ -0,0 +1,40 @@ +from optparse import make_option +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User +from django.contrib.auth.forms import PasswordResetForm +from django.contrib.auth.tokens import default_token_generator +from django.template.defaultfilters import slugify +from django.template.loader import render_to_string +from telemeta.models import * +from telemeta.util.unaccent import unaccent +from teleforma.models import * +import logging +from postman import * + + +class Command(BaseCommand): + help = "Reset the password for all (active) users " + message_template = 'postman/email_user_init.html' + subject_template = 'postman/email_user_subject_init.html' + + def init_password_email(self, user): + site = Site.objects.get_current() + ctx_dict = {'site': site, 'organization': settings.TELEMETA_ORGANIZATION, 'usr': user} + subject = render_to_string(subject_template, ctx_dict) + subject = ''.join(subject.splitlines()) + message = render_to_string(message_template, ctx_dict) + send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False) + profile = user.get_profile() + profile.init_password = True + profile.save() + mail_admins(subject, message) + + def handle(self, *args, **options): +# users = User.objects.all() + users = User.objects.filter(is_staff=True) + for user in users: + profile = user.get_profile() + if not profile.init_password and user.is_active: + self.init_password_email(user) + diff --git a/teleforma/models.py b/teleforma/models.py index 569bb22f..e7311a67 100755 --- a/teleforma/models.py +++ b/teleforma/models.py @@ -523,7 +523,7 @@ class Profile(models.Model): language = CharField(_('Language'), max_length=255, blank=True) telephone = CharField(_('Telephone'), max_length=255, blank=True) expiration_date = DateField(_('Expiration_date'), blank=True, null=True) - init_password = BooleanField(_('Password initialization')) + init_password = BooleanField(_('Password initialized')) class Meta: db_table = app_label + '_' + 'profiles' diff --git a/teleforma/templates/postman/archives.html b/teleforma/templates/postman/archives.html index ab3d94a2..219600a1 100644 --- a/teleforma/templates/postman/archives.html +++ b/teleforma/templates/postman/archives.html @@ -5,4 +5,4 @@ {% block pm_undelete_button %}{% endblock %} {% block pm_footer_info %}

{% trans "Messages in this folder will never be removed. You can use this folder for long term storage." %}

-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/teleforma/templates/postman/email_user_init.txt b/teleforma/templates/postman/email_user_init.txt new file mode 100644 index 00000000..cbfd4f57 --- /dev/null +++ b/teleforma/templates/postman/email_user_init.txt @@ -0,0 +1,19 @@ +{% load i18n %}{% load telemeta_utils %}{% load teleforma_tags %}{% autoescape off %}{% trans "Hello" %} {{ usr.first_name }} {{ usr.last_name }}, + +Suite à votre inscription à la formation estivale 2012 du Pré-Barreau, vous trouverez ci-dessous un lien vous invitant à choisir votre mot de passe à la plateforme e-learning. + +http://{{ site.name }}/account/reset_password + +Cette plateforme vous permettra d’accéder tout au long de votre formation aux différents documents - fascicules de cours (selon la formule choisie), fascicules d’actualisation, sujets et corrigés - ainsi qu’à l’ensemble de vos enseignements. La messagerie intégrée vous permet de communiquer avec les administrateurs, les utilisateurs et le corps enseignant. Une page d'aide est également disponible pour vous assister lors de la découverte de ces nouveaux services. + +Nous vous rappelons que votre formation commencera le vendredi 20 juillet 2012 par une séance de méthodologie à la note de synthèse (2h) et aux épreuves juridiques (2h). + +Ainsi, vous composerez sur la première note de synthèse dès le samedi 21 juillet et sur les épreuves juridiques les lundi 23 et mardi 24 juillet. + +Votre emploi du temps vous sera communiqué vers le 16 juillet. + +{% trans "Best regards" %}, +{% trans "The site administrator" %} {% trans "of" %} {% organization %} + +{% blocktrans %}Note: This message is issued by an automated system. +Do not reply, this would not be taken into account.{% endblocktrans %}{% endautoescape %} diff --git a/teleforma/templates/postman/email_user_subject_init.txt b/teleforma/templates/postman/email_user_subject_init.txt new file mode 100644 index 00000000..152eb262 --- /dev/null +++ b/teleforma/templates/postman/email_user_subject_init.txt @@ -0,0 +1 @@ +{% load i18n %}{% autoescape off %}{% blocktrans with site.name as sitename %}Initialization of your account for {{ organization }} on the site {{ sitename }}{% endblocktrans %}{% endautoescape %} \ No newline at end of file diff --git a/teleforma/templates/teleforma/inc/document_list.html b/teleforma/templates/teleforma/inc/document_list.html index 2a6224b2..52b92011 100644 --- a/teleforma/templates/teleforma/inc/document_list.html +++ b/teleforma/templates/teleforma/inc/document_list.html @@ -15,12 +15,7 @@ {% for document in course.document.all|from_course_type:type|from_doc_type:doc_type %} {% if document.file %}{% endif %} {{ document.title }}{% if document.file %}{% endif %} - - {{ document.date_added }} + {{ document.date_modified }} {% if document.file %}{% endif %} {% endfor %} @@ -35,5 +30,4 @@

{% trans "No document" %}

- -{% endif %} \ No newline at end of file +{% endif %} -- 2.39.5