aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources
diff options
context:
space:
mode:
Diffstat (limited to 'pyblackbird_cc/resources')
-rw-r--r--pyblackbird_cc/resources/forms.py1
-rw-r--r--pyblackbird_cc/resources/models.py4
-rw-r--r--pyblackbird_cc/resources/tests/test_models.py4
-rw-r--r--pyblackbird_cc/resources/tests/test_views.py14
-rw-r--r--pyblackbird_cc/resources/views.py10
5 files changed, 27 insertions, 6 deletions
diff --git a/pyblackbird_cc/resources/forms.py b/pyblackbird_cc/resources/forms.py
index 9320a77..75d23b4 100644
--- a/pyblackbird_cc/resources/forms.py
+++ b/pyblackbird_cc/resources/forms.py
@@ -157,4 +157,5 @@ class ResourceUpdateMetadataForm(forms.ModelForm):
"curriculum",
"main_resource_category",
"additional_resource_category",
+ "feature_slot",
]
diff --git a/pyblackbird_cc/resources/models.py b/pyblackbird_cc/resources/models.py
index 27d74e7..44a5024 100644
--- a/pyblackbird_cc/resources/models.py
+++ b/pyblackbird_cc/resources/models.py
@@ -73,7 +73,9 @@ class Resource(models.Model):
("Scottish", "Scottish"),
],
)
- feature_slot = models.IntegerField(choices=((1, 1), (2, 2), (3, 3)), unique=True, null=True)
+ feature_slot = models.IntegerField(
+ choices=((1, 1), (2, 2), (3, 3)), unique=True, null=True, blank=True
+ )
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
diff --git a/pyblackbird_cc/resources/tests/test_models.py b/pyblackbird_cc/resources/tests/test_models.py
index ec420ae..2e45d39 100644
--- a/pyblackbird_cc/resources/tests/test_models.py
+++ b/pyblackbird_cc/resources/tests/test_models.py
@@ -15,10 +15,6 @@ from pyblackbird_cc.resources.models import ResourceType
from pyblackbird_cc.resources.views import ResourceInfo
from pyblackbird_cc.resources.views import _extract_metadata_from_resource
-# TODO - convert this test into the test of a function
-# that takes a Resource object and returns all the PDF snapshots
-# file names
-
@pytest.mark.django_db()
def test_resource_model(resources):
diff --git a/pyblackbird_cc/resources/tests/test_views.py b/pyblackbird_cc/resources/tests/test_views.py
index 27a6a85..123476f 100644
--- a/pyblackbird_cc/resources/tests/test_views.py
+++ b/pyblackbird_cc/resources/tests/test_views.py
@@ -11,6 +11,7 @@ from django.urls import reverse
from .. import services
from ..models import ResourceCategory
from ..models import ResourceType
+from ..forms import ResourceCreateForm
from ..views import create_resource
@@ -21,6 +22,19 @@ def test_create_featured_resource_view(client):
assert response.status_code == 302
+@pytest.mark.django_db()
+def test_create_resource_view(client):
+ url = reverse("resources:create_resource")
+ response = client.get(url)
+ assert response.status_code == 302
+
+
+def test_create_resource_has_form(client):
+ url = reverse("resources:create_resource")
+ response = client.get(url)
+ assert type(response.context["form"]) == ResourceCreateForm
+
+
class PDFFileUploadTestCase(TestCase):
def setUp(self):
self.url = reverse("resources:create_resource")
diff --git a/pyblackbird_cc/resources/views.py b/pyblackbird_cc/resources/views.py
index 9fcb77b..2bcb9c2 100644
--- a/pyblackbird_cc/resources/views.py
+++ b/pyblackbird_cc/resources/views.py
@@ -38,6 +38,7 @@ class ResourceInfo:
snapshot_urls: dict[str, list[str]]
thumbnail_filenames: list[str]
thumbnail_urls: list[str]
+ feature_slot: int
created: str
updated: str
@@ -98,6 +99,7 @@ def _extract_metadata_from_resource(resource_obj) -> ResourceInfo | None:
snapshot_urls=snapshot_url_dict,
thumbnail_filenames=resource_obj.thumbnail_filenames,
thumbnail_urls=thumbnail_urls,
+ feature_slot=resource_obj.feature_slot,
created=resource_obj.created_at,
updated=resource_obj.updated_at,
)
@@ -110,7 +112,11 @@ def _extract_metadata_from_resource(resource_obj) -> ResourceInfo | None:
def index(request):
resource_objs = Resource.objects.all()
resource_list = [_extract_metadata_from_resource(r) for r in resource_objs]
- context = {"resource_list": resource_list}
+ # featured_resources = Resource.objects.filter(feature_slot__gt=0).all()
+ featured_resources = [r for r in resource_list if r.feature_slot]
+ breakpoint()
+ featured_resources = sorted(featured_resources, key=lambda resource: resource.feature_slot)
+ context = {"resource_list": resource_list, "featured_resources": featured_resources}
return render(request, "resources/resource_list.html", context)
@@ -245,6 +251,7 @@ def create_resource(request):
curriculum = form.cleaned_data["curriculum"]
main_resource_category = form.cleaned_data["main_resource_category"]
additional_resource_category = form.cleaned_data["additional_resource_category"]
+ feature_slot = form.cleaned_data["feature_slot"]
try:
resource = Resource.objects.create(
@@ -255,6 +262,7 @@ def create_resource(request):
curriculum=curriculum,
main_resource_category=main_resource_category,
additional_resource_category=additional_resource_category,
+ feature_slot=feature_slot,
)
metadata_generator = create_metadata(pdf_files)