create generic jci links directly from measurables and intents

This commit is contained in:
Fred Pauchet 2018-03-14 15:14:37 +01:00
parent 33240d5974
commit a37625bc32
9 changed files with 146 additions and 13 deletions

Binary file not shown.

View File

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-03-14 13:53
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dms', '0005_auto_20180308_1623'),
]
operations = [
migrations.AlterField(
model_name='document',
name='jci_standard',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='documents', to='jci.Standard'),
),
]

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-03-14 14:01
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dms', '0006_auto_20180314_1453'),
]
operations = [
migrations.AddField(
model_name='version',
name='snapshot',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='version',
name='file',
field=models.FileField(blank=True, null=True, upload_to='revisions/'),
),
]

View File

@ -13,6 +13,8 @@ import pdfkit
from process.models import Approval
from process.exceptions import ActorException
from writer.models import Section
class Audience(ClosureModel):
name = models.CharField(max_length=50)
@ -79,7 +81,7 @@ class Document(models.Model):
type = models.ForeignKey(DocumentType)
created_at = models.DateTimeField(auto_now_add=True)
manager = models.ForeignKey(User)
jci_standard = models.ForeignKey('jci.Standard', related_name='documents')
jci_standard = models.ForeignKey('jci.Standard', related_name='documents', null=True, blank=True)
@property
def last_published_version(self):
@ -142,7 +144,13 @@ class Document(models.Model):
@reversion.create_revision()
def save(self, *args, **kwargs):
# todo : should create a default version based on the document type template.
super().save()
if not self.pk:
super().save() # obtains a new id for this document
self.create_new_version() # create a new empty version
for model_section in self.type.model_sections.all(): # create default sections
Section.create_from_model_section(model_section, self)
else:
super().save()
def to_pdf(self):
x = ""
@ -214,7 +222,8 @@ class Version(models.Model):
"""
# instance structure
document = models.ForeignKey(Document, related_name='versions')
file = models.FileField(upload_to='revisions/')
file = models.FileField(upload_to='revisions/', null=True, blank=True)
snapshot = models.TextField(blank=True, null=True)
# system fields
major = models.PositiveIntegerField()

View File

@ -55,6 +55,14 @@ def create_link(matchobj):
return '[' + matchobj.group(0) + '](/jci/standard/' + str(std_id) + '?measurable=' + measurable + ')'
def create_markdown_from_content(content):
str_list = [x for x in Chapter.objects.values_list('acronym', flat=True)]
regex_query = "(" + '|'.join(str_list) + ")(\.[0-9])*(\, ME [0-9])?"
modified_content = re.sub(regex_query, create_link, content)
return mark_safe(markdown(modified_content, safe_mode='escape'))
class Intent(models.Model):
content = models.TextField(max_length=16000)
@ -64,11 +72,7 @@ class Intent(models.Model):
return None
def get_message_as_markdown(self):
str_list = [x for x in Chapter.objects.values_list('acronym', flat=True)]
regex_query = "(" + '|'.join(str_list) + ")(\.[0-9])*(\, ME [0-9])?"
modified_content = re.sub(regex_query, create_link, self.content)
return mark_safe(markdown(modified_content, safe_mode='escape'))
return create_markdown_from_content(self.content)
class Standard(models.Model):
@ -101,6 +105,9 @@ class Measurable(models.Model):
def __str__(self):
return '{} ME {}'.format(self.standard, self.order)
def get_message_as_markdown(self):
return create_markdown_from_content(self.content)
class Meta:
unique_together = ('standard', 'order')
ordering = ('standard__headline__acronym', 'standard__order', 'order')

View File

@ -3,8 +3,17 @@
{% block "content" %}
<h2>{{ standard }}</h2>
{% if standard.measurables %}
<ul>
{% for measurable in standard.measurables.all %}
<li>{{ measurable }}
{{ measurable.get_message_as_markdown | safe }}</li>
{% endfor %}
</ul>
{% endif %}
{% if standard.intent %}
<h2><a href="{% url 'intent_details' standard.intent.id %}">Intent</a></h2>
{{ standard.intent.content }}
{{ standard.intent.get_message_as_markdown | safe }}
{% endif %}
{% endblock %}

View File

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-03-14 12:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('writer', '0005_modelsection_document_type'),
]
operations = [
migrations.AddField(
model_name='modelsection',
name='content',
field=models.TextField(default=' '),
preserve_default=False,
),
migrations.AddField(
model_name='modelsection',
name='order',
field=models.IntegerField(default=1),
preserve_default=False,
),
]

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-03-14 13:53
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('writer', '0006_auto_20180314_1356'),
]
operations = [
migrations.AlterModelOptions(
name='modelsection',
options={'ordering': ['order']},
),
]

View File

@ -3,20 +3,36 @@ from django.db import models
from django.utils.html import mark_safe
from markdown import markdown
from dms.models import Document, DocumentType
class ModelSection(models.Model):
title = models.CharField(max_length=255)
document_type = models.ForeignKey(DocumentType, related_name='model_sections')
order = models.IntegerField()
content = models.TextField()
document_type = models.ForeignKey('dms.DocumentType', related_name='model_sections')
class Meta:
ordering = ['order']
class Section(models.Model):
document = models.ForeignKey(Document, related_name='sections')
document = models.ForeignKey('dms.Document', related_name='sections')
order = models.IntegerField()
title = models.CharField(max_length=255)
content = models.TextField()
@staticmethod
def create_from_model_section(model_section, current_document):
section = Section.objects.create(
title=model_section.title,
order=model_section.order,
content=model_section.content,
document=current_document
)
section.save()
return section
def get_message_as_markdown(self):
return mark_safe(markdown(self.content, safe_mode='escape'))