Changed invitation email and into a notification.
authorLennard de Rijk <ljvderijk@gmail.com>
Wed, 17 Dec 2008 19:33:03 +0000
changeset 756 a0c0b48563cb
parent 755 1ed041c0cdc6
child 757 b11cee4ab535
Changed invitation email and into a notification. Also changed the public template for Notification to allow HTML code. Patch by: Lennard de Rijk
app/soc/logic/helper/notifications.py
app/soc/models/notification.py
app/soc/templates/soc/mail/invitation.html
app/soc/templates/soc/notification/messages/invitation.html
app/soc/templates/soc/notification/public.html
--- a/app/soc/logic/helper/notifications.py	Mon Dec 15 01:15:32 2008 +0000
+++ b/app/soc/logic/helper/notifications.py	Wed Dec 17 19:33:03 2008 +0000
@@ -22,10 +22,12 @@
   ]
 
 
+import time
 import os
 
 from google.appengine.api import users
 
+from django.template import loader
 from django.utils.translation import ugettext_lazy
 
 from soc.logic import mail_dispatcher
@@ -47,15 +49,14 @@
   """
   
   # get user logic
-  user_logic = model_logic.user
+  user_logic = model_logic.user.logic
 
   # get the current user
-  properties = {'account': users.get_current_user()}
-  current_user_entity = user_logic.logic.getForFields(properties, unique=True)
+  current_user_entity = user_logic.getForCurrentAccount()
   
   # get the user the request is for
   properties = {'link_id': entity.link_id }
-  request_user_entity = user_logic.logic.getForFields(properties, unique=True)
+  request_user_entity = user_logic.getForFields(properties, unique=True)
 
   # create the invitation_url
   invitation_url = "%(host)s%(index)s" % {
@@ -64,24 +65,37 @@
 
   # get the group entity
   group_entity = entity.scope
-
+  
+  # create the properties for the message
   messageProperties = {
       'to_name': request_user_entity.name,
       'sender_name': current_user_entity.name,
       'role': entity.role,
       'group': group_entity.name,
       'invitation_url': invitation_url,
-      'to': request_user_entity.account.email(),
-      'sender': current_user_entity.account.email(),
-      'subject': DEF_INVITATION_MSG_FMT % {
-          'role': entity.role,
-          'group': group_entity.name
+      }
+  
+  # render the message
+  message = loader.render_to_string('soc/notification/messages/invitation.html', dictionary=messageProperties)
+  
+  # create the fields for the notification
+  fields = { 
+      'from_user' : current_user_entity,
+      'subject' : DEF_INVITATION_MSG_FMT % {
+          'role' : entity.role,
+          'group' : group_entity.name 
           },
-      }
-
-  # send out the message using the default invitation template    
-  mail_dispatcher.sendMailFromTemplate('soc/mail/invitation.html', 
-                                       messageProperties)
+      'message' : message,
+      'scope' : request_user_entity,
+      'link_id' :'%i' % (time.time()),
+      'scope_path' : request_user_entity.link_id
+  }
+  
+  # create and put a new notification in the datastore
+  notification_logic = model_logic.notification.logic
+  notification_logic.updateOrCreateFromFields(fields, 
+      notification_logic.getKeyFieldsFromDict(fields))
+  
   
 def sendWelcomeMessage(user_entity):
   """Sends out a welcome message to a user.
--- a/app/soc/models/notification.py	Mon Dec 15 01:15:32 2008 +0000
+++ b/app/soc/models/notification.py	Wed Dec 17 19:33:03 2008 +0000
@@ -38,7 +38,7 @@
   from_user = db.ReferenceProperty(reference_class=soc.models.user.User,
       required=False,
       collection_name="sent_notifications",
-      verbose_name=ugettext_lazy('From User'))
+      verbose_name=ugettext_lazy('From'))
   
   subject = db.StringProperty(required=True,
       verbose_name=ugettext_lazy('Subject'))
--- a/app/soc/templates/soc/mail/invitation.html	Mon Dec 15 01:15:32 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-{% 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 %}
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-{% block content %}
-You have been invited by {{ sender_name }} to become a {{ role }} for {{ group }}.
-Please click <a href="{{ invitation_url }}">here</a> to fill in the necessary information and accept the invitation.
-{% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/notification/messages/invitation.html	Wed Dec 17 19:33:03 2008 +0000
@@ -0,0 +1,18 @@
+{% 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 <a href="{{ invitation_url }}">here</a> to fill in the necessary information and accept the invitation.
+{% endblock %}
--- a/app/soc/templates/soc/notification/public.html	Mon Dec 15 01:15:32 2008 +0000
+++ b/app/soc/templates/soc/notification/public.html	Wed Dec 17 19:33:03 2008 +0000
@@ -34,7 +34,14 @@
 {% readonly_field_as_table_row "To" entity.scope.name %}
 {% readonly_field_as_table_row "Sent On" entity.created_on %}
 {% readonly_field_as_table_row entity.fields.subject.label entity.subject %}
-{% readonly_multiline_field_as_table_row entity.fields.message.label entity.message %}
+
+<tr title="{{ field.help_text }}">
+ <td class="formfieldlabel">
+	{{ entity.fields.message.label }}:
+ </td>
+ <td class="formfieldvalue">
+	{{ entity.message|safe|linebreaks }}
+ </td>
 
 <tr>
   <td>