Skip to content

Commit

Permalink
revert #86 , this is not the way to do it.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hetti committed Jul 14, 2018
1 parent d189929 commit c139733
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mos/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
HOS_NAME = 'Metalab OS'
HOS_HOME_EVENT_NUM = 5
HOS_WIKI_URL = '/wiki/'
MEDIAWIKI_API = HOS_WIKI_URL + "api.php"
HOS_ANNOUNCE_FROM = 'core@metalab.at'
HOS_SEPA_CREDITOR_ID = 'AT12ZZZ00000000001'

Expand All @@ -143,3 +144,9 @@
HOS_INTRODUCTION = True
HOS_PROJECTS = True
HOS_RECENT_CHANGES = True

# ----------------- Jour Fixe Reminder ------------
MOS_JF_DAYS_IN_ADVANCE = 3
MOS_JF_DB_ID = 2 # id of events of type "Jour Fixe" in the database
MOS_JF_SENDER = 'core@metalab.at'
MOS_JF_RECIPIENTS = ['intern@lists.metalab.at']
3 changes: 3 additions & 0 deletions mos/settings/devel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@
MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)

HOS_SEPA_CREDITOR_ID = 'AT29HXR00000037632'

HOS_WIKI_URL = "https://metalab.at/wiki/"
MEDIAWIKI_API = HOS_WIKI_URL + "api.php"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ django-extensions
python-dateutil
freezegun
feedparser
requests
64 changes: 64 additions & 0 deletions sources/management/commands/jour_fixe_reminder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from django.core.management.base import NoArgsCommand, CommandError
from django.conf import settings
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.core.mail import send_mail
from django.template.loader import get_template
from django.template import Context
from cal.models import Event
import datetime, requests

# TODO: does this handle timezones correctly?
# TODO: send a warning mail to core if the next jour fixe does not have a wiki page

def get_next_jf():
when = datetime.date.today() + datetime.timedelta(days = settings.MOS_JF_DAYS_IN_ADVANCE)
try:
# FIXME: django too old, this doesn't work yet: startDate__date = when
return Event.objects.get(category_id = settings.MOS_JF_DB_ID,
startDate__year = when.year,
startDate__month = when.month,
startDate__day = when.day)
except MultipleObjectsReturned as e:
raise e # FIXME: Ehhhhh. Multiple Jour fixes in the calendar for the same date.
except ObjectDoesNotExist:
return None

def get_wiki_article(article):
query = {"action": "parse", "page": article, "format": "json"}
return requests.get(settings.MEDIAWIKI_API, params = query).json()

def get_wiki_headlines(article):
article = get_wiki_article(article)
if article.get("error", False):
return {"article_missing": True, "error": True, "headlines": []}

results = []
skip = True
for heading in article["parse"]["sections"]:
if heading["toclevel"] == 1:
skip = heading["anchor"] != "Themen"
continue
if skip:
continue
results.append(heading["line"])

return {"article_missing": False, "error": len(results) == 0, "headlines": results}

def mail(template, ctx_vars):
tpl = get_template(template)
ctx = Context(ctx_vars)
msg = tpl.render(ctx)
sub = ''.join(get_template(template + ".subject").render(ctx).splitlines())
send_mail(sub, msg,
settings.MOS_JF_SENDER,
settings.MOS_JF_RECIPIENTS,
fail_silently=False)

class Command(NoArgsCommand):
help = 'Send the Jour Fixe reminder email, if a Jour Fixe is in settings.MOS_JF_DAYS_IN_ADVANCE days'
def handle_noargs(self, **options):
next_jf = get_next_jf()
if not next_jf:
return
ctx = { 'jf': next_jf, 'wiki': get_wiki_headlines(next_jf.wikiPage) }
mail("jour_fixe_reminder.mail", ctx)
23 changes: 23 additions & 0 deletions templates/jour_fixe_reminder.mail
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% load i18n %}{% language 'de' %}Liebe Leute,

Am {{ jf.startDate | date:"l" }} den {{ jf.startDate | date:"Y-m-d" }} um {{ jf.startDate | date:"H:i" }} gibt es einen Jour Fixe.

{% if wiki.article_missing %}
Leider gibt es dazu keinen Wiki-Artikel. Das bedeutet wahrscheinlich, dass der
Jour Fixe ausfällt. Die Deadline für neue Themen ist nämlich vorbei.
{% elif wiki.error %}
Leider hat der Wiki-Artikel das falsche Format und kann nicht geparst werden,
oder es ist ein anderer Fehler beim lesen des Artikels aufgetreten. Wenn das MOS
den Artikel nicht lesen kann, kannst du ihn sicher auch nicht lesen ;)
Du kannst es aber versuchen.
{% else %}Folgende Themen wurden bisher im Wiki eingetragen:
{% for heading in wiki.headlines %}
* {{ heading }}{% if heading == "Thema1 (you)" %} - bitte löscht diese Boilerplate-Themen raus, wenn ihr ein Thema anlegt.{% endif %}{% endfor %}

Laut einer gottgegebenen Regel müssen Jour-Fixe-Themen mindestens 3 Tage vor dem
Termin eingetragen sein, wenn du also noch Vorschläge hast, bitte nimm sie mit
zum nächsten Jour Fixe.
{% endif %}
Wiki Page: https://metalab.at/wiki/{{ jf.wikiPage }}

<3 dein MOS{% endlanguage %}
4 changes: 4 additions & 0 deletions templates/jour_fixe_reminder.mail.subject
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% language 'de' %}
[REMINDER] Jour Fixe am {{ jf.startDate | date:"l, Y-m-d" }}
{% endlanguage %}

0 comments on commit c139733

Please sign in to comment.