forked from sydney-linux-user-group/slug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_publish.py
89 lines (65 loc) · 2.19 KB
/
event_publish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
#
# -*- coding: utf-8 -*-
# vim: set ts=4 sw=4 et sts=4 ai:
"""Module for creating and editing Event objects."""
import config
config.setup()
# Python Imports
# AppEngine Imports
from google.appengine.api import mail
from google.appengine.api import users
from google.appengine.ext import webapp
# Third Party imports
# Our App imports
import models
import logging
# We don't want to wrap this line as we use a grep to extract the details
# pylint: disable-msg=C0301
extensions = ['abbr', 'footnotes', 'def_list', 'fenced_code', 'tables', 'subscript', 'superscript', 'slugheader', 'anyurl']
def prep_values(key=None):
user = users.get_current_user()
if key:
try:
key = long(key)
event = models.Event.get_by_id(key)
assert event
# pylint: disable-msg=W0702
except (AssertionError, ValueError):
event = None
else:
event = None
return user, event
class SendEmailAboutEvent(webapp.RequestHandler):
def post(self, key=None):
user, event = prep_values(key)
if not user or not event or event.published:
self.redirect("/events")
message = mail.EmailMessage()
message.sender = "[email protected]"
message.to = "[email protected]"
message.body = event.plaintext
message.html = event.html
if event.emailed:
# This is an update
message.subject = "Updated: %s " % event.name
else:
message.subject = event.name
message.send()
logging.info("Sent email. Subject: %s | To: %s | Body: %s",
message.subject, message.to, message.body)
event.emailed = True
event.put()
self.redirect("/events")
class PublishEvent(webapp.RequestHandler):
def post(self, key=None):
user, event = prep_values(key)
if user and event:
announcement = models.Announcement(
name=event.name,
plaintext=event.plaintext,
html=event.html)
event.announcement = announcement.put()
event.published = True
event.put()
self.redirect('/events')