From 37fae3c6556797952166350d2d2021bbea47a726 Mon Sep 17 00:00:00 2001 From: Pawel Solyga Date: Sun, 16 Nov 2008 12:48:23 +0000 Subject: [PATCH] Add an e-mail dispatcher that can be used to send messages via the website. Add base and invitation templates that can be used with email dispatcher to send invitation emails. Please read the module doc string for more information how to use it. Patch by: Lennard de Rijk, Pawel Solyga --- app/soc/logic/dicts.py | 25 +++++- app/soc/logic/mail_dispatcher.py | 118 +++++++++++++++++++++++++++++ app/soc/templates/soc/mail/base.html | 40 ++++++++++ app/soc/templates/soc/mail/invitation.html | 19 +++++ 4 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 app/soc/logic/mail_dispatcher.py create mode 100644 app/soc/templates/soc/mail/base.html create mode 100644 app/soc/templates/soc/mail/invitation.html diff --git a/app/soc/logic/dicts.py b/app/soc/logic/dicts.py index 24aa8ac2..95d991a8 100644 --- a/app/soc/logic/dicts.py +++ b/app/soc/logic/dicts.py @@ -19,11 +19,31 @@ __authors__ = [ '"Sverre Rabbelier" ', + '"Lennard de Rijk" ', ] +def filter(target, keys): + """Filters a dictonary to only allow items with the given keys. + + Args: + target: The dictionary that is to be filtered + keys: The list with keys to filter the dictionary on + + Returns: + A dictionary that only contains the (key,value) from target that have their key in keys + """ + result = {} + + for key, value in target.iteritems(): + if key in keys: + result[key] = value + + return result + + def merge(target, updates): - """Like the builtin 'update' method but does not overwrite existing values + """Like the builtin 'update' method but does not overwrite existing values. Args: target: The dictionary that is to be updated, may be None @@ -42,8 +62,9 @@ def merge(target, updates): return target + def zip(keys, values): - """Returns a dict containing keys with values + """Returns a dict containing keys with values. If there are more items in keys than in values, None will be used. If there are more items in values than in keys, they will be ignored. diff --git a/app/soc/logic/mail_dispatcher.py b/app/soc/logic/mail_dispatcher.py new file mode 100644 index 00000000..3b819550 --- /dev/null +++ b/app/soc/logic/mail_dispatcher.py @@ -0,0 +1,118 @@ +#!/usr/bin/python2.5 +# +# Copyright 2008 the Melange authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Functions used to send email messages. + +The following are the possible fields of an email message: + + sender: The email address of the sender, the From address. This must be the + email address of a registered administrator for the application, or the + address of the current signed-in user. Administrators can be added to + an application using the Administration Console. The current user's email + address can be determined with the Users API. + to: A recipient's email address (a string) or a list of email addresses to + appear on the To: line in the message header. + cc: A recipient's email address (a string) or a list of email addresses to + appear on the Cc: line in the message header. + bcc: A recipient's email address (a string) or a list of email addresses to + receive the message, but not appear in the message header ("blind carbon + copy"). + reply_to: An email address to which a recipient should reply instead of the + sender address, the Reply-To: field. + subject: The subject of the message, the Subject: line. + body: The plaintext body content of the message. + html: An HTML version of the body content, for recipients that + prefer HTML email. + attachments: The file attachments for the message, as a list of two-value + tuples, one tuple for each attachment. Each tuple contains a filename as + the first element, and the file contents as the second element. + An attachment file must be one of the allowed file types, and the + filename must end with an extension that corresponds with the type. + For a list of allowed types and filename extensions, see Allowed + Attachment Types. + +Usage: + + context = { 'sender': 'melange-noreply@foo.com', + 'to': 'bob@bar.com', + 'subject': 'You have been invited to become a Host', + 'sender_name': 'Alice', + 'to_name': 'Melange Team', + 'role': 'Host', + 'group': 'Google Summer of Code 2009', + 'invitation_url': 'http://invitation-url'} + + sendMailUsingTemplate('soc/mail/invitation.html', context) +""" + +__authors__ = [ + '"Lennard de Rijk" ', + '"Pawel Solyga" + + + + + + +
+

+ {% block greeting %} + Hi {{ to_name }}, + {% endblock %} +

+
+ +
+

{% block content %}{% endblock %}

+
+ +
+

+ {% block signature %}Greetings,
{{ sender_name }}{% endblock %} +

+
+ + + diff --git a/app/soc/templates/soc/mail/invitation.html b/app/soc/templates/soc/mail/invitation.html new file mode 100644 index 00000000..0ed4e139 --- /dev/null +++ b/app/soc/templates/soc/mail/invitation.html @@ -0,0 +1,19 @@ +{% extends "soc/mail/base.html" %} +{% comment %} +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +{% endcomment %} + +{% block content %} +You have been invited by {{ sender_name }} to become a {{ role }} for {{ group }}. +Please click here to fill in the necessary information and accept the invitation. +{% endblock %} -- 2.11.4.GIT