Store and display port notes

This commit is contained in:
arjunsalyan
2020-08-03 13:12:25 +05:30
committed by Arjun Salyan
parent e98583f217
commit 1fe32d7942
5 changed files with 65 additions and 2 deletions
+27
View File
@@ -0,0 +1,27 @@
import io
import subprocess
from port.models import Port
def get_notes_all_ports():
# Limiting the fields that are selected
# This ensures that the updated_at field does not get updated
# Because changes to a port's notes are not considered as an update
for port in Port.objects.all().only('name', 'notes'):
get_notes(port)
return
def get_notes(port):
try:
output = subprocess.run(["port", "notes", port.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = output.stdout.decode('utf-8')
except OSError:
return
result_lines = io.StringIO(result)
# maintain linebreaks in the field that is saved to database using
port.notes = "<br>".join(result_lines)
port.save()
+11
View File
@@ -0,0 +1,11 @@
from django.core.management.base import BaseCommand
from parsing_scripts import get_notes
class Command(BaseCommand):
help = "Fetches notes using the 'port notes' command and saves in database"
def handle(self, *args, **options):
get_notes.get_notes_all_ports()
+18
View File
@@ -0,0 +1,18 @@
# Generated by Django 2.2.10 on 2020-07-26 07:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('port', '0007_port_version_updated_at'),
]
operations = [
migrations.AddField(
model_name='port',
name='notes',
field=models.TextField(null=True),
),
]
+1
View File
@@ -37,6 +37,7 @@ class Port(models.Model):
name = models.CharField(max_length=100, db_index=True)
license = models.CharField(max_length=100, default='')
replaced_by = models.CharField(max_length=100, null=True)
notes = models.TextField(null=True)
active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
+8 -2
View File
@@ -88,7 +88,7 @@
</div>
{% endfor %}
</div>
<br><br>
<br>
{% endif %}
{% endwith %}
<h4 class="border-bottom">"{{ port.name }}" depends on</h4>
@@ -106,7 +106,7 @@
{% else %}
<p>No ports</p>
{% endif %}
<br><br>
<br>
<h4 class="border-bottom">Ports that depend on "{{ port.name }}"</h4>
{% if dependents|length > 0 %}
{% for d in dependents %}
@@ -124,6 +124,12 @@
{% else %}
<p>No ports</p>
{% endif %}
<br>
{% if port.notes %}
<h4 class="border-bottom">Port notes</h4>
{{ port.notes|safe }}
<br>
{% endif %}
</div>
<div class="col-lg-4">
<div>