Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions www/account/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

from django.conf import settings
from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone, http
from django.utils.translation import get_language
from django.template.loader import render_to_string
from django.core.mail import send_mail
from django.core.mail import EmailMultiAlternatives
Expand Down Expand Up @@ -170,3 +172,12 @@ def has_identity_set(self):
if self.first_name and self.last_name:
return True
return False


def add_user_language(sender, instance, created, **kwargs):
if created:
instance.browser_language = get_language()
instance.save(update_fields=['browser_language'])

# register the signal
post_save.connect(add_user_language, sender=User)
56 changes: 55 additions & 1 deletion www/account/tasks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,64 @@
# -*- coding:Utf-8 -*-

from celery.task import task
import datetime

from django.utils.timezone import now
from django.template.loader import render_to_string
from django.template import Context
from django.conf import settings
from django.core.mail import EmailMessage, get_connection

from celery.task import task, periodic_task
from celery.schedules import crontab

from vosae_utils import respects_language


@task
@respects_language
def user_send_activation_email(user):
user.send_activation_email()

@periodic_task(run_every=crontab(minute=0, hour='*/1'))
@respects_language
def user_send_inactive_email():
from account.models import User

for user in User.objects.filter(is_active=False, date_joined__gte=now() - datetime.timedelta(days=1, hours=1), date_joined__lte=now() - datetime.timedelta(days=1)):

context = {
'user': user,
'site': {'name': settings.SITE_NAME, 'url': settings.SITE_URL}
}
# Send mails
connection = get_connection()
plaintext_context = Context(autoescape=False) # HTML escaping not appropriate in plaintext
subject = render_to_string('account/emails/inactive_email_subject.txt', context, plaintext_context)
subject = ''.join(subject.splitlines())
text_body = render_to_string('account/emails/inactive_email_message.txt', context, plaintext_context)

message = EmailMessage(subject=subject, from_email="maxime@vosae.com", to=[user.email], body=text_body, connection=connection)
message.preserve_recipients = False # Useful for Mandrill
message.send()

@periodic_task(run_every=crontab(minute=0, hour='*/1'))
@respects_language
def user_send_after_one_week_email():
from account.models import User

for user in User.objects.filter(is_active=True, date_joined__gte=now() - datetime.timedelta(days=7, hours=1), date_joined__lte=now() - datetime.timedelta(days=7)):

context = {
'user': user,
'site': {'name': settings.SITE_NAME, 'url': settings.SITE_URL}
}
# Send mails
connection = get_connection()
plaintext_context = Context(autoescape=False) # HTML escaping not appropriate in plaintext
subject = render_to_string('account/emails/after_one_week_email_subject.txt', context, plaintext_context)
subject = ''.join(subject.splitlines())
text_body = render_to_string('account/emails/after_one_week_email_message.txt', context, plaintext_context)

message = EmailMessage(subject=subject, from_email="maxime@vosae.com", to=[user.email], body=text_body, connection=connection)
message.preserve_recipients = False # Useful for Mandrill
message.send()
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% load i18n %}{% autoescape off %}
{% blocktrans with site=site.name first_name=user.first_name %}Hi {{ first_name }},

You signed up with {{ site }} a little over a week ago. And, I was wondering how's it going? If you want to share with me your first feelings, if you are running into any issues, or have any questions, I would love to help!
If you are looking for a little guidance on a conversation, you can answer the following questions:

- Every company is different... what kind of business are you running?
- How many colleagues do you have?
- What have you enjoyed about {{ site }}?
- What is not perfect?
- What questions can I answer for you about {{ site }}?
- Just respond, and we can get the dialog going. We have worked with many customers, and would like to know how we can help you.


Regards,
--
Maxime Gaillard
Co-founder, CEO
Vosae
{% endblocktrans %}
{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans with site=site.name %}Your {{ site }} account{% endblocktrans %}
16 changes: 16 additions & 0 deletions www/account/templates/account/emails/inactive_email_message.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% load i18n %}{% autoescape off %}
{% if user.first_name %}
{% blocktrans with first_name=user.first_name %}Hi {{ first_name }},{% endblocktrans %}
{% else %}
{% trans "Hi," %}
{% endif %}
{% blocktrans with site=site.name %}I notice you've set up a {{ site }} account, but have yet activated your account. Please let me know if you were running into any issues, or have any questions, I would love to help!

Regards,
--
Maxime Gaillard
Co-founder, CEO
Vosae
{% endblocktrans %}
{% endautoescape %}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans with site=site.name %}Your {{ site }} account{% endblocktrans %}