Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docgenerator: Added support for JSON, instead of XML, as a schema's f…
…ormat. A schema that's documented by this system can now be in JSON format. Previously this system assumed every documented format was XML. The new models JSONObject and JSONObjectRelationship contain the meat of the metadata about all of the objects and keys within a JSON format. These models are roughly analogous to the existing XMLElement and XMLRelationship models. I originally tried to shoehorn JSON into the existing XMLElement model, but that ended up being very confusing -- hence the totally separate models. There are two new Django views, json_object_list and json_object_detail. These work similarly to the existing element_list and element_detail. Example pages now properly support JSON formats, inserting the appropriate deep links to doc pages for each element key/value. The json_object_detail page also has an 'Examples' section, linking to each example document in which that particular JSON object is used. Note that this commit is purely the infrastructure for the docs system and doesn't include the actual changes to MNX (to convert it from XML into a JSON format). That will come in a subsequent commit.
- Loading branch information
1 parent
fc54356
commit 641cfc6
Showing
10 changed files
with
435 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Generated by Django 4.1.5 on 2023-03-14 11:19 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('spec', '0030_auto_20211105_1029'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='xmlschema', | ||
name='is_json', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AlterField( | ||
model_name='datatype', | ||
name='union_types', | ||
field=models.ManyToManyField(blank=True, help_text='If this data type is a union of multiple other types, list them here.', related_name='+', to='spec.datatype'), | ||
), | ||
migrations.CreateModel( | ||
name='JSONObject', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=80)), | ||
('slug', models.CharField(max_length=80)), | ||
('object_type', models.SmallIntegerField(choices=[(1, 'Dictionary'), (2, 'Array'), (3, 'String'), (4, 'Number'), (5, 'Boolean'), (6, 'Literal string')])), | ||
('schema', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='spec.xmlschema')), | ||
], | ||
options={ | ||
'verbose_name': 'JSON object', | ||
'verbose_name_plural': 'JSON objects', | ||
'db_table': 'json_objects', | ||
'unique_together': {('schema', 'slug')}, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='ExampleDocumentObject', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('example', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='spec.exampledocument')), | ||
('json_object', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='spec.jsonobject')), | ||
], | ||
options={ | ||
'db_table': 'example_objects', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='JSONObjectRelationship', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('child_key', models.CharField(max_length=80)), | ||
('is_required', models.BooleanField(default=False)), | ||
('child', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='child_rel', to='spec.jsonobject')), | ||
('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='parent_rel', to='spec.jsonobject')), | ||
], | ||
options={ | ||
'verbose_name': 'JSON object relationship', | ||
'verbose_name_plural': 'JSON object relationships', | ||
'db_table': 'json_object_relationships', | ||
'unique_together': {('parent', 'child_key')}, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %}The {{ object.name }} object{% endblock %} | ||
|
||
{% block content %} | ||
<p class="breadcrumb"> | ||
<a href="{% relative_url 'homepage' %}">{{ SITE_OPTIONS.site_name }}</a> > | ||
<a href="{% relative_url_string object.schema.reference_url %}">{{ object.schema.name }} reference</a> > | ||
<a href="{% relative_url_string object.schema.json_objects_url %}">Objects</a> > | ||
{{ object.name }} | ||
</p> | ||
|
||
<h1>The {{ object.name }} object</h1> | ||
|
||
<p><b>Type:</b> {{ object.pretty_object_type }}</p> | ||
|
||
{% if child_relationships %} | ||
<h2>Keys:</h2> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Type</th> | ||
<th>Required?</th> | ||
<th>Description</th> | ||
</tr> | ||
</thead> | ||
|
||
{% for rel in child_relationships %} | ||
<tr> | ||
<td>"{{ rel.child_key }}"</td> | ||
<td> | ||
{% if rel.child.is_array %} | ||
An array of | ||
{% for childrel in rel.child.get_child_relationships %} | ||
<a href="{% relative_url_string childrel.child.get_absolute_url %}">{{ childrel.child.name }} objects</a>{% if not forloop.last %}, {% endif %} | ||
{% endfor %} | ||
{% else %} | ||
<a href="{% relative_url_string rel.child.get_absolute_url %}">{{ rel.child.name }} object</a> | ||
{% endif %} | ||
</td> | ||
<td>{{ rel.is_required|yesno|title }}</td> | ||
<td></td> | ||
</tr> | ||
{% endfor %} | ||
|
||
</table> | ||
{% endif %} | ||
|
||
{% if examples %} | ||
<h2 id="examples">Examples</h2> | ||
|
||
<p>This element is used in the following examples:</p> | ||
<p> | ||
{% for example in examples %}<nobr><a href="{% relative_url_string example.example.get_absolute_url %}">{{ example.example.name }}</a></nobr>{% if not forloop.last %}, {% endif %}{% endfor %} | ||
</p> | ||
{% endif %} | ||
|
||
{% endblock %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %}Objects used in {{ schema.name }}{% endblock %} | ||
|
||
{% block content %} | ||
<p class="breadcrumb"> | ||
<a href="{% relative_url 'homepage' %}">{{ SITE_OPTIONS.site_name }}</a> > | ||
<a href="{% relative_url_string schema.reference_url %}">{{ schema.name }} reference</a> > | ||
Objects | ||
</p> | ||
|
||
<h1>Objects used in {{ schema.name }}</h1> | ||
|
||
<p><a href="{% relative_url_string schema.element_tree_url %}">Tree view</a> | <b>Alphabetical list</b></p> | ||
|
||
<ul> | ||
{% for object in objects %} | ||
<li><a href="{% relative_url_string object.get_absolute_url %}">{{ object.name }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.