From 229b193b25ac55777b28ba8223f1e91c0da2a071 Mon Sep 17 00:00:00 2001 From: Yingtong Li Date: Wed, 13 Feb 2019 15:17:43 +1100 Subject: [PATCH] Implement bulletin more view --- .../jinja2/sspromotions/email/bulletin.html | 21 +++++++++++-------- sspromotions/utils.py | 19 ++++++++++++++++- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/sspromotions/jinja2/sspromotions/email/bulletin.html b/sspromotions/jinja2/sspromotions/email/bulletin.html index 2f1fc63..fcdf787 100644 --- a/sspromotions/jinja2/sspromotions/email/bulletin.html +++ b/sspromotions/jinja2/sspromotions/email/bulletin.html @@ -90,15 +90,18 @@

More from MUMUS:

{{ gap }} - - {% for item in more %} - - {% if item.image %}{% if item.link %}{% endif %}{{ item.title }}{% if item.link %}{% endif %}
{% endif %} -
{{ item.title }}
-

{{ item.content }}

- {% if item.link %}

Read more ›

{% endif %} - - {% endfor %} + + + {% for item in more %} + + {% endfor %} +
+ {% if item.image %}{% if item.link %}{% endif %}{{ item.title }}{% if item.link %}{% endif %}
{% endif %} +
{{ item.title }}
+

{{ item.content|striptags|truncate(100) }}

+ {% if item.link %}

Read more ›

{% endif %} +

Subscribe to {{ item.group.name }}

+
{% endif %} {% endblock content %} diff --git a/sspromotions/utils.py b/sspromotions/utils.py index 7958f39..cd68720 100644 --- a/sspromotions/utils.py +++ b/sspromotions/utils.py @@ -64,11 +64,28 @@ def bulletin_args(member, groups, events, bulbegin, bulend): 'bulletin_items': items }) + more = [] + all_groups = models.Group.objects.all() + for group in all_groups: + if group in groups: + continue + if not group.subscribable: + continue + + for item in group.bulletinitem_set.filter(date__gte=bulbegin).filter(date__lt=bulend).all(): + # Check also_limit + # Allow matching across all groups, but only subscribable ones + if member is None or len(item.also_limit) == 0 or any(any(g.id == x and g.subscribable for g in all_groups) for x in item.also_limit): + more.append(item) + + if len(more) >= 3: + break + return { 'member': member, 'events': events, 'groups': groups_data, - 'more': [], # TODO + 'more': more, 'bulbegin': bulbegin, 'bulend': bulend }