From ca55b750a9deb93dc81b0ca2d53f1e636ed00f9f Mon Sep 17 00:00:00 2001 From: Jason Goldstein Date: Tue, 26 Jul 2016 13:27:57 -0400 Subject: [PATCH] Alt text support $ manage migrate cropduster --- cropduster/fields.py | 5 ++++- cropduster/forms.py | 3 ++- cropduster/migrations/0002_alt_text.py | 20 ++++++++++++++++++++ cropduster/models.py | 1 + cropduster/templatetags/cropduster_tags.py | 2 ++ docs/quickstart.rst | 2 +- 6 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 cropduster/migrations/0002_alt_text.py diff --git a/cropduster/fields.py b/cropduster/fields.py index bf8263f6..e74b1e3f 100644 --- a/cropduster/fields.py +++ b/cropduster/fields.py @@ -222,7 +222,10 @@ def get_formset(self, request, obj=None, **kwargs): field=self.field, formset_attrs=formset_attrs, prefix=self.default_prefix, - form_attrs={"caption": forms.CharField(required=False)}, + form_attrs={ + "caption": forms.CharField(required=False), + "alt_text": forms.CharField(required=False), + }, for_concrete_model=for_concrete_model, ) diff --git a/cropduster/forms.py b/cropduster/forms.py index 44b0b0fb..5ce39678 100644 --- a/cropduster/forms.py +++ b/cropduster/forms.py @@ -168,7 +168,8 @@ def get_cropduster_field_on_model(model, field_identifier): class CropDusterInlineFormSet(BaseGenericFileInlineFormSet): - fields = ('image', 'thumbs', 'attribution', 'attribution_link', 'caption', 'field_identifier') + fields = ('image', 'thumbs', 'attribution', 'attribution_link', + 'caption', 'alt_text', 'field_identifier') def __init__(self, *args, **kwargs): super(CropDusterInlineFormSet, self).__init__(*args, **kwargs) diff --git a/cropduster/migrations/0002_alt_text.py b/cropduster/migrations/0002_alt_text.py new file mode 100644 index 00000000..819a2ee8 --- /dev/null +++ b/cropduster/migrations/0002_alt_text.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import cropduster.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('cropduster', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='image', + name='alt_text', + field=models.TextField(null=False, default="", verbose_name=b'Alt Text', blank=True), + ), + ] diff --git a/cropduster/models.py b/cropduster/models.py index e8c3de9a..050775e8 100644 --- a/cropduster/models.py +++ b/cropduster/models.py @@ -228,6 +228,7 @@ class Image(models.Model): attribution = models.CharField(max_length=255, blank=True, null=True) attribution_link = models.URLField(max_length=255, blank=True, null=True) caption = models.TextField(blank=True, null=True) + alt_text = models.TextField("Alt Text", blank=True, default="") class Meta: app_label = cropduster_settings.CROPDUSTER_APP_LABEL diff --git a/cropduster/templatetags/cropduster_tags.py b/cropduster/templatetags/cropduster_tags.py index 626cbdad..db53ba12 100644 --- a/cropduster/templatetags/cropduster_tags.py +++ b/cropduster/templatetags/cropduster_tags.py @@ -34,6 +34,7 @@ def get_crop(image, crop_name, **kwargs): "attribution": 'Stock Photoz', "attribution_link": 'http://stockphotoz.com', "caption": 'Woman laughing alone with salad.', + "alt_text": 'Woman laughing alone with salad.' } For use in an image tag or style block like: @@ -71,4 +72,5 @@ def get_crop(image, crop_name, **kwargs): "attribution": image.related_object.attribution, "attribution_link": image.related_object.attribution_link, "caption": image.related_object.caption, + "alt_text": image.related_object.alt_text, } diff --git a/docs/quickstart.rst b/docs/quickstart.rst index e737cc24..75e99cd8 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -92,7 +92,7 @@ To get a dictionary containing information about an image within a template, use {% if img %}
- {{ alt_text }} {% if img.attribution %}