datatracker/ietf/name/generate_fixtures.py
Henrik Levkowetz 2daef52bea This commit replaces the code defined group features with features held
in a database table:

- Added a GroupFeatures model to the group models, and removed the old 
  features.py
- Added a agenda type for future use in showing different group types on
  different agendas.
- Renamed the group feature has_materials to has_nonsession_materials.
- Added API resources and admin support for the new tables.
- Added a Directorate (with reviews) group type as complement to
  Directorate, to distinguish between directorates with and without reviews.
- Adjusted tests as needed.
- Updated the fixtures, and fixed the generate_fixtures script to include
  the new AgendaTypeName objects.

There still exists about 70 instances of code comparing the group type
with a list of types; most of these should probably be replaced with new
features, instead, to make it possible to add new group types through the
database table, rather than having to edit the code.  That was the purpose
of this refactoring from the start, but the presence of this large number
of comparisons of group type against lists of types defeats the goal until
we add appropriate features and replace the group type list comparisons.
 - Legacy-Id: 15316
2018-07-12 10:51:48 +00:00

58 lines
1.6 KiB
Python

#!/usr/bin/python
# simple script for exporting name related base data for the tests
# boiler plate
import os, sys
import django
basedir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../..'))
sys.path.insert(0, basedir)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings")
django.setup()
# script
from django.core.serializers import serialize
def output(name, seq):
try:
f = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures/%s.json" % name), 'w')
f.write(serialize("json", seq, indent=1))
f.close()
except:
from django.db import connection
from pprint import pprint
pprint(connection.queries)
raise
# pick all name models directly out of the module
objects = []
import inspect
import ietf.name.models
for n in dir(ietf.name.models):
symbol = getattr(ietf.name.models, n)
if inspect.isclass(symbol) and issubclass(symbol, ietf.name.models.NameModel):
if not symbol._meta.abstract:
objects.extend(symbol.objects.all())
import ietf.doc.models # also pick some other name-like types while we're at it
objects += ietf.doc.models.StateType.objects.all()
objects += ietf.doc.models.State.objects.all()
objects += ietf.doc.models.BallotType.objects.all()
import ietf.group.models
objects += ietf.group.models.GroupFeatures.objects.all()
import ietf.mailtrigger.models
objects += ietf.mailtrigger.models.Recipient.objects.all()
objects += ietf.mailtrigger.models.MailTrigger.objects.all()
import ietf.utils.models
objects += ietf.utils.models.VersionInfo.objects.all()
output("names", objects)