This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
226 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python | ||
# coding: utf-8 | ||
from __future__ import unicode_literals | ||
import arrow | ||
|
||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
from django.core.mail import send_mail | ||
from django.template.loader import render_to_string | ||
|
||
from django_th.models import Digest | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
help = 'Trigger all data from cache in version 2' | ||
|
||
def handle(self, *args, **options): | ||
""" | ||
get all the digest data to send to each user | ||
""" | ||
now = arrow.utcnow().to(settings.TIME_ZONE) | ||
now = now.date() | ||
|
||
digest = Digest.objects.filter(date_end=str(now)).order_by('user', | ||
'date_end') | ||
users = digest.distinct('user') | ||
|
||
subject = 'Your digester' | ||
|
||
msg_plain = render_to_string('digest/email.txt', | ||
{'digest': digest, | ||
'subject': subject}) | ||
msg_html = render_to_string('digest/email.html', | ||
{'digest': digest, | ||
'subject': subject}) | ||
message = msg_plain | ||
from_email = settings.ADMINS | ||
recipient_list = () | ||
for user in users: | ||
recipient_list += (user.user.email,) | ||
|
||
send_mail(subject, message, from_email, recipient_list, | ||
html_message=msg_html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.5 on 2017-09-16 08:35 | ||
from __future__ import unicode_literals | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('django_th', '0010_userservice_token'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='userservice', | ||
name='duration', | ||
field=models.CharField(choices=[('d', 'Day'), ('w', 'Week'), ('m', 'Month'), ('n', 'None')], default='n', | ||
max_length=1), | ||
), | ||
migrations.CreateModel( | ||
name='Digest', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=600)), | ||
('link', models.URLField()), | ||
('duration', models.CharField(max_length=1)), | ||
('date_end', models.DateField()), | ||
('provider', models.CharField(max_length=40)), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.dispatch import Signal | ||
|
||
digest_event = Signal(providing_args=["user", "title", "link", "duration"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Digest of your service </h1> | ||
<ul> | ||
{% for data in digest %} | ||
<li><a href="{{ data.link }}">{{ data.title }}</a></li> | ||
{% endfor %} | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Digest of your service | ||
|
||
{% for data in digest %} | ||
{{ data.title }} - {{ data.link }} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters