From 37698a2ebba6ea366b93f70f6ad87336b302b70c Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sun, 26 May 2024 16:49:34 +0100 Subject: Better presentation of the feature resources --- pyblackbird_cc/resources/forms.py | 8 +- .../0006_resource_card_description_and_more.py | 23 +++ .../migrations/0007_alter_resource_feature_slot.py | 18 +++ .../0008_alter_resource_card_description.py | 18 +++ pyblackbird_cc/resources/models.py | 8 +- pyblackbird_cc/resources/views.py | 5 +- .../templates/resources/resource_list.html | 178 +++++++++++---------- 7 files changed, 174 insertions(+), 84 deletions(-) create mode 100644 pyblackbird_cc/resources/migrations/0006_resource_card_description_and_more.py create mode 100644 pyblackbird_cc/resources/migrations/0007_alter_resource_feature_slot.py create mode 100644 pyblackbird_cc/resources/migrations/0008_alter_resource_card_description.py (limited to 'pyblackbird_cc') diff --git a/pyblackbird_cc/resources/forms.py b/pyblackbird_cc/resources/forms.py index 75d23b4..ca38640 100644 --- a/pyblackbird_cc/resources/forms.py +++ b/pyblackbird_cc/resources/forms.py @@ -34,7 +34,7 @@ class ResourceCreateForm(forms.Form): "eg: 'Fractions KS2 Worksheet and Answers.'", ) description = forms.CharField( - max_length=1000, + max_length=5000, widget=forms.Textarea, help_text=" You can (and should) use Markdown here. " "This is your opportunity to clearly explain what your resource " @@ -53,6 +53,11 @@ class ResourceCreateForm(forms.Form): "characters by using lots of relevant keywords as part of an " "enticing pitch.", ) + card_description = forms.CharField( + max_length=1000, + widget=forms.Textarea, + help_text="If you enter text here, it will be used in the 'card' description box on the home page. Max 1000 characters.", + ) resource_type = forms.ModelChoiceField(queryset=ResourceType.objects.all()) age_range = forms.ChoiceField( choices=AGE_RANGE_CHOICES, @@ -152,6 +157,7 @@ class ResourceUpdateMetadataForm(forms.ModelForm): fields = [ "name", "description", + "card_description", "resource_type", "age_range", "curriculum", diff --git a/pyblackbird_cc/resources/migrations/0006_resource_card_description_and_more.py b/pyblackbird_cc/resources/migrations/0006_resource_card_description_and_more.py new file mode 100644 index 0000000..d343e76 --- /dev/null +++ b/pyblackbird_cc/resources/migrations/0006_resource_card_description_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 5.0.4 on 2024-05-26 15:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('resources', '0005_rename_feature_slot_1_resource_feature_slot_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='resource', + name='card_description', + field=models.TextField(blank=True, help_text="If you enter text here, it will be used in the 'card' description box on the home page. Max 1000 characters.", max_length=1000, null=True), + ), + migrations.AlterField( + model_name='resource', + name='feature_slot', + field=models.IntegerField(blank=True, choices=[(1, 1), (2, 2), (3, 3)], null=True, unique=True), + ), + ] diff --git a/pyblackbird_cc/resources/migrations/0007_alter_resource_feature_slot.py b/pyblackbird_cc/resources/migrations/0007_alter_resource_feature_slot.py new file mode 100644 index 0000000..c5c17c7 --- /dev/null +++ b/pyblackbird_cc/resources/migrations/0007_alter_resource_feature_slot.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.4 on 2024-05-26 15:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('resources', '0006_resource_card_description_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='resource', + name='feature_slot', + field=models.IntegerField(blank=True, choices=[(0, 0), (1, 1), (2, 2), (3, 3)], default=0, null=True, unique=True), + ), + ] diff --git a/pyblackbird_cc/resources/migrations/0008_alter_resource_card_description.py b/pyblackbird_cc/resources/migrations/0008_alter_resource_card_description.py new file mode 100644 index 0000000..18e5739 --- /dev/null +++ b/pyblackbird_cc/resources/migrations/0008_alter_resource_card_description.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.4 on 2024-05-26 15:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('resources', '0007_alter_resource_feature_slot'), + ] + + operations = [ + migrations.AlterField( + model_name='resource', + name='card_description', + field=models.TextField(blank=True, default='', help_text="If you enter text here, it will be used in the 'card' description box on the home page. Max 1000 characters.", max_length=1000), + ), + ] diff --git a/pyblackbird_cc/resources/models.py b/pyblackbird_cc/resources/models.py index 44a5024..0d1bbe3 100644 --- a/pyblackbird_cc/resources/models.py +++ b/pyblackbird_cc/resources/models.py @@ -56,6 +56,12 @@ class Resource(models.Model): blank=False, help_text=DESC_HELP_TEXT, ) + card_description = models.TextField( + max_length=1000, + blank=True, + default="", + help_text="If you enter text here, it will be used in the 'card' description box on the home page. Max 1000 characters.", + ) age_range = models.CharField( max_length=20, null=False, @@ -74,7 +80,7 @@ class Resource(models.Model): ], ) feature_slot = models.IntegerField( - choices=((1, 1), (2, 2), (3, 3)), unique=True, null=True, blank=True + choices=((0, 0), (1, 1), (2, 2), (3, 3)), unique=True, null=True, blank=True, default=0, ) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) diff --git a/pyblackbird_cc/resources/views.py b/pyblackbird_cc/resources/views.py index 8eea5b3..ea8953f 100644 --- a/pyblackbird_cc/resources/views.py +++ b/pyblackbird_cc/resources/views.py @@ -30,6 +30,7 @@ class ResourceInfo: id: int name: str description: str + card_description: str main_resource_category_name: str additional_resource_category_name: str | None age_range: str | None @@ -91,6 +92,7 @@ def _extract_metadata_from_resource(resource_obj) -> ResourceInfo | None: id=resource_obj.id, name=resource_obj.name, description=resource_obj.description, + card_description=resource_obj.card_description, main_resource_category_name=resource_obj.main_resource_category.name, additional_resource_category_name=arc_name, age_range=resource_obj.age_range, @@ -112,7 +114,6 @@ 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] - # featured_resources = Resource.objects.filter(feature_slot__gt=0).all() featured_resources = [r for r in resource_list if r.feature_slot] featured_resources = sorted(featured_resources, key=lambda resource: resource.feature_slot) context = {"resource_list": resource_list, "featured_resources": featured_resources} @@ -245,6 +246,7 @@ def create_resource(request): thumbnail_files = form.cleaned_data["thumbnail_files"] name = form.cleaned_data["name"] description = form.cleaned_data["description"] + card_description = form.cleaned_data["card_description"] resource_type = form.cleaned_data["resource_type"] age_range = form.cleaned_data["age_range"] curriculum = form.cleaned_data["curriculum"] @@ -256,6 +258,7 @@ def create_resource(request): resource = Resource.objects.create( name=name, description=description, + card_description=card_description, resource_type=resource_type, age_range=age_range, curriculum=curriculum, diff --git a/pyblackbird_cc/templates/resources/resource_list.html b/pyblackbird_cc/templates/resources/resource_list.html index f7e705c..9b428d3 100644 --- a/pyblackbird_cc/templates/resources/resource_list.html +++ b/pyblackbird_cc/templates/resources/resource_list.html @@ -3,113 +3,129 @@ {% load static %} {% load markdown_extras %} - {% block title %} +{% block title %} Joanna Lemon Learning - Resource List - {% endblock title %} - {% block content %} +{% endblock title %} +{% block content %} {% if request.user.is_authenticated and request.user.is_staff %} -
-
Admin bar
-

- Only you will see this bar - normal users will not see it. It allows us to - include buttons for adding new resources, etc. -

-
-
-
- Add a new resource -
-
- Logged in as - {{ request.user.email }} -
-
-
- {% csrf_token %} - -
+
+
Admin bar
+

+ Only you will see this bar - normal users will not see it. It allows us to + include buttons for adding new resources, etc. +

+
+
+ +
+ Logged in as + {{ request.user.email }} +
+
+
+ {% csrf_token %} + +
+
-
{% endif %} -
-
{% if featured_resources %} -
-
-
Featured resources
+
+
+
Featured resources
+
-
-
- {% for resource in featured_resources %} -
- {{ resource.thumbnail_filename }} -
-
{{ resource.name }}
-
-
- {{ resource.main_resource_category_name }} -
-
- {{ resource.age_range }} +
+ {% for resource in featured_resources %} +
+ {{ resource.thumbnail_filename }} +
+
{{ resource.name }}
+
+
+ {{ resource.main_resource_category_name }} +
+
+ {{ resource.age_range }} +
+ {% if request.user.is_authenticated and request.user.is_staff %} +
+ Feature slot: {{ resource.feature_slot }} +
+ {% endif %} +
+ {% if resource.card_description %} +

{{ resource.card_description | markdown | safe }}

+ {% else %} +

{{ resource.description | markdown | safe }}

+ {% endif %} + Details + {% if request.user.is_authenticated and request.user.is_staff %} + Edit + {% endif %}
-

{{ resource.description | markdown | safe }}

- Details -
-
- {% endfor %} + {% endfor %} {% else %} -

There are no featured resources

+

There are no featured resources

{% endif %}
-
-
{% if resource_list %} -
-
-
Standard resources
+
+
+
Standard resources
+
-
-
- {% for resource in resource_list %} -
- {{ resource.thumbnail_filename }} -
-
{{ resource.name }}
-
-
- {{ resource.main_resource_category_name }} -
-
- {{ resource.age_range }} +
+ {% for resource in resource_list %} +
+ {{ resource.thumbnail_filename }} +
+
{{ resource.name }}
+
+
+ {{ resource.main_resource_category_name }} +
+
+ {{ resource.age_range }} +
+
+ {% if resource.card_description %} +

{{ resource.card_description | markdown | safe }}

+ {% else %} +

{{ resource.description | markdown | safe }}

+ {% endif %} + Details + {% if request.user.is_authenticated and request.user.is_staff %} + Edit + {% endif %}
-

{{ resource.description | markdown | safe }}

- Details -
+ {% endfor %}
- {% endfor %}
-
- {% else %} -

There are no resources

+

There are no resources

{% endif %}
- {% endblock content %} +{% endblock content %} -- cgit v1.2.3