Пример #1
0
    def create_user(self):
        """
        Creates and logs in a new user for the habit
        """
        summary_form = self.form_list[2]
        user = User.objects.create_user(
            email=summary_form.cleaned_data.get('email'),
        )
        user.backend = 'django.contrib.auth.backends.ModelBackend'
        login(self.request, user)

        user_created.send(user)

        c = {
            'email': user.email,
            'uid': int_to_base36(user.pk),
            'user': user,
            'token': token_generator.make_token(user),
        }

        render_to_email(
            text_template='emails/onboarding/welcome.txt',
            html_template='emails/onboarding/welcome.html',
            to=(user,),
            subject='Welcome!',
            opt_out=False,
            context=c,
        )

        return user
Пример #2
0
    def save(self):
        """
        Saves the habit.
        """

        habit_form = self.form_list[0]
        reminder_form = self.form_list[1]

        habit = Habit.objects.create(
            user=self.user,
            description=habit_form.cleaned_data.get('description'),
            resolution=habit_form.cleaned_data.get('resolution'),
            target_value=habit_form.cleaned_data.get('target_value'),
            reminder=reminder_form.cleaned_data.get('trigger'),
            reminder_hour=reminder_form.cleaned_data.get('hour') or 0,
            reminder_days=reminder_form.cleaned_data.get('days') or 0,
            start=datetime.now(),
        )
        habit_created.send(habit)

        if self.send_habit_email:
            render_to_email(
                text_template='emails/onboarding/habit_created.txt',
                html_template='emails/onboarding/habit_created.html',
                to=(self.user,),
                subject='You set up a new habit!',
                context={
                    'habit': habit,
                }
            )
Пример #3
0
            def save(self):
                user = User(
                    email=self.cleaned_data['email'],
                    name=self.cleaned_data['name'],
                    is_active=False,
                )
                user.set_password(self.cleaned_data['password'])
                user.save()

                c = {
                    'email': user.email,
                    'confirm_url': request.build_absolute_uri(
                        reverse(
                            'confirm_email_address',
                            kwargs={
                                'uidb64': urlsafe_base64_encode(
                                    force_bytes(user.pk),
                                ),
                                'token': token_generator.make_token(user),
                            },
                        )
                    ),
                    'user': user,
                }

                render_to_email(
                    text_template='registration/welcome_email.txt',
                    html_template='registration/welcome_email.html',
                    to=(user,),
                    subject=_('Welcome to Kallisto!'),
                    opt_out=False,
                    context=c,
                )
                
                return user
Пример #4
0
def password_change(request, *args, **kwargs):
    response = django.contrib.auth.views.password_change(request, *args, **kwargs)
    if request.method == 'POST' and response.status_code == 302:
        user_changed_password.send(sender=password_change)
        render_to_email(
            text_template='emails/accounts/password_changed.txt',
            html_template='emails/accounts/password_changed.html',
            to=(request.user,),
            subject='Your password has been changed',
            opt_out=False,
        )
    return response
Пример #5
0
def send_data_collection_email(habit, today=None):
    if today is None:
        today = datetime.date.today()

    if not habit.send_data_collection_emails or habit.archived:
        return

    if today == habit.start:
        # Don't ask for data from before the habit was created
        return

    if habit.resolution == 'weekday':
        # Don't ask for data on Sundays and Mondays
        if today.weekday() in [6, 0]:
            return

    if habit.resolution == 'weekendday':
        # Don't ask for data from Tuesday to Saturday
        if today.weekday() in range(1, 6):
            return

    if habit.resolution == 'week':
        # Don't ask for data unless today is a Monday
        if today.weekday() != 0:
            return

    if habit.resolution == 'month':
        # Don't ask for data unless today is the 1st of a new month
        if today.day != 1:
            return

    time_period_name = {
        'day': _('yesterday'),
        'weekday': _('yesterday'),
        'weekendday': _('yesterday'),
        'week': _('last week'),
        'month': _('last month'),
    }[habit.resolution]

    return render_to_email(
        text_template='emails/habits/data_collection.txt',
        html_template='emails/habits/data_collection.html',
        to=(habit.user, ),
        subject='Let us know how you did',
        context={
            'time_period_name':
            time_period_name,
            'habit':
            habit,
            'unsubscribe_url':
            make_auto_login_link(habit.user,
                                 redirect=reverse('account_settings')),
            'record_url':
            make_auto_login_link(habit.user,
                                 redirect=reverse('habit_record',
                                                  args=[habit.pk])),
        },
    )
Пример #6
0
def send_data_collection_email(habit, today=None):
    if today is None:
        today = datetime.date.today()

    if not habit.send_data_collection_emails or habit.archived:
        return

    if today == habit.start:
        # Don't ask for data from before the habit was created
        return

    if habit.resolution == 'weekday':
        # Don't ask for data on Sundays and Mondays
        if today.weekday() in [6, 0]:
            return

    if habit.resolution == 'weekendday':
        # Don't ask for data from Tuesday to Saturday
        if today.weekday() in range(1, 6):
            return

    if habit.resolution == 'week':
        # Don't ask for data unless today is a Monday
        if today.weekday() != 0:
            return

    if habit.resolution == 'month':
        # Don't ask for data unless today is the 1st of a new month
        if today.day != 1:
            return

    time_period_name = {
        'day':        _('yesterday'),
        'weekday':    _('yesterday'),
        'weekendday': _('yesterday'),
        'week':       _('last week'),
        'month':      _('last month'),
    }[habit.resolution]

    return render_to_email(
        text_template='emails/habits/data_collection.txt',
        html_template='emails/habits/data_collection.html',
        to=(habit.user,),
        subject='Let us know how you did',
        context={
            'time_period_name': time_period_name,
            'habit': habit,
            'unsubscribe_url': make_auto_login_link(habit.user, redirect=reverse('account_settings')),
            'record_url': make_auto_login_link(habit.user, redirect=reverse('habit_record', args=[habit.pk])),
        },
    )
Пример #7
0
            def save(self):
                user = User(
                    email=self.cleaned_data['email'],
                    name=self.cleaned_data['name'],
                    is_active=False,
                )
                user.set_password(self.cleaned_data['password'])
                user.save()

                c = {
                    'email':
                    user.email,
                    'confirm_url':
                    request.build_absolute_uri(
                        reverse(
                            'confirm_email_address',
                            kwargs={
                                'uidb64':
                                urlsafe_base64_encode(force_bytes(user.pk), ),
                                'token':
                                token_generator.make_token(user),
                            },
                        )),
                    'user':
                    user,
                }

                render_to_email(
                    text_template='registration/welcome_email.txt',
                    html_template='registration/welcome_email.html',
                    to=(user, ),
                    subject=_('Welcome to Kallisto!'),
                    opt_out=False,
                    context=c,
                )

                return user
Пример #8
0
def send_reminder_email(habit):
    if habit.archived:
        return

    return render_to_email(
        text_template='emails/habits/reminder.txt',
        html_template='emails/habits/reminder.html',
        to=(habit.user, ),
        subject=habit.description,
        context={
            'habit':
            habit,
            'unsubscribe_url':
            make_auto_login_link(habit.user,
                                 redirect=reverse(
                                     'habit_edit',
                                     args=[habit.pk],
                                 )),
        },
    )
Пример #9
0
def send_reminder_email(habit):
    if habit.archived:
        return

    return render_to_email(
        text_template='emails/habits/reminder.txt',
        html_template='emails/habits/reminder.html',
        to=(habit.user,),
        subject=habit.description,
        context={
            'habit': habit,
            'unsubscribe_url': make_auto_login_link(
                habit.user,
                redirect=reverse(
                    'habit_edit',
                    args=[habit.pk],
                )
            ),
        },
    )