From 00bb418fe4f707d98000de97ba91a3f5ec367fe0 Mon Sep 17 00:00:00 2001 From: Yax <1949284+kianby@users.noreply.github.com> Date: Fri, 11 Sep 2015 20:23:53 +0200 Subject: [PATCH] Add report feature --- app/models/report.py | 8 +++--- app/services/processor.py | 41 ++++++++++++++++++++++++----- app/templates/en/report.tpl | 11 ++++++++ app/templates/en/report_message.tpl | 1 + app/templates/fr/report.tpl | 11 ++++++++ app/templates/fr/report_message.tpl | 1 + 6 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 app/templates/en/report.tpl create mode 100644 app/templates/en/report_message.tpl create mode 100644 app/templates/fr/report.tpl create mode 100644 app/templates/fr/report_message.tpl diff --git a/app/models/report.py b/app/models/report.py index e6102d1..a72409d 100644 --- a/app/models/report.py +++ b/app/models/report.py @@ -12,10 +12,10 @@ class Report(Model): name = CharField(unique=True) email = CharField() url = CharField() - published = BooleanField() - rejected = BooleanField() - subscribed = BooleanField() - unsubscribed = BooleanField() + published = BooleanField(default=False) + rejected = BooleanField(default=False) + subscribed = BooleanField(default=False) + unsubscribed = BooleanField(default=False) site = ForeignKeyField(Site, related_name='report_site') class Meta: diff --git a/app/services/processor.py b/app/services/processor.py index a8199d1..1fb29a4 100644 --- a/app/services/processor.py +++ b/app/services/processor.py @@ -10,6 +10,7 @@ from jinja2 import Environment, FileSystemLoader from app.models.site import Site from app.models.comment import Comment from app.models.reader import Reader +from app.models.report import Report import requests import json import config @@ -218,26 +219,52 @@ def notify_reader(from_email, to_email, token, url): def report_rejected(comment): - pass + report = Report(site=comment.site, url=comment.url, + name=comment.author_name, email=comment.author_email, + rejected=True) + report.save() def report_published(comment): - pass + report = Report(site=comment.site, url=comment.url, + name=comment.author_name, email=comment.author_email, + published=True) + report.save() def report_subscribed(comment): - pass + report = Report(site=comment.site, url=comment.url, + name=comment.author_name, email=comment.author_email, + subscribed=True) + report.save() def report_unsubscribed(comment): - pass + report = Report(site=comment.site, url=comment.url, + name=comment.author_name, email=comment.author_email, + unsubscribed=True) + report.save() def report(token): - print('report requested for {}'.format(token)) - standby_count = Comment.select().join(Site).where( + site = Site.select().where(Site.token == token).get() + c_standby = Comment.select().join(Site).where( Site.token == token, Comment.published.is_null(True)).count() - print('standby {}'.format(standby_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) + subject = get_template('report_message').render(site=site.name) + mail(site.admin_email, subject, email_body) + + # TODO: delete report table + #Report.delete().execute() def mail(to_email, subject, message): diff --git a/app/templates/en/report.tpl b/app/templates/en/report.tpl new file mode 100644 index 0000000..188edb8 --- /dev/null +++ b/app/templates/en/report.tpl @@ -0,0 +1,11 @@ +Comments : +- published : {{ published }} +- rejected : {{ rejected }} +- standby : {{ standby }} + +New readers : {{ subscribed }} +Cancelled subscriptions : {{ unsubscribed }} + +-- +Stacosys + diff --git a/app/templates/en/report_message.tpl b/app/templates/en/report_message.tpl new file mode 100644 index 0000000..c1b5056 --- /dev/null +++ b/app/templates/en/report_message.tpl @@ -0,0 +1 @@ +Status report : {{ site }} \ No newline at end of file diff --git a/app/templates/fr/report.tpl b/app/templates/fr/report.tpl new file mode 100644 index 0000000..0445295 --- /dev/null +++ b/app/templates/fr/report.tpl @@ -0,0 +1,11 @@ +Nombre de commentaires : +- publié(s) : {{ published }} +- rejeté(s) : {{ rejected }} +- en attente : {{ standby }} + +Nombre de nouveaux abonnés : {{ subscribed }} +Abonnements résiliés : {{ unsubscribed }} + +-- +Stacosys + diff --git a/app/templates/fr/report_message.tpl b/app/templates/fr/report_message.tpl new file mode 100644 index 0000000..45f08e7 --- /dev/null +++ b/app/templates/fr/report_message.tpl @@ -0,0 +1 @@ +Rapport d'activité : {{ site }} \ No newline at end of file