Improve reporting

pull/6/head
Yax 9 years ago
parent 07702cbd0e
commit 3f246b6037

@ -6,7 +6,8 @@ import re
from datetime import datetime
from threading import Thread
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.comment import Comment
from app.models.reader import Reader
@ -15,7 +16,6 @@ import requests
import json
import config
logger = logging.getLogger(__name__)
queue = Queue()
proc = None
@ -206,8 +206,8 @@ def notify_subscribed_readers(token, site_url, url):
Reader.url == url):
to_email = reader.email
logger.info('notify reader %s' % to_email)
unsubscribe_url = '%s?email=%s&token=%s&url=%s' % (
config.UNSUBSCRIBE_URL, to_email, token, reader.url)
unsubscribe_url = '%s/unsubscribe?email=%s&token=%s&url=%s' % (
config.ROOT_URL, to_email, token, reader.url)
email_body = get_template(
'notify_subscriber').render(article_url=article_url,
unsubscribe_url=unsubscribe_url)
@ -253,24 +253,52 @@ def report_unsubscribed(comment):
def report(token):
site = Site.select().where(Site.token == token).get()
c_standby = Comment.select().join(Site).where(
Site.token == token, Comment.published.is_null(True)).count()
c_published = Report.select().join(Site).where(
Site.token == token, Report.published).count()
c_rejected = Report.select().join(Site).where(
Site.token == token, Report.rejected).count()
c_subscribed = Report.select().join(Site).where(
Site.token == token, Report.subscribed).count()
c_unsubscribed = Report.select().join(Site).where(
Site.token == token, Report.unsubscribed).count()
email_body = get_template('report').render(standby=c_standby, published=c_published, rejected=c_rejected,
subscribed=c_subscribed,unsubscribed=c_unsubscribed)
standbys = []
for row in Comment.select().join(Site).where(
Site.token == token, Comment.published.is_null(True)):
standbys.append({'url': "http://" + site.url + row.url,
'created': row.created.strftime('%d/%m/%y %H:%M'),
'name': row.author_name, 'content': row.content,
'id': row.id})
published = []
for row in Report.select().join(Site).where(
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)
mail(site.admin_email, subject, email_body)
print(email_body)
#mail(site.admin_email, subject, email_body)
# TODO: delete report table
#Report.delete().execute()
# Report.delete().execute()
def mail(to_email, subject, message):

@ -1,11 +1,42 @@
Comments :
- published : {{ published }}
- rejected : {{ rejected }}
- standby : {{ standby }}
{% if subscribed %}
{% if subscribed|length > 1 %}NEW SUBSCRIPTIONS{% else %}NEW SUBSCRIPTION{% endif %} :
{% for c in subscribed %}
- {{ c.name }} ({{ c.email }}) => {{ c.url }}
{% endfor %}
New readers : {{ subscribed }}
Cancelled subscriptions : {{ unsubscribed }}
{% endif %}
{% 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

@ -1,11 +1,42 @@
Nombre de commentaires :
- publié(s) : {{ published }}
- rejeté(s) : {{ rejected }}
- en attente : {{ standby }}
{% if subscribed %}
{% if subscribed|length > 1 %}NOUVEAUX ABONNEMENTS{% else %}NOUVEL ABONNEMENT{% endif %} :
{% for c in subscribed %}
- {{ c.name }} ({{ c.email }}) => {{ c.url }}
{% endfor %}
Nombre de nouveaux abonnés : {{ subscribed }}
Abonnements résiliés : {{ unsubscribed }}
{% endif %}
{% 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

@ -16,4 +16,5 @@ SALT = "BRRJRqXgGpXWrgTidBPcixIThHpDuKc0"
SECRET = "Uqca5Kc8xuU6THz9"
UNSUBSCRIBE_URL = 'http://localhost:8000/unsubscribe'
ROOT_URL = 'http://localhost:8000'

Loading…
Cancel
Save