Changed notifications helper to properly use the fact that from_user is not a required property.
The list template has changed to reflect this. The naming is open for discussion but note that if it is decided to change it that it also needs to be changed in the public.html template.
Patch by: Lennard de Rijk
Reviewed by: to-be-reviewed
--- a/app/soc/logic/helper/notifications.py Sun Mar 15 20:58:39 2009 +0000
+++ b/app/soc/logic/helper/notifications.py Sun Mar 15 22:32:05 2009 +0000
@@ -86,7 +86,9 @@
template = DEF_GROUP_INVITE_NOTIFICATION_TEMPLATE
- sendNotification(to_user, message_properties, subject, template)
+ from_user = model_logic.user.logic.getForCurrentAccount()
+
+ sendNotification(to_user, from_user, message_properties, subject, template)
def sendNewGroupNotification(entity, params):
@@ -118,23 +120,28 @@
template = DEF_NEW_GROUP_TEMPLATE
- sendNotification(to_user, message_properties, subject, template)
+ sendNotification(to_user, None, message_properties, subject, template)
-def sendNotification(to_user, message_properties, subject, template):
- """Sends out an notification to the specified user.
+def sendNotification(to_user, from_user, message_properties, subject, template):
+ """Sends out a notification to the specified user.
Args:
to_user : user to which the notification will be send
- message_properties : email message properties
+ from_user: user from who sends the notifications (None iff sent by site)
+ message_properties : message properties
subject : subject of notification email
template : template used for generating notification
"""
- from_user = model_logic.user.logic.getForCurrentAccount()
+ if from_user:
+ sender_name = from_user.name
+ else:
+ site_entity = model_logic.site.logic.getSingleton()
+ sender_name = 'The %s Team' %(site_entity.site_name)
new_message_properties = {
- 'sender_name': from_user.name,
+ 'sender_name': sender_name,
'to_name': to_user.name,
}
--- a/app/soc/templates/soc/notification/list/row.html Sun Mar 15 20:58:39 2009 +0000
+++ b/app/soc/templates/soc/notification/list/row.html Sun Mar 15 22:32:05 2009 +0000
@@ -1,7 +1,13 @@
<tr class="off" onmouseover="this.className='on'" onmouseout="this.className='off'"
onclick="document.location.href='{{ list.redirect }}'" name="name">
<td align="right"><div class="name"><a class="noul"
- href="{{ list.redirect }}">{{ list.item.from_user.name }}</a>
+ href="{{ list.redirect }}">
+ {% if list.item.from_user %}
+ {{ list.item.from_user.name }}
+ {% else %}
+ Anonymous
+ {% endif %}
+ </a>
</div>
</td>
<td><div class="subject">{{ list.item.subject }}</div></td>