comparison rhodecode/model/notification.py @ 1716:7d1fc253549e beta

notification to commit author + gardening
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 23 Nov 2011 22:46:14 +0200
parents 54687aa00724
children 7ff304d3028f
comparison
equal deleted inserted replaced
1715:e1e482093077 1716:7d1fc253549e
34 from rhodecode.model import BaseModel 34 from rhodecode.model import BaseModel
35 from rhodecode.model.db import Notification, User, UserNotification 35 from rhodecode.model.db import Notification, User, UserNotification
36 36
37 log = logging.getLogger(__name__) 37 log = logging.getLogger(__name__)
38 38
39
39 class NotificationModel(BaseModel): 40 class NotificationModel(BaseModel):
40 41
41 42
42 def __get_user(self, user): 43 def __get_user(self, user):
43 if isinstance(user, User): 44 if isinstance(user, basestring):
44 return user
45 elif isinstance(user, basestring):
46 return User.get_by_username(username=user) 45 return User.get_by_username(username=user)
47 elif isinstance(user, int):
48 return User.get(user)
49 else: 46 else:
50 raise Exception('Unsupported user must be one of int,' 47 return self._get_instance(User, user)
51 'str or User object')
52 48
53 def __get_notification(self, notification): 49 def __get_notification(self, notification):
54 if isinstance(notification, Notification): 50 if isinstance(notification, Notification):
55 return notification 51 return notification
56 elif isinstance(notification, int): 52 elif isinstance(notification, int):
80 76
81 created_by_obj = self.__get_user(created_by) 77 created_by_obj = self.__get_user(created_by)
82 78
83 recipients_objs = [] 79 recipients_objs = []
84 for u in recipients: 80 for u in recipients:
85 recipients_objs.append(self.__get_user(u)) 81 obj = self.__get_user(u)
82 if obj:
83 recipients_objs.append(obj)
86 recipients_objs = set(recipients_objs) 84 recipients_objs = set(recipients_objs)
87 return Notification.create(created_by=created_by_obj, subject=subject, 85 return Notification.create(created_by=created_by_obj, subject=subject,
88 body=body, recipients=recipients_objs, 86 body=body, recipients=recipients_objs,
89 type_=type_) 87 type_=type_)
90 88