Added a tiny management command to list group types per feature.

- Legacy-Id: 15918
This commit is contained in:
Henrik Levkowetz 2019-01-30 15:52:33 +00:00
parent 95fe1ae729
commit 5d88a0805b
3 changed files with 43 additions and 0 deletions

View file

View file

@ -0,0 +1,43 @@
# Copyright The IETF Trust 2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
import collections
from django.core.management.base import BaseCommand
from django.db.models.fields import BooleanField
import debug # pyflakes:ignore
from ietf.group.models import GroupFeatures
class Command(BaseCommand):
help = "Show group features"
def handle(self, *filenames, **options):
self.verbosity = options['verbosity']
hasfeature = {}
hasrole = {}
# By property:
for field in GroupFeatures.objects.first()._meta.fields:
if isinstance(field, BooleanField):
hasfeature[field.name] = []
else:
hasrole[field.name] = collections.defaultdict(list)
for f in GroupFeatures.objects.all():
for field in f._meta.fields:
value = getattr(f, field.name)
if value == True:
hasfeature[field.name].append(str(f.type.slug))
elif isinstance(value, list):
for role in value:
hasrole[field.name][role].append(str(f.type.slug))
for k,v in sorted(hasfeature.items()):
print("%-24s: %s" % (k, sorted(v)))
print("")
for k,roles in sorted(hasrole.items()):
if roles and 'roles' in k:
print("%s:" % k)
for r, v in sorted(roles.items()):
print("%16s%-8s: %s" % ('', r, sorted(v)))