diff --git a/app/parsing_scripts/get_notes.py b/app/parsing_scripts/get_notes.py
new file mode 100644
index 0000000..8d0ff3b
--- /dev/null
+++ b/app/parsing_scripts/get_notes.py
@@ -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 = "
".join(result_lines)
+ port.save()
diff --git a/app/port/management/commands/get-notes.py b/app/port/management/commands/get-notes.py
new file mode 100644
index 0000000..e692e6a
--- /dev/null
+++ b/app/port/management/commands/get-notes.py
@@ -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()
diff --git a/app/port/migrations/0008_port_notes.py b/app/port/migrations/0008_port_notes.py
new file mode 100644
index 0000000..8527653
--- /dev/null
+++ b/app/port/migrations/0008_port_notes.py
@@ -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),
+ ),
+ ]
diff --git a/app/port/models.py b/app/port/models.py
index 1f5a106..cd00f90 100644
--- a/app/port/models.py
+++ b/app/port/models.py
@@ -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)
diff --git a/app/port/templates/port/port_details.html b/app/port/templates/port/port_details.html
index 49f7260..dc5368b 100644
--- a/app/port/templates/port/port_details.html
+++ b/app/port/templates/port/port_details.html
@@ -88,7 +88,7 @@
{% endfor %}
-
+
{% endif %}
{% endwith %}
No ports
{% endif %} -No ports
{% endif %} +