comparison rhodecode/model/notification.py @ 2082:0e27da019f84 beta

code garden
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 01 Mar 2012 02:52:46 +0200
parents 179604334d98
children 8ecfed1d8f8b
comparison
equal deleted inserted replaced
2081:249c151e3d7d 2082:0e27da019f84
167 """ 167 """
168 Creates a human readable description based on properties 168 Creates a human readable description based on properties
169 of notification object 169 of notification object
170 """ 170 """
171 171
172 _map = {notification.TYPE_CHANGESET_COMMENT:_('commented on commit'), 172 _map = {
173 notification.TYPE_MESSAGE:_('sent message'), 173 notification.TYPE_CHANGESET_COMMENT: _('commented on commit'),
174 notification.TYPE_MENTION:_('mentioned you'), 174 notification.TYPE_MESSAGE: _('sent message'),
175 notification.TYPE_REGISTRATION:_('registered in RhodeCode')} 175 notification.TYPE_MENTION: _('mentioned you'),
176 notification.TYPE_REGISTRATION: _('registered in RhodeCode')
177 }
176 178
177 DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" 179 DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
178 180
179 tmpl = "%(user)s %(action)s %(when)s" 181 tmpl = "%(user)s %(action)s %(when)s"
180 if show_age: 182 if show_age:
181 when = h.age(notification.created_on) 183 when = h.age(notification.created_on)
182 else: 184 else:
183 DTF = lambda d: datetime.datetime.strftime(d, DATETIME_FORMAT) 185 DTF = lambda d: datetime.datetime.strftime(d, DATETIME_FORMAT)
184 when = DTF(notification.created_on) 186 when = DTF(notification.created_on)
185 data = dict(user=notification.created_by_user.username, 187 data = dict(
186 action=_map[notification.type_], 188 user=notification.created_by_user.username,
187 when=when) 189 action=_map[notification.type_], when=when,
190 )
188 return tmpl % data 191 return tmpl % data
189 192
190 193
191 class EmailNotificationModel(BaseModel): 194 class EmailNotificationModel(BaseModel):
192 195
198 def __init__(self): 201 def __init__(self):
199 self._template_root = rhodecode.CONFIG['pylons.paths']['templates'][0] 202 self._template_root = rhodecode.CONFIG['pylons.paths']['templates'][0]
200 self._tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup 203 self._tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup
201 204
202 self.email_types = { 205 self.email_types = {
203 self.TYPE_CHANGESET_COMMENT:'email_templates/changeset_comment.html', 206 self.TYPE_CHANGESET_COMMENT: 'email_templates/changeset_comment.html',
204 self.TYPE_PASSWORD_RESET:'email_templates/password_reset.html', 207 self.TYPE_PASSWORD_RESET: 'email_templates/password_reset.html',
205 self.TYPE_REGISTRATION:'email_templates/registration.html', 208 self.TYPE_REGISTRATION: 'email_templates/registration.html',
206 self.TYPE_DEFAULT:'email_templates/default.html' 209 self.TYPE_DEFAULT: 'email_templates/default.html'
207 } 210 }
208 211
209 def get_email_tmpl(self, type_, **kwargs): 212 def get_email_tmpl(self, type_, **kwargs):
210 """ 213 """
211 return generated template for email based on given type 214 return generated template for email based on given type
214 """ 217 """
215 218
216 base = self.email_types.get(type_, self.email_types[self.TYPE_DEFAULT]) 219 base = self.email_types.get(type_, self.email_types[self.TYPE_DEFAULT])
217 email_template = self._tmpl_lookup.get_template(base) 220 email_template = self._tmpl_lookup.get_template(base)
218 # translator inject 221 # translator inject
219 _kwargs = {'_':_} 222 _kwargs = {'_': _}
220 _kwargs.update(kwargs) 223 _kwargs.update(kwargs)
221 log.debug('rendering tmpl %s with kwargs %s' % (base, _kwargs)) 224 log.debug('rendering tmpl %s with kwargs %s' % (base, _kwargs))
222 return email_template.render(**_kwargs) 225 return email_template.render(**_kwargs)