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 /pyblackbird_cc/resources | |
parent | b3c7d985a50a38fcb19d8e9f91b5b719d43e31a4 (diff) |
Better presentation of the feature resources
Diffstat (limited to 'pyblackbird_cc/resources')
6 files changed, 77 insertions, 3 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, |