Mercurial > kallithea
diff rhodecode/model/notification.py @ 2432:d3ac7491a5c8 codereview
Share common getter functions in base model, and remove duplicated functions from other models
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 09 Jun 2012 20:23:48 +0200 |
parents | 91fae60bf2b6 |
children | 74f2910f7ad9 |
line wrap: on
line diff
--- a/rhodecode/model/notification.py Sat Jun 09 18:10:59 2012 +0200 +++ b/rhodecode/model/notification.py Sat Jun 09 20:23:48 2012 +0200 @@ -42,9 +42,6 @@ class NotificationModel(BaseModel): - def __get_user(self, user): - return self._get_instance(User, user, callback=User.get_by_username) - def __get_notification(self, notification): if isinstance(notification, Notification): return notification @@ -77,12 +74,12 @@ if recipients and not getattr(recipients, '__iter__', False): raise Exception('recipients must be a list of iterable') - created_by_obj = self.__get_user(created_by) + created_by_obj = self._get_user(created_by) if recipients: recipients_objs = [] for u in recipients: - obj = self.__get_user(u) + obj = self._get_user(u) if obj: recipients_objs.append(obj) recipients_objs = set(recipients_objs) @@ -126,7 +123,7 @@ # we don't want to remove actual notification just the assignment try: notification = self.__get_notification(notification) - user = self.__get_user(user) + user = self._get_user(user) if notification and user: obj = UserNotification.query()\ .filter(UserNotification.user == user)\ @@ -140,29 +137,29 @@ raise def get_for_user(self, user): - user = self.__get_user(user) + user = self._get_user(user) return user.notifications def mark_all_read_for_user(self, user): - user = self.__get_user(user) + user = self._get_user(user) UserNotification.query()\ .filter(UserNotification.read == False)\ .update({'read': True}) def get_unread_cnt_for_user(self, user): - user = self.__get_user(user) + user = self._get_user(user) return UserNotification.query()\ .filter(UserNotification.read == False)\ .filter(UserNotification.user == user).count() def get_unread_for_user(self, user): - user = self.__get_user(user) + user = self._get_user(user) return [x.notification for x in UserNotification.query()\ .filter(UserNotification.read == False)\ .filter(UserNotification.user == user).all()] def get_user_notification(self, user, notification): - user = self.__get_user(user) + user = self._get_user(user) notification = self.__get_notification(notification) return UserNotification.query()\