Skip to content

Commit

Permalink
Add alt_text to images
Browse files Browse the repository at this point in the history
  • Loading branch information
elprans committed May 6, 2019
1 parent 954315d commit 9808514
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion wagtail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# major.minor.patch.release.number
# release must be one of alpha, beta, rc, or final
VERSION = (2, 0, 109, 'final', 0)
VERSION = (2, 0, 110, 'final', 0)

__version__ = get_version(VERSION)

Expand Down
28 changes: 28 additions & 0 deletions wagtail/images/migrations/0022_auto_20190506_2114.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.0.13 on 2019-05-06 21:14

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('wagtailimages', '0021_rendition_alt_text'),
]

operations = [
migrations.AddField(
model_name='image',
name='alt_text',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='rendition',
name='alt_text',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='userrendition',
name='alt_text',
field=models.CharField(blank=True, max_length=255, null=True),
),
]
11 changes: 5 additions & 6 deletions wagtail/images/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class AbstractImage(CollectionMember, index.Indexed, models.Model, WillowImageWr
file = models.ImageField(
verbose_name=_('file'), upload_to=get_upload_to, width_field='width', height_field='height'
)
alt_text = models.CharField(max_length=255, null=True, blank=True)
width = models.IntegerField(verbose_name=_('width'), editable=False)
height = models.IntegerField(verbose_name=_('height'), editable=False)
created_at = models.DateTimeField(verbose_name=_('created at'), auto_now_add=True, db_index=True)
Expand Down Expand Up @@ -360,10 +361,7 @@ def filename(self):

@property
def default_alt_text(self):
# by default the alt text field (used in rich text insertion) is populated
# from the title. Subclasses might provide a separate alt field, and
# override this
return self.title
return self.alt_text

def is_editable_by_user(self, user):
from wagtail.images.permissions import permission_policy
Expand All @@ -383,6 +381,7 @@ class Meta:
class Image(AbstractImage):
admin_form_fields = (
'title',
'alt_text',
'file',
'collection',
'tags',
Expand Down Expand Up @@ -511,15 +510,15 @@ class AbstractRendition(models.Model):
width = models.IntegerField(editable=False)
height = models.IntegerField(editable=False)
focal_point_key = models.CharField(max_length=16, blank=True, default='', editable=False)
alt_text = models.CharField(max_length=255, null=True)
alt_text = models.CharField(max_length=255, null=True, blank=True)

@property
def url(self):
return self.file.url

@property
def alt(self):
return self.alt_text or self.image.title
return self.alt_text or self.image.alt_text

@property
def attrs(self):
Expand Down

0 comments on commit 9808514

Please sign in to comment.