Skip to content

Commit

Permalink
Alt text support
Browse files Browse the repository at this point in the history
$ manage migrate cropduster
  • Loading branch information
whatisjasongoldstein committed Aug 11, 2016
1 parent 5896f7b commit ca55b75
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cropduster/fields.py
Expand Up @@ -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,
)

Expand Down
3 changes: 2 additions & 1 deletion cropduster/forms.py
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions 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),
),
]
1 change: 1 addition & 0 deletions cropduster/models.py
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cropduster/templatetags/cropduster_tags.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
}
2 changes: 1 addition & 1 deletion docs/quickstart.rst
Expand Up @@ -92,7 +92,7 @@ To get a dictionary containing information about an image within a template, use
{% if img %}
<figure>
<img src="{{ img.url }}" width="{{ img.width }}" height="{{ img.height }}"
<img src="{{ img.url }}" alt="{{ alt_text }}" width="{{ img.width }}" height="{{ img.height }}"
alt="{{ img.caption }}" />
{% if img.attribution %}
<figcaption>
Expand Down

0 comments on commit ca55b75

Please sign in to comment.