Updated the makeresources command to use the current AppCommand.handle_app_config() interface.

- Legacy-Id: 13306
This commit is contained in:
Henrik Levkowetz 2017-05-10 20:08:40 +00:00
parent bea447c21c
commit 405f76f238
4 changed files with 56 additions and 14 deletions

View file

@ -3,12 +3,12 @@ from __future__ import print_function
import os
import datetime
import collections
from importlib import import_module
import debug # pyflakes:ignore
from django.core.management.base import AppCommand
from django.db import models
from django.utils.importlib import import_module
from django.template import Template, Context
from tastypie.resources import ModelResource
@ -53,16 +53,17 @@ def render(template, dictionary):
class Command(AppCommand):
def handle_app(self, app, **options):
if app.__package__:
print("\nInspecting %s .." % app.__package__)
resource_file_path = os.path.join(os.path.dirname(app.__file__), "resources.py")
def handle_app_config(self, app, **options):
# dotted path to app
if app.name:
print("\nInspecting %s .." % app.name)
resource_file_path = os.path.join(app.path, "resources.py")
app_models = models.get_models(app)
app_models = app.get_models()
app_resources = {}
if os.path.exists(resource_file_path):
resources = import_module("%s.resources" % app.__package__)
resources = import_module("%s.resources" % app.name)
for n,v in resources.__dict__.items():
if issubclass(type(v), type(ModelResource)):
app_resources[n] = v
@ -76,11 +77,11 @@ class Command(AppCommand):
do_update_resources = True
if do_update_resources:
print("Updating resources.py for %s" % app.__package__)
print("Updating resources.py for %s" % app.name)
with open(resource_file_path, "a") as rfile:
info = dict(
app=app.__package__,
app_label=app.__package__.split('.')[-1],
app=app.name,
app_label=app.label,
date=datetime.datetime.now()
)
new_models = {}
@ -106,7 +107,7 @@ class Command(AppCommand):
if rel_model_name == model_name:
# foreign key to self class -- quote
# the rmodel_name
rmodel_name="'%s.resources.%sResource'" % (app.__package__, rel_model_name)
rmodel_name="'%s.resources.%sResource'" % (app.name, rel_model_name)
else:
rmodel_name=rel_model_name+"Resource"
foreign_keys.append(dict(
@ -134,7 +135,7 @@ class Command(AppCommand):
if rel_model_name == model_name:
# foreign key to self class -- quote
# the rmodel_name
rmodel_name="'%s.resources.%sResource'" % (app.__package__, rel_model_name)
rmodel_name="'%s.resources.%sResource'" % (app.name, rel_model_name)
else:
rmodel_name=rel_model_name+"Resource"
m2m_keys.append(dict(
@ -158,7 +159,7 @@ class Command(AppCommand):
for k in imports:
imports[k]["names"] = set(imports[k]["names"])
new_models[model_name] = dict(
app=app.__package__.split('.')[-1],
app=app.name.split('.')[-1],
model=model,
fields=model._meta.fields,
m2m_fields=model._meta.many_to_many,
@ -215,4 +216,4 @@ class Command(AppCommand):
info.update(dict(models=new_model_list))
rfile.write(render(resource_class_template, info))
else:
print(" nothing to do for %s" % app.__package__)
print(" nothing to do for %s" % app.name)

View file

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-05-04 13:15
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('doc', '0027_auto_20170412_0528'),
]
operations = [
migrations.CreateModel(
name='EditedAuthorsDocEvent',
fields=[
('docevent_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='doc.DocEvent')),
('basis', models.CharField(help_text=b'What is the source or reasoning for the changes to the author list', max_length=255)),
],
bases=('doc.docevent',),
),
migrations.AlterField(
model_name='docevent',
name='type',
field=models.CharField(choices=[(b'new_revision', b'Added new revision'), (b'new_submission', b'Uploaded new revision'), (b'changed_document', b'Changed document metadata'), (b'added_comment', b'Added comment'), (b'added_message', b'Added message'), (b'edited_authors', b'Edited the documents author list'), (b'deleted', b'Deleted document'), (b'changed_state', b'Changed state'), (b'changed_stream', b'Changed document stream'), (b'expired_document', b'Expired document'), (b'extended_expiry', b'Extended expiry of document'), (b'requested_resurrect', b'Requested resurrect'), (b'completed_resurrect', b'Completed resurrect'), (b'changed_consensus', b'Changed consensus'), (b'published_rfc', b'Published RFC'), (b'added_suggested_replaces', b'Added suggested replacement relationships'), (b'reviewed_suggested_replaces', b'Reviewed suggested replacement relationships'), (b'changed_group', b'Changed group'), (b'changed_protocol_writeup', b'Changed protocol writeup'), (b'changed_charter_milestone', b'Changed charter milestone'), (b'initial_review', b'Set initial review time'), (b'changed_review_announcement', b'Changed WG Review text'), (b'changed_action_announcement', b'Changed WG Action text'), (b'started_iesg_process', b'Started IESG process on document'), (b'created_ballot', b'Created ballot'), (b'closed_ballot', b'Closed ballot'), (b'sent_ballot_announcement', b'Sent ballot announcement'), (b'changed_ballot_position', b'Changed ballot position'), (b'changed_ballot_approval_text', b'Changed ballot approval text'), (b'changed_ballot_writeup_text', b'Changed ballot writeup text'), (b'changed_rfc_editor_note_text', b'Changed RFC Editor Note text'), (b'changed_last_call_text', b'Changed last call text'), (b'requested_last_call', b'Requested last call'), (b'sent_last_call', b'Sent last call'), (b'scheduled_for_telechat', b'Scheduled for telechat'), (b'iesg_approved', b'IESG approved document (no problem)'), (b'iesg_disapproved', b'IESG disapproved document (do not publish)'), (b'approved_in_minute', b'Approved in minute'), (b'iana_review', b'IANA review comment'), (b'rfc_in_iana_registry', b'RFC is in IANA registry'), (b'rfc_editor_received_announcement', b'Announcement was received by RFC Editor'), (b'requested_publication', b'Publication at RFC Editor requested'), (b'sync_from_rfc_editor', b'Received updated information from RFC Editor'), (b'requested_review', b'Requested review'), (b'assigned_review_request', b'Assigned review request'), (b'closed_review_request', b'Closed review request'), (b'downref_approved', b'Downref approved')], max_length=50),
),
]

View file

@ -840,6 +840,7 @@ EVENT_TYPES = [
("changed_document", "Changed document metadata"),
("added_comment", "Added comment"),
("added_message", "Added message"),
("edited_authors", "Edited the documents author list"),
("deleted", "Deleted document"),
@ -1068,3 +1069,10 @@ class DeletedEvent(models.Model):
def __unicode__(self):
return u"%s by %s %s" % (self.content_type, self.by, self.time)
class EditedAuthorsDocEvent(DocEvent):
""" Capture the reasoning or authority for changing a document author list.
Allows programs to recognize and not change lists that have been manually verified and corrected.
Example 'basis' values might be from ['manually adjusted','recomputed by parsing document', etc.]
"""
basis = models.CharField(help_text="What is the source or reasoning for the changes to the author list",max_length=255)

View file

@ -602,3 +602,7 @@ class ReviewRequestDocEventResource(ModelResource):
}
api.doc.register(ReviewRequestDocEventResource())