66 |
66 |
67 from django.template import loader |
67 from django.template import loader |
68 |
68 |
69 from google.appengine.api import mail |
69 from google.appengine.api import mail |
70 |
70 |
71 from soc.logic import accounts |
|
72 from soc.logic import dicts |
71 from soc.logic import dicts |
73 |
72 |
74 |
73 |
75 def sendMailFromTemplate(template, context): |
74 def sendMailFromTemplate(template, context): |
76 """Sends out an email using a Django template. |
75 """Sends out an email using a Django template. |
117 |
116 |
118 # send the message |
117 # send the message |
119 message.send() |
118 message.send() |
120 |
119 |
121 def getDefaultMailSender(): |
120 def getDefaultMailSender(): |
122 """Returns the email address that currently can be used to send emails. |
121 """Returns the sender that currently can be used to send emails. |
123 |
122 |
124 Returns: |
123 Returns: |
125 - If available the noreply email address from the site singleton |
124 - A tuple containing (sender_name, sender_address) |
126 - Or the email address of the current logged in User |
125 Consisting of: |
|
126 - If available the site name and noreply address from the site singleton |
|
127 - Or the public name and email address of the current logged in User |
127 - None if there is no address to return |
128 - None if there is no address to return |
128 """ |
129 """ |
129 |
130 |
130 import logging |
131 import logging |
131 |
132 |
132 from google.appengine.api import users |
133 from soc.logic import accounts |
133 |
134 from soc.logic.models import user as user_logic |
134 from soc.logic.models import site as site_logic |
135 from soc.logic.models import site as site_logic |
135 |
136 |
136 |
137 # check if there is a noreply email address set |
137 site_entity = site_logic.logic.getSingleton() |
138 site_entity = site_logic.logic.getSingleton() |
138 |
139 |
139 if site_entity.noreply_email: |
140 if site_entity.noreply_email: |
140 return site_entity.noreply_email |
141 return (site_entity.site_name, site_entity.noreply_email) |
141 |
142 |
142 # use the email address of the current logged in user |
143 # use the email address of the current logged in user |
143 account_entity = users.get_current_user() |
144 user_entity = user_logic.logic.getForCurrentAccount() |
144 |
145 |
145 if not account_entity: |
146 if not user_entity: |
146 logging.warning('Non-Authenticated user triggered getDefaultMailSender') |
147 logging.warning('Non-Authenticated user triggered getDefaultMailSender') |
147 return None |
148 return None |
148 |
149 |
149 return accounts.denormalizeAccount(account_entity).email() |
150 # denormalize the account and retrieve the email |
|
151 sender = accounts.denormalizeAccount(account_entity).email() |
|
152 |
|
153 return (user_entity.name, sender) |