From f15ab5b4dd3e53403e0749d82983718996f2e2ea Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Tue, 16 Jan 2024 15:51:13 -0700 Subject: [PATCH] 66 - Upload Form in Item Detail View --- src/items/models.py | 4 + src/items/views.py | 2 + src/static/css/cfehome-ui.css | 32 +++++ src/templates/items/detail.html | 13 +- src/templates/items/file-upload.html | 111 +--------------- .../items/snippets/object-table.html | 41 +++++- src/templates/items/snippets/upload.html | 123 ++++++++++++++++++ 7 files changed, 206 insertions(+), 120 deletions(-) create mode 100644 src/templates/items/snippets/upload.html diff --git a/src/items/models.py b/src/items/models.py index 57b068f..5c0bfac 100644 --- a/src/items/models.py +++ b/src/items/models.py @@ -53,6 +53,10 @@ def get_files_url(self): # return f"/items/{self.id}/" return reverse("items:files", kwargs={"id": self.id}) + def get_upload_url(self): + # return f"/items/{self.id}/" + return reverse("items:upload", kwargs={"id": self.id}) + def get_edit_url(self): # return f"/items/{self.id}/" return reverse("items:edit", kwargs={"id": self.id}) diff --git a/src/items/views.py b/src/items/views.py index 41b1aba..25e7c5e 100644 --- a/src/items/views.py +++ b/src/items/views.py @@ -41,6 +41,8 @@ def item_upload_view(request, id=None): # detail_url = instance.get_absolute_url() # return redirect(detail_url) template_name = 'items/file-upload.html' + if request.htmx: + template_name = 'items/snippets/upload.html' if request.method == "POST": print(request.POST) file_name = request.POST.get('file_name') diff --git a/src/static/css/cfehome-ui.css b/src/static/css/cfehome-ui.css index 0471ae6..ba25d4e 100644 --- a/src/static/css/cfehome-ui.css +++ b/src/static/css/cfehome-ui.css @@ -1563,6 +1563,14 @@ input:checked + .toggle-bg { max-height: 80vh; } +.max-h-\[10vh\] { + max-height: 10vh; +} + +.max-h-10 { + max-height: 2.5rem; +} + .w-1\/2 { width: 50%; } @@ -1743,6 +1751,12 @@ input:checked + .toggle-bg { margin-bottom: calc(1rem * var(--tw-space-y-reverse)); } +.space-y-2 > :not([hidden]) ~ :not([hidden]) { + --tw-space-y-reverse: 0; + margin-top: calc(0.5rem * calc(1 - var(--tw-space-y-reverse))); + margin-bottom: calc(0.5rem * var(--tw-space-y-reverse)); +} + .divide-y > :not([hidden]) ~ :not([hidden]) { --tw-divide-y-reverse: 0; border-top-width: calc(1px * calc(1 - var(--tw-divide-y-reverse))); @@ -2053,6 +2067,11 @@ input:checked + .toggle-bg { line-height: 1rem; } +.text-3xl { + font-size: 1.875rem; + line-height: 2.25rem; +} + .font-extrabold { font-weight: 800; } @@ -2065,6 +2084,10 @@ input:checked + .toggle-bg { font-weight: 600; } +.font-bold { + font-weight: 700; +} + .uppercase { text-transform: uppercase; } @@ -2256,6 +2279,10 @@ input:checked + .toggle-bg { text-decoration-line: underline; } +.focus\:z-10:focus { + z-index: 10; +} + .focus\:border-0:focus { border-width: 0px; } @@ -2527,6 +2554,11 @@ input:checked + .toggle-bg { --tw-ring-color: rgb(30 58 138 / var(--tw-ring-opacity)); } +:is(.dark .dark\:focus\:ring-gray-700:focus) { + --tw-ring-opacity: 1; + --tw-ring-color: rgb(55 65 81 / var(--tw-ring-opacity)); +} + @media (min-width: 640px) { .sm\:flex-row { flex-direction: row; diff --git a/src/templates/items/detail.html b/src/templates/items/detail.html index bc5f4d4..a18e366 100644 --- a/src/templates/items/detail.html +++ b/src/templates/items/detail.html @@ -4,15 +4,22 @@ {% block content %}
-
+
+
+
-

{{ instance.title }}

-

{{ instance.get_prefix }}

+

{{ instance.title }}

+ {% if instance.description %} +
{{ instance.description|linebreaks }}
+ {% endif %} diff --git a/src/templates/items/file-upload.html b/src/templates/items/file-upload.html index a5c45f9..aa6d277 100644 --- a/src/templates/items/file-upload.html +++ b/src/templates/items/file-upload.html @@ -5,116 +5,7 @@
- -
- - - -
- + {% include 'items/snippets/upload.html' with instance=instance %}
- - {% endblock content %} \ No newline at end of file diff --git a/src/templates/items/snippets/object-table.html b/src/templates/items/snippets/object-table.html index af4736e..d9ab57b 100644 --- a/src/templates/items/snippets/object-table.html +++ b/src/templates/items/snippets/object-table.html @@ -1,12 +1,35 @@ + + + + +
+ + + + + + + + + + + {% for object_dict in object_list %} + + -
- {{ object_dict.name }} - {% if object_dict.is_image %} - - {% endif %} - Download +
+ + {% endfor %} + +
+ File + + Actions +
+ {% if object_dict.is_image %} + + {% endif %} {{ object_dict.name }} + + + Download View in Browser {% if instance %}
-{% endfor %} \ No newline at end of file diff --git a/src/templates/items/snippets/upload.html b/src/templates/items/snippets/upload.html new file mode 100644 index 0000000..5641431 --- /dev/null +++ b/src/templates/items/snippets/upload.html @@ -0,0 +1,123 @@ +
+ +
+ + + + + + + + +
+
+ + + \ No newline at end of file