aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc
diff options
context:
space:
mode:
Diffstat (limited to 'pyblackbird_cc')
-rw-r--r--pyblackbird_cc/resources/forms.py38
-rw-r--r--pyblackbird_cc/resources/models.py26
-rw-r--r--pyblackbird_cc/resources/urls.py5
-rw-r--r--pyblackbird_cc/resources/views.py23
-rw-r--r--pyblackbird_cc/templates/resources/resource_detail.html18
-rw-r--r--pyblackbird_cc/templates/resources/resource_metadata_update.html26
6 files changed, 109 insertions, 27 deletions
diff --git a/pyblackbird_cc/resources/forms.py b/pyblackbird_cc/resources/forms.py
index f905811..da27fd4 100644
--- a/pyblackbird_cc/resources/forms.py
+++ b/pyblackbird_cc/resources/forms.py
@@ -5,8 +5,12 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
from django import forms
-from .models import ResourceCategory
-from .models import ResourceType
+from pyblackbird_cc.resources.models import Resource
+from pyblackbird_cc.resources.models import ResourceCategory
+from pyblackbird_cc.resources.models import ResourceType
+
+from .models import AGE_RANGE_CHOICES
+from .models import CURRICULUM_CHOICES
logger = logging.getLogger(__name__)
@@ -50,24 +54,12 @@ class ResourceCreateForm(forms.Form):
)
resource_type = forms.ModelChoiceField(queryset=ResourceType.objects.all())
age_range = forms.ChoiceField(
- choices=[
- ("3-5", "3-5"),
- ("5-7", "5-7"),
- ("7-11", "7-11"),
- ("11-14", "11-14"),
- ("14-16", "14-16"),
- ("16+", "16+"),
- ("Age not applicable", "Age not applicable"),
- ],
+ choices=AGE_RANGE_CHOICES,
help_text="Try to be accurate in your choice of age range so that your resource "
"shows up in the correct searches. (Although we don't have searches yet!)",
)
curriculum = forms.ChoiceField(
- choices=[
- ("No curriculum", "No curriculum"),
- ("English", "English"),
- ("Scottish", "Scottish"),
- ],
+ choices=CURRICULUM_CHOICES,
)
main_resource_category = forms.ModelChoiceField(
queryset=ResourceCategory.objects.all(),
@@ -137,3 +129,17 @@ class ResourceCreateForm(forms.Form):
if len(pdf_files) > ALLOWED_PDFS:
raise forms.ValidationError("Please select up to 20 PDF files.")
return pdf_files
+
+
+class ResourceUpdateMetadataForm(forms.ModelForm):
+ class Meta:
+ model = Resource
+ fields = [
+ "name",
+ "description",
+ "resource_type",
+ "age_range",
+ "curriculum",
+ "main_resource_category",
+ "additional_resource_category",
+ ]
diff --git a/pyblackbird_cc/resources/models.py b/pyblackbird_cc/resources/models.py
index 68f0637..b11bcb9 100644
--- a/pyblackbird_cc/resources/models.py
+++ b/pyblackbird_cc/resources/models.py
@@ -1,5 +1,21 @@
from django.db import models
+CURRICULUM_CHOICES = [
+ ("No curriculum", "No curriculum"),
+ ("English", "English"),
+ ("Scottish", "Scottish"),
+]
+
+AGE_RANGE_CHOICES = [
+ ("3-5", "3-5"),
+ ("5-7", "5-7"),
+ ("7-11", "7-11"),
+ ("11-14", "11-14"),
+ ("14-16", "14-16"),
+ ("16+", "16+"),
+ ("Age not applicable", "Age not applicable"),
+]
+
# Create your models here.
class Resource(models.Model):
@@ -28,15 +44,7 @@ class Resource(models.Model):
null=False,
default="5-7",
blank=False,
- choices=[
- ("3-5", "3-5"),
- ("5-7", "5-7"),
- ("7-11", "7-11"),
- ("11-14", "11-14"),
- ("14-16", "14-16"),
- ("16+", "16+"),
- ("Age not applicable", "Age not applicable"),
- ],
+ choices=AGE_RANGE_CHOICES,
)
curriculum = models.CharField(
max_length=20,
diff --git a/pyblackbird_cc/resources/urls.py b/pyblackbird_cc/resources/urls.py
index 30c5f99..86b3f4d 100644
--- a/pyblackbird_cc/resources/urls.py
+++ b/pyblackbird_cc/resources/urls.py
@@ -7,6 +7,11 @@ urlpatterns = [
path("", views.index, name="index"),
path("create/", views.create_resource, name="create_resource"),
path("resource/<int:resource_id>", views.resource_detail, name="resource_detail"),
+ path(
+ "resource/update-metadata/<int:pk>",
+ views.update_resource_metadata,
+ name="resource_update_metadata",
+ ),
]
htmx_patterns = [
diff --git a/pyblackbird_cc/resources/views.py b/pyblackbird_cc/resources/views.py
index c1d7672..e96e701 100644
--- a/pyblackbird_cc/resources/views.py
+++ b/pyblackbird_cc/resources/views.py
@@ -15,6 +15,7 @@ from django.shortcuts import render
from . import services
from .forms import ResourceCreateForm
+from .forms import ResourceUpdateMetadataForm
from .models import PDFPageSnapshot
from .models import PDFResource
from .models import Resource
@@ -357,3 +358,25 @@ def hx_download_button(request):
"resources/hx_download_button.html",
{"pdf_url": _extract_metadata_from_resource(res).pdf_url},
)
+
+
+@login_required
+def update_resource_metadata(request, pk): # Change resource_id to pk
+ resource = get_object_or_404(Resource, pk=pk)
+
+ if request.method == "POST":
+ form = ResourceUpdateMetadataForm(request.POST, instance=resource)
+ if form.is_valid():
+ form.save()
+ return redirect(
+ "resources:resource_detail",
+ resource_id=resource.pk,
+ ) # Use pk instead of resource_id
+ else:
+ form = ResourceUpdateMetadataForm(instance=resource)
+
+ return render(
+ request,
+ "resources/resource_metadata_update.html",
+ {"form": form, "resource": resource},
+ )
diff --git a/pyblackbird_cc/templates/resources/resource_detail.html b/pyblackbird_cc/templates/resources/resource_detail.html
index 6daa42b..70c1b11 100644
--- a/pyblackbird_cc/templates/resources/resource_detail.html
+++ b/pyblackbird_cc/templates/resources/resource_detail.html
@@ -19,8 +19,22 @@
<span class="fw-bold">Number of files:</span> X NUMBER OF FILES
</div>
</div>
- <div>
- <span class="fw-bold">Created:</span> {{ resource.created|date:"D d M Y" }}
+ <div class="d-flex flex-row justify-content-between my-3 flex-wrap">
+ <div>
+ <span class="fw-bold">Created:</span> {{ resource.created|date:"D d M Y" }}
+ </div>
+ <div>
+ {% if request.user.is_authenticated and request.user.is_staff %}
+ <a href="{% url "resources:resource_update_metadata" resource.id %}"
+ class="text-danger">Edit this resource</a>
+ {% endif %}
+ </div>
+ <div>
+ {% if request.user.is_authenticated %}<a href="#" class="text-danger">Replace the PDFs</a>{% endif %}
+ </div>
+ <div>
+ {% if request.user.is_authenticated %}<a href="#" class="text-danger">Replace the preview images</a>{% endif %}
+ </div>
</div>
</div>
</div>
diff --git a/pyblackbird_cc/templates/resources/resource_metadata_update.html b/pyblackbird_cc/templates/resources/resource_metadata_update.html
new file mode 100644
index 0000000..bb37ea1
--- /dev/null
+++ b/pyblackbird_cc/templates/resources/resource_metadata_update.html
@@ -0,0 +1,26 @@
+{% extends "base.html" %}
+
+{% load static %}
+{% load crispy_forms_tags %}
+
+{% block title %}
+ Joanna Lemon Resources - Update Resource
+{% endblock title %}
+{# {% block extra_css %}#}
+{# <link rel="stylesheet" href="{% static 'css/forms.css' %}">#}
+{# {% endblock %}#}
+{% block content %}
+ <div class="row d-flex justify-content-center">
+ <div class="col bg-light mt-lg-4 p-4 border border-success border-opacity-25 rounded">
+ <h2>Update this resource</h2>
+ <p>{% lorem %}</p>
+ <form action="{% url 'resources:resource_update_metadata' resource.id %}"
+ method="post">
+ {% csrf_token %}
+ {{ form|crispy }}
+ {# now for the submit button #}
+ <button type="submit" class="btn btn-primary">Submit</button>
+ </form>
+ </div>
+ </div>
+{% endblock content %}