mirror of
https://github.com/macports/macports-webapp.git
synced 2026-07-13 03:18:42 -07:00
Store and display port notes
This commit is contained in:
committed by
Arjun Salyan
parent
e98583f217
commit
1fe32d7942
@@ -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()
|
||||
@@ -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()
|
||||
@@ -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),
|
||||
),
|
||||
]
|
||||
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user