From c8b98fbb5cd7278527a951ad6156acc5717328b2 Mon Sep 17 00:00:00 2001
From: Frank Sauerburger <frank@sauerburger.com>
Date: Mon, 10 May 2021 18:29:45 +0200
Subject: [PATCH] Add preliminary design

---
 uhepp_org/uhepp_vault/forms.py                |  7 ++++++
 .../migrations/0009_auto_20210409_1516.py     | 23 +++++++++++++++++++
 uhepp_org/uhepp_vault/models.py               |  1 +
 .../templates/uhepp_vault/plot_detail.html    | 12 ++++++++++
 uhepp_org/uhepp_vault/views.py                |  6 +++--
 5 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 uhepp_org/uhepp_vault/migrations/0009_auto_20210409_1516.py

diff --git a/uhepp_org/uhepp_vault/forms.py b/uhepp_org/uhepp_vault/forms.py
index 1022de6..e892c0a 100644
--- a/uhepp_org/uhepp_vault/forms.py
+++ b/uhepp_org/uhepp_vault/forms.py
@@ -1,5 +1,6 @@
 from django import forms
 from django.utils.translation import gettext_lazy as _
+from . import models
 
 class TokenForm(forms.Form):
     description = forms.CharField(label=_('Description'), max_length=100)
@@ -22,3 +23,9 @@ class CollectionPermForm(forms.BaseForm):
         self.declared_fields = self.base_fields
 
         super().__init__(*args, **kwds)
+
+class PlotForm(forms.ModelForm):
+    class Meta:
+        model = models.Plot
+        fields = ["comment"]
+
diff --git a/uhepp_org/uhepp_vault/migrations/0009_auto_20210409_1516.py b/uhepp_org/uhepp_vault/migrations/0009_auto_20210409_1516.py
new file mode 100644
index 0000000..0e9b150
--- /dev/null
+++ b/uhepp_org/uhepp_vault/migrations/0009_auto_20210409_1516.py
@@ -0,0 +1,23 @@
+# Generated by Django 3.1.7 on 2021-04-09 15:16
+
+from django.db import migrations, models
+import django.db.models.functions.text
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('uhepp_vault', '0008_auto_20210223_1620'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='collection',
+            options={'ordering': ['-activity', django.db.models.functions.text.Lower('title')]},
+        ),
+        migrations.AddField(
+            model_name='plot',
+            name='comment',
+            field=models.TextField(blank=True, null=True),
+        ),
+    ]
diff --git a/uhepp_org/uhepp_vault/models.py b/uhepp_org/uhepp_vault/models.py
index 4b54c9e..61404e3 100644
--- a/uhepp_org/uhepp_vault/models.py
+++ b/uhepp_org/uhepp_vault/models.py
@@ -64,6 +64,7 @@ class Plot(models.Model):
     api_view_count = models.IntegerField(default=0)
     title = models.CharField(max_length=255, null=True, blank=True)
     uploaded = models.DateTimeField(auto_now_add=True)
+    comment = models.TextField(null=True, blank=True)
 
     collection = models.ForeignKey(
         Collection,
diff --git a/uhepp_org/uhepp_vault/templates/uhepp_vault/plot_detail.html b/uhepp_org/uhepp_vault/templates/uhepp_vault/plot_detail.html
index df1e857..50d470f 100644
--- a/uhepp_org/uhepp_vault/templates/uhepp_vault/plot_detail.html
+++ b/uhepp_org/uhepp_vault/templates/uhepp_vault/plot_detail.html
@@ -1,6 +1,7 @@
 {% extends 'uhepp_vault/base.html' %}
 {% load pygmentify_tags %}
 {% load humanize %}
+{% load crispy_forms_tags %}
 
 {% block title %}{{ plot.title }} - uhepp hub{% endblock %}
 
@@ -29,6 +30,7 @@
     </a>
   </span>
   {% endif %}</h1>
+
 <div class="d-none d-lg-inline text-muted">
     <i class="fas fa-eye"></i>
     {{ plot.view_count }} view{{ plot.view_count|pluralize }},
@@ -38,6 +40,7 @@
     </span>
 </div>
 
+
 <div class="d-flex">
 <span class="d-none d-md-inline">UUID: {{ plot.uuid }}</span>
 <div class="ml-auto btn-group btn-group-sm access-menu">
@@ -122,6 +125,15 @@ uhepp push {{ plot.collection.pk }} local_file.json</pre>
 </div>
 </div>
 
+<form method="POST" class="m-1 d-flex">
+  <textarea name="comment" cols="40" class="textarea form-control" id="id_comment" rows="2"></textarea>
+  <div>
+    <button class="btn btn-outline-secondary">
+        <i class="fas fa-save"></i>
+    </button>
+  </div>
+</form>
+
 
 <div id="app-root">
   <div class="d-flex justify-content-center my-5">
diff --git a/uhepp_org/uhepp_vault/views.py b/uhepp_org/uhepp_vault/views.py
index 529894c..28761d8 100644
--- a/uhepp_org/uhepp_vault/views.py
+++ b/uhepp_org/uhepp_vault/views.py
@@ -19,7 +19,7 @@ from uhepp_api.masks import MaskRelatedColletions
 from .models import PUBLIC_LEVEL, INTERNAL_LEVEL, PUBLIC_LEVEL, \
                     Collection, Plot, Profile
 
-from .forms import TokenForm
+from .forms import TokenForm, PlotForm
 
 def quantize(value, sig_digits):
     if value <= 100:
@@ -212,10 +212,12 @@ class PlotListView(generic.ListView):
             )
         return queryset
 
-class PlotDetail(generic.DetailView):
+class PlotDetail(generic.UpdateView):
     model = Plot
     slug_field = 'uuid'
     slug_url_kwarg = 'uuid'
+    fields = ["comment"]
+    template_name = 'uhepp_vault/plot_detail.html'
 
     def get_queryset(self):
         if self.request.user.is_anonymous:
-- 
GitLab