def test_add_notification(self): data = {'data': 'some data here'} for i, uid in enumerate(self.uids[:10], start=1): Notification(uid, self.receivers, data).send() assert len(Notification.get_data(self.test_user1)) == i assert Notification.unread_count(self.test_user1) == i assert len(Notification.get_data(self.test_user2)) == i assert Notification.unread_count(self.test_user2) == i
def _q_index(request): user = request.user if user: all = request.get_form_var('all') scope = request.get_form_var('scope') unread = not all or all != '1' scope = ActionScope.getScope(scope) or '' # 不带scope则默认所有 actions = Notification.get_data(user.name) # 迁移数据 all_actions = [migrate_notif_data(action, user.name) for action in actions] if scope: actions = [action for action in all_actions if action.get('scope') == scope] else: actions = all_actions if unread: actions = [action for action in actions if not action.get('read')] count_dict = {s: len([a for a in all_actions if a.get('scope') == s and not a.get('read')]) for s in ActionScope.all_scopes} else: count_dict = {s: len([a for a in all_actions if a.get('scope') == s]) for s in ActionScope.all_scopes} count_dict['all'] = sum(count_dict.values()) return st('notifications.html', **locals()) else: return request.redirect("/hub/teams")
def test_get_data(self): for i, uid in enumerate(self.uids[:10], start=1): data = {'data': 'test' + uid} Notification(uid, self.receivers, data).send() data = Notification.get_data(self.test_user1) assert len(data) == 10 for i, d in enumerate(reversed(data)): assert d.get('uid') == self.uids[i] assert d.get('data') == 'test'+self.uids[i]
def _q_index(request): start = request.get_form_var('start', '0') limit = request.get_form_var('count', '20') if start.isdigit() and limit.isdigit(): start = int(start) limit = int(limit) else: start = 0 limit = 20 user = request.user notifications = Notification.get_data(user.name) return notifications[start:(start+limit)]
def _q_index(request): start = request.get_form_var('start', '0') limit = request.get_form_var('count', '20') if start.isdigit() and limit.isdigit(): start = int(start) limit = int(limit) else: start = 0 limit = 20 user = request.user notifications = Notification.get_data(user.name) return notifications[start:(start + limit)]