def test_get_users_data(self): """ Test parsing xml with user data """ data, base_avatar_url = utils.get_users_data() self.assertDictEqual( data, { '176': { 'avatar': '/api/images/users/176', 'name': 'Adrian Kruszewski'}, '141': { 'avatar': '/api/images/users/141', 'name': u'Adam Pie\u015bkiewicz', }, } ) main.app.config.update({'DATA_PATH': 'noexistspath'}) self.assertEqual(({}, None), utils.get_users_data())
def users_view(): """ Sorted users listing for dropdown. """ data = get_users_data() result = [{ 'user_id': i, 'name': data[i].get('name', 'User {0}'.format(i)), } for i in data.keys()] result.sort(key=lambda x: x['name'], cmp=locale.strcoll) return result
def test_get_users_data(self): """Test returned data from xml""" data = utils.get_users_data() self.assertDictEqual(data, { '10': { u'avatar': u'https://intranet.stxnext.pl/api/images/users/165', u'name': 'Rando M.', }, '11': { u'avatar': u'https://intranet.stxnext.pl/api/images/users/151', u'name': 'Not F.', } })
def users_view(): """Users listing for dropdown.""" data = get_users_data() result = [ { 'user_id': user, 'name': user_data['name'], 'avatar': user_data['avatar'] } for user, user_data in data.iteritems() ] return result
def users_data_view(user_id): """ Returns user's real name and link to avatar. """ data = get_users_data() if user_id not in data: log.debug('User %s not found!', user_id) abort(404) return { 'real_name': data[user_id].get('name', None), 'avatar': data[user_id].get('avatar', None), }
def users_view(): """Users listing for dropdown.""" data = get_users_data() result = [ { 'user_id': user, 'name': user_data['name'], 'avatar': user_data['avatar'] } for user, user_data in data.iteritems() ] result = sorted(result, key=lambda k: k['name'], cmp=locale.strcoll) return result
def employees_in_year_month(year, month): """ Returns top 5 employees in month and year. It returns structure like this: data = [ { 'presence_time': 118402, 'id': 11, 'name': 'User 11', 'avatar': None }, { 'presence_time': 78217, 'id': 10, 'name': 'Jan P.', 'avatar': 'https://intranet.stxnext.pl/api/images/users/10' }, { 'presence_time': 0, 'id': 12, 'name': 'Patryk G.', 'avatar': 'https://intranet.stxnext.pl/api/images/users/12' }, ] """ data = get_data() result = [] year_month = '{0}-{1:02}'.format(year, month) for user_id in data: grouped = group_by_month_and_year(data[user_id]) result.append({ 'id': user_id, 'presence_time': sum(grouped[year_month]), }) result.sort(key=lambda x: x['presence_time'], reverse=True) result = result[:5] users_data = get_users_data() for user in result: user_id = user['id'] user.update( name=users_data[user_id].get('name', 'User {0}'.format(user_id)), avatar=users_data[user_id].get('avatar', None), ) return result
def users_view(): """ Users listing for dropdown. """ data, avatar_base_url = get_users_data() sort_users = data.keys() locale.setlocale(locale.LC_ALL, "") sort_users.sort( key=lambda user_id: data[user_id]['name'], cmp=locale.strcoll ) locale.setlocale(locale.LC_ALL, "C") return [ dict( user_id=user_id, name=data[user_id]['name'], avatar='%s%s' % ( avatar_base_url, data[user_id]['avatar'] ), ) for user_id in sort_users ]