Add report feature

This commit is contained in:
Yax 2015-09-11 20:23:53 +02:00
parent 49c4083882
commit 18ad5870b7
6 changed files with 62 additions and 11 deletions

View file

@ -12,10 +12,10 @@ class Report(Model):
name = CharField(unique=True) name = CharField(unique=True)
email = CharField() email = CharField()
url = CharField() url = CharField()
published = BooleanField() published = BooleanField(default=False)
rejected = BooleanField() rejected = BooleanField(default=False)
subscribed = BooleanField() subscribed = BooleanField(default=False)
unsubscribed = BooleanField() unsubscribed = BooleanField(default=False)
site = ForeignKeyField(Site, related_name='report_site') site = ForeignKeyField(Site, related_name='report_site')
class Meta: class Meta:

View file

@ -10,6 +10,7 @@ from jinja2 import Environment, 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
from app.models.report import Report
import requests import requests
import json import json
import config import config
@ -218,26 +219,52 @@ def notify_reader(from_email, to_email, token, url):
def report_rejected(comment): 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): 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): 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): 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): def report(token):
print('report requested for {}'.format(token)) site = Site.select().where(Site.token == token).get()
standby_count = Comment.select().join(Site).where( c_standby = Comment.select().join(Site).where(
Site.token == token, Comment.published.is_null(True)).count() 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): def mail(to_email, subject, message):

View file

@ -0,0 +1,11 @@
Comments :
- published : {{ published }}
- rejected : {{ rejected }}
- standby : {{ standby }}
New readers : {{ subscribed }}
Cancelled subscriptions : {{ unsubscribed }}
--
Stacosys

View file

@ -0,0 +1 @@
Status report : {{ site }}

View file

@ -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

View file

@ -0,0 +1 @@
Rapport d'activité : {{ site }}