Commit 9df18026 authored by Luc Saffre's avatar Luc Saffre
Browse files
parent 22cc7c9e
......@@ -57,7 +57,7 @@ class ChangeWatcher(object):
for k, o, n in self.get_updates(*args, **kwargs):
f = self.watched._meta.get_field(k)
html = self.get_change_desc_html(f, o, n)
if html:
if html is not None and len(html):
yield html
# yield "{0} : {1}".format(k, desc)
......
......@@ -552,6 +552,13 @@ request from it.
context.update(ar=self)
return settings.SITE.kernel.memo_parser.parse(html, **context)
def obj2memo(self, *args, **kwargs):
"""Calls the site's parser's :meth:`obj2memo
<lino.utils.memo.Parser.obj2memo>` method.
"""
return settings.SITE.kernel.memo_parser.obj2memo(*args, **kwargs)
# def parse_memo(self, html):
# return self.renderer.parse_memo(html, ar=self)
......
......@@ -4,7 +4,7 @@
{% for msg in messages%}
<div>
<H3>{{fds(msg.created.date())}} {{msg.created.time().strftime('%H:%M')}}</H3>
{{msg.body}}
{{ar.parse_memo(msg.body)}}
</div>
{% endfor %}
<body>
......@@ -29,7 +29,7 @@ class ChangeObservable(dd.Model):
"""
if cw is None:
elems = [E.p(
ar.obj2html(self),
ar.obj2memo(self),
' ', _("has been created by {user}").format(
user=ar.get_user()))]
else:
......@@ -37,7 +37,7 @@ class ChangeObservable(dd.Model):
if len(items) == 0:
return
elems = [E.p(
ar.obj2html(self),
ar.obj2memo(self),
' ', _("has been modified by {user}").format(
user=ar.get_user()),
":")]
......
# -*- coding: UTF-8 -*-
# Copyright 2011-2016 Luc Saffre
# Copyright 2011-2017 Luc Saffre
# License: BSD (see file COPYING for details)
"""Database models for this plugin.
......@@ -13,13 +13,14 @@ import json
from django.db import models
from django.conf import settings
from django.utils import timezone
from django.utils import translation
from lino.api import dd, rt, _
from lino.api import pgettext
from lino.core.roles import SiteStaff
#from lino.core.roles import SiteStaff
from lino.core.gfks import gfk2lookup
from lino.core.requests import BaseRequest
#from lino.core.requests import BaseRequest
from lino.core.site import html2text
from lino.mixins import Created, ObservedPeriod
......@@ -299,11 +300,16 @@ class Message(UserAuthored, Controllable, Created):
@classmethod
def send_summary_emails(cls, mm):
"""Send summary emails for all pending notifications with the given
mail_mode `mm`.
"""
qs = cls.objects.filter(sent__isnull=True)
qs = qs.exclude(user__email='')
qs = qs.filter(mail_mode=mm).order_by('user')
if qs.count() == 0:
return
ar = rt.login()
sender = settings.SERVER_EMAIL
template = rt.get_template('notify/summary.eml')
users = dict()
......@@ -313,14 +319,16 @@ class Message(UserAuthored, Controllable, Created):
dd.logger.debug(
"Send out %s summaries for %d users.", mm, len(users))
for user, messages in users.items():
subject = _("{} notifications").format(len(messages))
subject = settings.EMAIL_SUBJECT_PREFIX + subject
context = dict(user=user, E=E, rt=rt, messages=messages)
body = template.render(**context)
rt.send_email(subject, sender, body, [user.email])
for msg in messages:
msg.sent = timezone.now()
msg.save()
with translation.override(user.language):
subject = _("{} notifications").format(len(messages))
subject = settings.EMAIL_SUBJECT_PREFIX + subject
context = dict(ar=ar, user=user, E=E, rt=rt, messages=messages)
body = template.render(**context)
# dd.logger.debug("20170112 %s", body)
rt.send_email(subject, sender, body, [user.email])
for msg in messages:
msg.sent = timezone.now()
msg.save()
def send_browser_message_for_all_users(self, user):
......@@ -460,6 +468,8 @@ class MyMessages(My, Messages):
order_by = ['created']
# hide_headers = True
slave_grid_format = 'summary'
# slave_grid_format = 'list'
# slave_grid_format = 'grid'
@classmethod
def get_slave_summary(cls, mi, ar):
......@@ -477,7 +487,8 @@ class MyMessages(My, Messages):
s = E.tostring(ar.action_button(ba, obj))
s += fds(obj.created) + " " + obj.created.strftime(
settings.SITE.time_format_strftime) + " "
s += obj.body
s += ar.parse_memo(obj.body)
# s += obj.body
return "<li>{}</li>".format(s)
items = []
......
......@@ -170,10 +170,15 @@ class Parser(object):
def __init__(self, **context):
self.commands = dict()
self.context = context
self.renderers = dict()
def register_command(self, cmd, func):
self.commands[cmd] = func
def register_renderer(self, cl, func):
assert not cl in self.renderers
self.renderers[cl] = func
def eval_match(self, matchobj):
expr = matchobj.group(1)
try:
......@@ -218,6 +223,18 @@ class Parser(object):
s = EVAL_REGEX.sub(self.eval_match, s)
return s
def obj2memo(self, obj, **options):
"""Render the given database object as memo markup.
This works only for objects for which there is a renderer.
Renderers are defined by :meth:`register_renderer`.
"""
h = self.renderers.get(obj.__class__)
if h is None:
return "*{}*".format(obj)
return h(obj, **options)
def _test():
import doctest
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment