Improve reporting
This commit is contained in:
parent
07702cbd0e
commit
3f246b6037
4 changed files with 123 additions and 32 deletions
|
@ -6,7 +6,8 @@ import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment
|
||||||
|
from jinja2 import FileSystemLoader
|
||||||
from app.models.site import Site
|
from app.models.site import Site
|
||||||
from app.models.comment import Comment
|
from app.models.comment import Comment
|
||||||
from app.models.reader import Reader
|
from app.models.reader import Reader
|
||||||
|
@ -15,7 +16,6 @@ import requests
|
||||||
import json
|
import json
|
||||||
import config
|
import config
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
queue = Queue()
|
queue = Queue()
|
||||||
proc = None
|
proc = None
|
||||||
|
@ -206,8 +206,8 @@ def notify_subscribed_readers(token, site_url, url):
|
||||||
Reader.url == url):
|
Reader.url == url):
|
||||||
to_email = reader.email
|
to_email = reader.email
|
||||||
logger.info('notify reader %s' % to_email)
|
logger.info('notify reader %s' % to_email)
|
||||||
unsubscribe_url = '%s?email=%s&token=%s&url=%s' % (
|
unsubscribe_url = '%s/unsubscribe?email=%s&token=%s&url=%s' % (
|
||||||
config.UNSUBSCRIBE_URL, to_email, token, reader.url)
|
config.ROOT_URL, to_email, token, reader.url)
|
||||||
email_body = get_template(
|
email_body = get_template(
|
||||||
'notify_subscriber').render(article_url=article_url,
|
'notify_subscriber').render(article_url=article_url,
|
||||||
unsubscribe_url=unsubscribe_url)
|
unsubscribe_url=unsubscribe_url)
|
||||||
|
@ -253,24 +253,52 @@ def report_unsubscribed(comment):
|
||||||
|
|
||||||
def report(token):
|
def report(token):
|
||||||
site = Site.select().where(Site.token == token).get()
|
site = Site.select().where(Site.token == token).get()
|
||||||
c_standby = Comment.select().join(Site).where(
|
|
||||||
Site.token == token, Comment.published.is_null(True)).count()
|
standbys = []
|
||||||
c_published = Report.select().join(Site).where(
|
for row in Comment.select().join(Site).where(
|
||||||
Site.token == token, Report.published).count()
|
Site.token == token, Comment.published.is_null(True)):
|
||||||
c_rejected = Report.select().join(Site).where(
|
standbys.append({'url': "http://" + site.url + row.url,
|
||||||
Site.token == token, Report.rejected).count()
|
'created': row.created.strftime('%d/%m/%y %H:%M'),
|
||||||
c_subscribed = Report.select().join(Site).where(
|
'name': row.author_name, 'content': row.content,
|
||||||
Site.token == token, Report.subscribed).count()
|
'id': row.id})
|
||||||
c_unsubscribed = Report.select().join(Site).where(
|
|
||||||
Site.token == token, Report.unsubscribed).count()
|
published = []
|
||||||
email_body = get_template('report').render(standby=c_standby, published=c_published, rejected=c_rejected,
|
for row in Report.select().join(Site).where(
|
||||||
subscribed=c_subscribed,unsubscribed=c_unsubscribed)
|
Site.token == token, Report.published):
|
||||||
|
published.append({'url': "http://" + site.url + row.url,
|
||||||
|
'name': row.name, 'email': row.email})
|
||||||
|
|
||||||
|
rejected = []
|
||||||
|
for row in Report.select().join(Site).where(
|
||||||
|
Site.token == token, Report.rejected):
|
||||||
|
rejected.append({'url': "http://" + site.url + row.url,
|
||||||
|
'name': row.name, 'email': row.email})
|
||||||
|
|
||||||
|
subscribed = []
|
||||||
|
for row in Report.select().join(Site).where(
|
||||||
|
Site.token == token, Report.subscribed):
|
||||||
|
subscribed.append({'url': "http://" + site.url + row.url,
|
||||||
|
'name': row.name, 'email': row.email})
|
||||||
|
|
||||||
|
unsubscribed = []
|
||||||
|
for row in Report.select().join(Site).where(
|
||||||
|
Site.token == token, Report.subscribed):
|
||||||
|
unsubscribed.append({'url': "http://" + site.url + row.url,
|
||||||
|
'name': row.name, 'email': row.email})
|
||||||
|
|
||||||
|
email_body = get_template('report').render(secret=config.SECRET,
|
||||||
|
root_url=config.ROOT_URL,
|
||||||
|
standbys=standbys,
|
||||||
|
published=published,
|
||||||
|
rejected=rejected,
|
||||||
|
subscribed=subscribed,
|
||||||
|
unsubscribed=unsubscribed)
|
||||||
subject = get_template('report_message').render(site=site.name)
|
subject = get_template('report_message').render(site=site.name)
|
||||||
mail(site.admin_email, subject, email_body)
|
print(email_body)
|
||||||
|
#mail(site.admin_email, subject, email_body)
|
||||||
|
|
||||||
# TODO: delete report table
|
# TODO: delete report table
|
||||||
#Report.delete().execute()
|
# Report.delete().execute()
|
||||||
|
|
||||||
|
|
||||||
def mail(to_email, subject, message):
|
def mail(to_email, subject, message):
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,42 @@
|
||||||
Comments :
|
{% if subscribed %}
|
||||||
- published : {{ published }}
|
{% if subscribed|length > 1 %}NEW SUBSCRIPTIONS{% else %}NEW SUBSCRIPTION{% endif %} :
|
||||||
- rejected : {{ rejected }}
|
{% for c in subscribed %}
|
||||||
- standby : {{ standby }}
|
- {{ c.name }} ({{ c.email }}) => {{ c.url }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
New readers : {{ subscribed }}
|
{% endif %}
|
||||||
Cancelled subscriptions : {{ unsubscribed }}
|
{% if unsubscribed %}
|
||||||
|
{% if unsubscribed|length > 1 %}CANCELLED SUBSCRIPTIONS{% else %}CANCELLED SUBSCRIPTION{% endif %} :
|
||||||
|
{% for c in unsubscribed %}
|
||||||
|
- {{ c.name }} ({{ c.email }}) => {{ c.url }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if published %}
|
||||||
|
{% if published|length > 1 %}PUBLISHED COMMENTS{% else %}PUBLISHED COMMENT{% endif %} :
|
||||||
|
{% for c in published %}
|
||||||
|
- {{ c.name }} ({{ c.email }}) => {{ c.url }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if rejected %}
|
||||||
|
{% if rejected|length > 1 %}REJECTED COMMENTS{% else %}REJECTED COMMENT{% endif %} :
|
||||||
|
{% for c in rejected %}
|
||||||
|
- {{ c.name }} ({{ c.email }}) => {{ c.url }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if standbys %}
|
||||||
|
{% if standbys|length > 1 %}STANDBY COMMENTS{% else %}STANDBY COMMENT{% endif %} :
|
||||||
|
{% for c in standbys %}
|
||||||
|
- {{ c.name }} ({{ c.created }}) => {{ c.url }}
|
||||||
|
{{ c.content }}
|
||||||
|
|
||||||
|
Accepter : {{ root_url}}/accept?secret={{ secret}}&comment={{ c.id }}
|
||||||
|
Rejeter : {{ root_url}}/reject?secret={{ secret}}&comment={{ c.id }}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
--
|
--
|
||||||
Stacosys
|
Stacosys
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,42 @@
|
||||||
Nombre de commentaires :
|
{% if subscribed %}
|
||||||
- publié(s) : {{ published }}
|
{% if subscribed|length > 1 %}NOUVEAUX ABONNEMENTS{% else %}NOUVEL ABONNEMENT{% endif %} :
|
||||||
- rejeté(s) : {{ rejected }}
|
{% for c in subscribed %}
|
||||||
- en attente : {{ standby }}
|
- {{ c.name }} ({{ c.email }}) => {{ c.url }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
Nombre de nouveaux abonnés : {{ subscribed }}
|
{% endif %}
|
||||||
Abonnements résiliés : {{ unsubscribed }}
|
{% if unsubscribed %}
|
||||||
|
{% if unsubscribed|length > 1 %}ABONNEMENTS RESILIES{% else %}ABONNEMENT RESILIE{% endif %} :
|
||||||
|
{% for c in unsubscribed %}
|
||||||
|
- {{ c.name }} ({{ c.email }}) => {{ c.url }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if published %}
|
||||||
|
{% if published|length > 1 %}COMMENTAIRES PUBLIES{% else %}COMMENTAIRE PUBLIE{% endif %} :
|
||||||
|
{% for c in published %}
|
||||||
|
- {{ c.name }} ({{ c.email }}) => {{ c.url }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if rejected %}
|
||||||
|
{% if rejected|length > 1 %}COMMENTAIRES REJETES{% else %}COMMENTAIRE REJETE{% endif %} :
|
||||||
|
{% for c in rejected %}
|
||||||
|
- {{ c.name }} ({{ c.email }}) => {{ c.url }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if standbys %}
|
||||||
|
{% if standbys|length > 1 %}COMMENTAIRES EN ATTENTE{% else %}COMMENTAIRE EN ATTENTE{% endif %} :
|
||||||
|
{% for c in standbys %}
|
||||||
|
- {{ c.name }} ({{ c.created }}) => {{ c.url }}
|
||||||
|
{{ c.content }}
|
||||||
|
|
||||||
|
Accepter : {{ root_url}}/accept?secret={{ secret}}&comment={{ c.id }}
|
||||||
|
Rejeter : {{ root_url}}/reject?secret={{ secret}}&comment={{ c.id }}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
--
|
--
|
||||||
Stacosys
|
Stacosys
|
||||||
|
|
||||||
|
|
|
@ -16,4 +16,5 @@ SALT = "BRRJRqXgGpXWrgTidBPcixIThHpDuKc0"
|
||||||
|
|
||||||
SECRET = "Uqca5Kc8xuU6THz9"
|
SECRET = "Uqca5Kc8xuU6THz9"
|
||||||
|
|
||||||
UNSUBSCRIBE_URL = 'http://localhost:8000/unsubscribe'
|
ROOT_URL = 'http://localhost:8000'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue