Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / management / commands / group-list.py @ def409e0

History | View | Annotate | Download (2 kB)

1 9d20fe23 Kostas Papadimitriou
# Copyright 2012 GRNET S.A. All rights reserved.
2 9d20fe23 Kostas Papadimitriou
#
3 9d20fe23 Kostas Papadimitriou
# Redistribution and use in source and binary forms, with or
4 9d20fe23 Kostas Papadimitriou
# without modification, are permitted provided that the following
5 9d20fe23 Kostas Papadimitriou
# conditions are met:
6 9d20fe23 Kostas Papadimitriou
#
7 9d20fe23 Kostas Papadimitriou
#   1. Redistributions of source code must retain the above
8 9d20fe23 Kostas Papadimitriou
#      copyright notice, this list of conditions and the following
9 9d20fe23 Kostas Papadimitriou
#      disclaimer.
10 9d20fe23 Kostas Papadimitriou
#
11 9d20fe23 Kostas Papadimitriou
#   2. Redistributions in binary form must reproduce the above
12 9d20fe23 Kostas Papadimitriou
#      copyright notice, this list of conditions and the following
13 9d20fe23 Kostas Papadimitriou
#      disclaimer in the documentation and/or other materials
14 9d20fe23 Kostas Papadimitriou
#      provided with the distribution.
15 9d20fe23 Kostas Papadimitriou
#
16 9d20fe23 Kostas Papadimitriou
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 9d20fe23 Kostas Papadimitriou
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 9d20fe23 Kostas Papadimitriou
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 9d20fe23 Kostas Papadimitriou
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 9d20fe23 Kostas Papadimitriou
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 9d20fe23 Kostas Papadimitriou
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 9d20fe23 Kostas Papadimitriou
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 9d20fe23 Kostas Papadimitriou
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 9d20fe23 Kostas Papadimitriou
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 9d20fe23 Kostas Papadimitriou
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 9d20fe23 Kostas Papadimitriou
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 9d20fe23 Kostas Papadimitriou
# POSSIBILITY OF SUCH DAMAGE.
28 9d20fe23 Kostas Papadimitriou
#
29 9d20fe23 Kostas Papadimitriou
# The views and conclusions contained in the software and
30 9d20fe23 Kostas Papadimitriou
# documentation are those of the authors and should not be
31 9d20fe23 Kostas Papadimitriou
# interpreted as representing official policies, either expressed
32 9d20fe23 Kostas Papadimitriou
# or implied, of GRNET S.A.
33 9d20fe23 Kostas Papadimitriou
34 9d20fe23 Kostas Papadimitriou
from astakos.im.models import Group
35 7cfc0cef Christos Stavrakakis
from snf_django.management.commands import ListCommand
36 9d20fe23 Kostas Papadimitriou
37 9d20fe23 Kostas Papadimitriou
38 ffb5cca1 Sofia Papagiannaki
def users_count(group):
39 ffb5cca1 Sofia Papagiannaki
    return group.user_set.count()
40 ffb5cca1 Sofia Papagiannaki
41 ffb5cca1 Sofia Papagiannaki
42 fc5138f0 Sofia Papagiannaki
class Command(ListCommand):
43 9d20fe23 Kostas Papadimitriou
    help = "List available groups"
44 9d20fe23 Kostas Papadimitriou
45 fc5138f0 Sofia Papagiannaki
    object_class = Group
46 9d20fe23 Kostas Papadimitriou
47 fc5138f0 Sofia Papagiannaki
    FIELDS = {
48 fc5138f0 Sofia Papagiannaki
        'id': ('id', 'The id of the group'),
49 fc5138f0 Sofia Papagiannaki
        'name': ('name', 'The name of the group'),
50 fc5138f0 Sofia Papagiannaki
        'users_count': (users_count, 'The number of the group users'),
51 fc5138f0 Sofia Papagiannaki
    }
52 9d20fe23 Kostas Papadimitriou
53 fc5138f0 Sofia Papagiannaki
    fields = ['id', 'name', 'users_count']