|
| 1 | +# Copyright The IETF Trust 2019, All Rights Reserved |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +from __future__ import unicode_literals, print_function |
| 4 | + |
| 5 | +import collections |
| 6 | + |
| 7 | +from django.core.management.base import BaseCommand |
| 8 | +from django.db.models.fields import BooleanField |
| 9 | + |
| 10 | +import debug # pyflakes:ignore |
| 11 | + |
| 12 | +from ietf.group.models import GroupFeatures |
| 13 | + |
| 14 | +class Command(BaseCommand): |
| 15 | + help = "Show group features" |
| 16 | + |
| 17 | + def handle(self, *filenames, **options): |
| 18 | + self.verbosity = options['verbosity'] |
| 19 | + hasfeature = {} |
| 20 | + hasrole = {} |
| 21 | + # By property: |
| 22 | + for field in GroupFeatures.objects.first()._meta.fields: |
| 23 | + if isinstance(field, BooleanField): |
| 24 | + hasfeature[field.name] = [] |
| 25 | + else: |
| 26 | + hasrole[field.name] = collections.defaultdict(list) |
| 27 | + for f in GroupFeatures.objects.all(): |
| 28 | + for field in f._meta.fields: |
| 29 | + value = getattr(f, field.name) |
| 30 | + if value == True: |
| 31 | + hasfeature[field.name].append(str(f.type.slug)) |
| 32 | + elif isinstance(value, list): |
| 33 | + for role in value: |
| 34 | + hasrole[field.name][role].append(str(f.type.slug)) |
| 35 | + for k,v in sorted(hasfeature.items()): |
| 36 | + print("%-24s: %s" % (k, sorted(v))) |
| 37 | + print("") |
| 38 | + for k,roles in sorted(hasrole.items()): |
| 39 | + if roles and 'roles' in k: |
| 40 | + print("%s:" % k) |
| 41 | + for r, v in sorted(roles.items()): |
| 42 | + print("%16s%-8s: %s" % ('', r, sorted(v))) |
| 43 | + |
0 commit comments