diff options
author | Matthew Lemon <y@yulqen.org> | 2024-05-26 16:49:34 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-05-26 16:49:34 +0100 |
commit | 37698a2ebba6ea366b93f70f6ad87336b302b70c (patch) | |
tree | 83bc29a8b9574cbf6091d8afc7cdf5ef7a56d211 | |
parent | b3c7d985a50a38fcb19d8e9f91b5b719d43e31a4 (diff) |
Better presentation of the feature resources
7 files changed, 174 insertions, 84 deletions
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 <strong>Markdown</strong> 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 %} - <div class="row bg-white p-4 rounded border border-success border-opacity-25"> - <h5 class="text-decoration-underline">Admin bar</h5> - <p> - Only you will see this bar - normal users will not see it. It allows us to - include buttons for adding new resources, etc. - </p> - <div class="col"> - <div class="d-flex flex-row flex-wrap justify-content-between"> - <div> - <a class="btn btn-primary my-md-2" - href="{% url 'resources:create_resource' %} ">Add a new resource</a> - </div> - <div class="bg-danger p-2 my-2 text-dark bg-white border border-1 border-danger"> - Logged in as - <strong>{{ request.user.email }}</strong> - </div> - <div class="my-md-2"> - <form action="{% url 'account_logout' %}" method="post"> - {% csrf_token %} - <button type="submit" class="btn btn-primary">Log out</button> - </form> + <div class="row bg-white p-4 rounded border border-success border-opacity-25"> + <h5 class="text-decoration-underline">Admin bar</h5> + <p> + Only you will see this bar - normal users will not see it. It allows us to + include buttons for adding new resources, etc. + </p> + <div class="col"> + <div class="d-flex flex-row flex-wrap justify-content-between"> + <div> + <a class="btn btn-primary my-md-2" + href="{% url 'resources:create_resource' %} ">Add a new resource</a> + </div> + <div class="bg-danger p-2 my-2 text-dark bg-white border border-1 border-danger"> + Logged in as + <strong>{{ request.user.email }}</strong> + </div> + <div class="my-md-2"> + <form action="{% url 'account_logout' %}" method="post"> + {% csrf_token %} + <button type="submit" class="btn btn-primary">Log out</button> + </form> + </div> </div> </div> </div> - </div> {% endif %} - <div class="row my-4"> - <!-- Featured resources first --> <div class="col"> {% if featured_resources %} - <div class="row my-4 text-center"> - <div class="col"> - <h5 class="display-6">Featured resources</h5> + <div class="row my-4 text-center"> + <div class="col"> + <h5 class="display-6">Featured resources</h5> + </div> </div> - </div> - <div class="d-flex flex-row justify-content-between flex-wrap"> - {% for resource in featured_resources %} - <div class="card mx-2 mt-2" style="width: 22rem;"> - <img class="card-img-top" - src="{{ resource.thumbnail_urls|first }}" - alt="{{ resource.thumbnail_filename }}" /> - <div class="card-body"> - <h5 class="card-title">{{ resource.name }}</h5> - <div class="d-flex flex-row justify-content-start align-content-center"> - <div> - <span class="badge bg-danger me-2">{{ resource.main_resource_category_name }}</span> - </div> - <div> - <span class="badge bg-secondary me-2">{{ resource.age_range }}</span> + <div class="d-flex flex-row justify-content-between flex-wrap"> + {% for resource in featured_resources %} + <div class="card mx-2 mt-2" style="width: 22rem;"> + <img class="card-img-top" + src="{{ resource.thumbnail_urls|first }}" + alt="{{ resource.thumbnail_filename }}" /> + <div class="card-body"> + <h5 class="card-title">{{ resource.name }}</h5> + <div class="d-flex flex-row justify-content-start align-content-center"> + <div> + <span class="badge bg-danger me-2">{{ resource.main_resource_category_name }}</span> + </div> + <div> + <span class="badge bg-secondary me-2">{{ resource.age_range }}</span> + </div> + {% if request.user.is_authenticated and request.user.is_staff %} + <div> + <span class="badge bg-info me-2">Feature slot: {{ resource.feature_slot }}</span> + </div> + {% endif %} + </div> + {% if resource.card_description %} + <p class="card-text my-3">{{ resource.card_description | markdown | safe }}</p> + {% else %} + <p class="card-text my-3">{{ resource.description | markdown | safe }}</p> + {% endif %} + <a href="{% url 'resources:resource_detail' resource_id=resource.id %}" + class="btn btn-primary">Details</a> + {% if request.user.is_authenticated and request.user.is_staff %} + <a href="{% url "resources:resource_update_metadata" resource.id %}" + class="btn btn-primary">Edit</a> + {% endif %} </div> </div> - <p class="card-text my-3">{{ resource.description | markdown | safe }}</p> - <a href="{% url 'resources:resource_detail' resource_id=resource.id %}" - class="btn btn-primary">Details</a> - </div> - </div> - {% endfor %} + {% endfor %} {% else %} - <p>There are no featured resources</p> + <p>There are no featured resources</p> {% endif %} </div> </div> - <div class="d-flex flex-row justify-content-between flex-wrap"> - <div class="col"> {% if resource_list %} - <div class="row my-4 text-center"> - <div class="col"> - <h5 class="display-6">Standard resources</h5> + <div class="row my-4 text-center"> + <div class="col"> + <h5 class="display-6">Standard resources</h5> + </div> </div> - </div> - <div class="d-flex flex-row justify-content-between flex-wrap"> - {% for resource in resource_list %} - <div class="card mx-2 mt-2" style="width: 22rem;"> - <img class="card-img-top" - src="{{ resource.thumbnail_urls|first }}" - alt="{{ resource.thumbnail_filename }}" /> - <div class="card-body"> - <h5 class="card-title">{{ resource.name }}</h5> - <div class="d-flex flex-row justify-content-start align-content-center"> - <div> - <span class="badge bg-danger me-2">{{ resource.main_resource_category_name }}</span> - </div> - <div> - <span class="badge bg-secondary me-2">{{ resource.age_range }}</span> + <div class="d-flex flex-row justify-content-between flex-wrap"> + {% for resource in resource_list %} + <div class="card mx-2 mt-2" style="width: 22rem;"> + <img class="card-img-top" + src="{{ resource.thumbnail_urls|first }}" + alt="{{ resource.thumbnail_filename }}" /> + <div class="card-body"> + <h5 class="card-title">{{ resource.name }}</h5> + <div class="d-flex flex-row justify-content-start align-content-center"> + <div> + <span class="badge bg-danger me-2">{{ resource.main_resource_category_name }}</span> + </div> + <div> + <span class="badge bg-secondary me-2">{{ resource.age_range }}</span> + </div> + </div> + {% if resource.card_description %} + <p class="card-text my-3">{{ resource.card_description | markdown | safe }}</p> + {% else %} + <p class="card-text my-3">{{ resource.description | markdown | safe }}</p> + {% endif %} + <a href="{% url 'resources:resource_detail' resource_id=resource.id %}" + class="btn btn-primary">Details</a> + {% if request.user.is_authenticated and request.user.is_staff %} + <a href="{% url "resources:resource_update_metadata" resource.id %}" + class="btn btn-primary">Edit</a> + {% endif %} </div> </div> - <p class="card-text my-3">{{ resource.description | markdown | safe }}</p> - <a href="{% url 'resources:resource_detail' resource_id=resource.id %}" - class="btn btn-primary">Details</a> - </div> + {% endfor %} </div> - {% endfor %} </div> - </div> - {% else %} - <p>There are no resources</p> + <p>There are no resources</p> {% endif %} </div> </div> - {% endblock content %} +{% endblock content %} |