예제 #1
0
def contact_us(request, template_name="accounts/contact_form.html"):
    if request.user.is_authenticated():
        form = ContactAuthForm()
    else:
        form = ContactForm()
    # if form was submitted, bind form instance.
    if request.method == "POST":
        if request.user.is_authenticated():
            form = ContactAuthForm(request.POST)
        else:
            form = ContactForm(request.POST)
        if form.is_valid():
            qui = request.POST.get("qui")
            if request.user.is_authenticated():
                from_email = "%s <%s>" % (request.user.username, request.user.email)
            else:
                from_email = "%s <%s>" % (request.POST["nom"], request.POST["email"])
            to_users = User.objects.filter(groups__name=qui)
            from core.mail import internal_sendmail

            internal_sendmail(
                ",".join([u.email for u in to_users]),
                from_email,
                request.POST["message"],
                "[Contact CAL] %s" % request.POST["sujet"],
                fail_silently=False,
            )
            return render_to_response("accounts/contact_form_sent.html", RequestContext(request, {}))
    return render_to_response(template_name, RequestContext(request, {"form": form}))
예제 #2
0
def send_participation_mail(sortie, nouveau, statut, template_name="sortie/participation_mail.html"): 
    current_site = Site.objects.get_current()
    site_name = current_site.name
    domain = current_site.domain
    maillist = []

    # Seulement l'auteur est notifie des changements de participation
    add_to_maillist(maillist, sortie.auteur, nouveau)

    participationstr = "What the F**k !!"
    if statut == "oui":
        participationstr = u"participe"
    elif statut == "non":
        participationstr = u"ne participe pas"
    elif statut == "peutetre":
        participationstr = u"participe potentiellement"
    subject = u"[CAL](%s) Je %s à '%s'" % (sortie.get_short_date_string(), participationstr, sortie.titre)
    from_email = "Les Cannes A L'air <*****@*****.**>"
    for u in maillist:
        text = render_to_string(template_name, {'site_name': site_name,
                                                'domain': domain,
                                                'user': nouveau,
                                                'profil':u,
                                                'sortie': sortie,
                                                })
        internal_sendmail(u.email, from_email, text, subject)
예제 #3
0
def send_mail_download(zipname, galerie, email):
    current_site = Site.objects.get_current()
    domain = current_site.domain
    downloadurl = "http://%s%s%s" % (domain, settings.TODOWNLOAD_URL, zipname)

    subject = "[CAL - Download] %s" % (galerie.titre)
    from_email = "Les Cannes A L'air <*****@*****.**>"

    text = render_to_string("galerie/mail_dl_galerie.html", {'galerie': galerie, 'downloadurl': downloadurl,})
    internal_sendmail(email, from_email, text, subject)
예제 #4
0
def send_comment_mail(comment): 
    current_site = Site.objects.get_current()
    site_name = current_site.name
    domain = current_site.domain
    maillist = []
    article = None
    sortie = None
    galerie = None
    from_email = "Les Cannes A L'air <*****@*****.**>"

    for s in comment.sortie_comments_set.all():
        sortie = s
        for p in sortie.sorties_suivies_set.all():
            add_to_maillist(maillist, p.user, comment.auteur)

    for a in comment.article_comments_set.all():
        article = a
        for p in article.articles_suivis_set.all():
            add_to_maillist(maillist, p.user, comment.auteur)

    for g in comment.galerie_comments_set.all():
        galerie = g
        for p in galerie.galeries_suivies_set.all():
            add_to_maillist(maillist, p.user, comment.auteur)

    template_name=None
    if article:
        subject = "[CAL] %s" % (article.titre)
        template_name="comment/message_mail_article.html"
    if sortie:
        subject = "[CAL](%s) %s" % (sortie.get_short_date_string(), sortie.titre)
        template_name="comment/message_mail_sortie.html"
    if galerie:
        subject = "[CAL] %s" % (galerie.titre)
        template_name="comment/message_mail_galerie.html"
    for u in maillist:
        text = render_to_string(template_name, {'site_name': site_name,
                                                'domain': domain,
                                                'user': comment.auteur,
                                                'comment': comment,
                                                'profil':u,
                                                'sortie': sortie,
                                                'article': article,
                                                'galerie': galerie,
                                                })
        internal_sendmail(u.email, from_email, text, subject)
예제 #5
0
def send_notification_new_thread(message, template_name="forum/new_thread_mail.html"):
    current_site = Site.objects.get_current()
    site_name = current_site.name
    domain = current_site.domain
    maillist = []
        
    for p in Profil.objects.filter(suivre_les_discussions=True):
        add_to_maillist(maillist, p.user, message.auteur)

    subject = "[Forum CAL] %s" % (message.thread.titre)
    from_email = "Les Cannes A L'air <*****@*****.**>"
    for u in maillist:
        text = render_to_string(template_name, {'site_name': site_name,
                                                'domain': domain,
                                                'user': message.auteur,
                                                'message': message,
                                                'profil': u,
                                                })
        internal_sendmail(u.email, from_email, text, subject)
예제 #6
0
def send_notification_new_article(article, template_name="article/mail_new_article.html"):
    current_site = Site.objects.get_current()
    site_name = current_site.name
    domain = current_site.domain
    maillist = []
        
    for p in Profil.objects.filter(suivre_les_articles=True):
        add_to_maillist(maillist, p.user, article.auteur)

    subject = "[CAL] %s" % (article.titre)
    from_email = "Les Cannes A L'air <*****@*****.**>"
    for u in maillist:
        text = render_to_string(template_name, {'site_name': site_name,
                                                'domain': domain,
                                                'user': article.auteur,
                                                'article': article,
                                                'profil': u,
                                                })
        internal_sendmail(u.email, from_email, text, subject)
예제 #7
0
def send_notification_new_sortie(sortie, template_name="sortie/mail_new_sortie.html"):
    current_site = Site.objects.get_current()
    site_name = current_site.name
    domain = current_site.domain
    maillist = []
        
    for p in Profil.objects.filter(suivre_les_sorties=True):
        add_to_maillist(maillist, p.user, sortie.auteur)
    for p in Profil.objects.filter(suivre_les_sorties_partype__in=sortie.activites.all()):
        add_to_maillist(maillist, p.user, sortie.auteur)

    subject = "[CAL](%s) %s" % (sortie.get_short_date_string(), sortie.titre)
    from_email = "Les Cannes A L'air <*****@*****.**>"
    for u in maillist:
        text = render_to_string(template_name, {'site_name': site_name,
                                                'domain': domain,
                                                'user': sortie.auteur,
                                                'sortie': sortie,
                                                'profil': u,
                                                })
        internal_sendmail(u.email, from_email, text, subject)
예제 #8
0
def create_new_user(request, template_name="accounts/user_create_form.html"):
    form = CustomUserCreationForm()
    # if form was submitted, bind form instance.
    if request.method == "POST":
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            # user must be active for login to work
            user.is_active = True
            user.email = request.POST.get("email")
            user.first_name = request.POST.get("first_name")
            user.last_name = request.POST.get("last_name")
            user.save()
            p = Profil(user=user)
            p.last_known_activity = LogActivity.getDefault()
            p.save()

            from_email = "Les Cannes A L'air <*****@*****.**>"
            text = (
                "Nouvel inscrit chez les CAL : %s %s (%s)<br><br>L'invalidation du compte peut se faire <a href='http://cannesalair.fr/admin/auth/user/%s/'>ici</a>."
                % (user.first_name, user.last_name, user.email, user.id)
            )
            to_users = User.objects.filter(groups__name="Admin")
            from core.mail import internal_sendmail

            internal_sendmail(
                ",".join([u.email for u in to_users]),
                from_email,
                text,
                "[CAL] %s vient de s'inscrire sur le site des CAL" % user.username,
                fail_silently=False,
            )
            return HttpResponseRedirect(reverse("editprofil"))

    for f in form.fields:
        if not f == "captcha":
            form.fields[f].widget.attrs["class"] = "input-medium"
        form.fields[f].help_text = ""
    return render_to_response(template_name, RequestContext(request, {"form": form, "isstandalone": True}))
예제 #9
0
def send_message_mail(message, template_name="forum/message_mail.html"): 
    current_site = Site.objects.get_current()
    site_name = current_site.name
    domain = current_site.domain
    maillist = []
    for p in message.thread.discussions_suivies_set.all():
        add_to_maillist(maillist, p.user, message.auteur)
    for p in message.thread.forum.forums_suivis_set.all():
        add_to_maillist(maillist, p.user, message.auteur)
    for u in message.thread.forum.moderateurs.all():
        add_to_maillist(maillist, u, message.auteur)
        
    subject = "[Forum CAL] %s" % (message.thread.titre)
    from_email = "Les Cannes A L'air <*****@*****.**>"
    for u in maillist:
        text = render_to_string(template_name, {'site_name': site_name,
                                                'domain': domain,
                                                'user': message.auteur,
                                                'message': message,
                                                'profil': u,
                                                })
        internal_sendmail(u.email, from_email, text, subject)