Adds alt text to status images

This commit is contained in:
Mouse Reeve 2020-11-24 11:44:13 -08:00
parent 45a0bd79fd
commit ff5a0f7bc2
5 changed files with 7 additions and 4 deletions

View file

@ -227,7 +227,8 @@ def image_attachments_formatter(images_json):
''' deserialize a list of images ''' ''' deserialize a list of images '''
attachments = [] attachments = []
for image in images_json: for image in images_json:
attachment = models.Attachment() caption = image.get('name')
attachment = models.Attachment(caption=caption)
image_field = image_formatter(image) image_field = image_formatter(image)
attachment.image.save(*image_field, save=False) attachment.image.save(*image_field, save=False)
attachments.append(attachment) attachments.append(attachment)

View file

@ -1,4 +1,4 @@
# Generated by Django 3.0.7 on 2020-11-24 17:46 # Generated by Django 3.0.7 on 2020-11-24 19:39
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -19,6 +19,7 @@ class Migration(migrations.Migration):
('updated_date', models.DateTimeField(auto_now=True)), ('updated_date', models.DateTimeField(auto_now=True)),
('remote_id', models.CharField(max_length=255, null=True)), ('remote_id', models.CharField(max_length=255, null=True)),
('image', models.ImageField(blank=True, null=True, upload_to='status/')), ('image', models.ImageField(blank=True, null=True, upload_to='status/')),
('caption', models.TextField(blank=True, null=True)),
('status', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='bookwyrm.Status')), ('status', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='bookwyrm.Status')),
], ],
options={ options={

View file

@ -159,6 +159,7 @@ class Attachment(BookWyrmModel):
related_name='attachments' related_name='attachments'
) )
image = models.ImageField(upload_to='status/', null=True, blank=True) image = models.ImageField(upload_to='status/', null=True, blank=True)
caption = models.TextField(null=True, blank=True)
class GeneratedNote(Status): class GeneratedNote(Status):

View file

@ -21,7 +21,7 @@
{% if status.attachments %} {% if status.attachments %}
<div> <div>
{% for attachment in status.attachments.all %} {% for attachment in status.attachments.all %}
<img src="/images/{{ attachment.image }}"> <img src="/images/{{ attachment.image }}" alt="{{ attachment.caption }}">
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}

2
bw-dev
View file

@ -61,7 +61,7 @@ case "$1" in
;; ;;
migrate) migrate)
execweb python manage.py rename_app fedireads bookwyrm execweb python manage.py rename_app fedireads bookwyrm
execweb python manage.py migrate execweb python manage.py "$@"
;; ;;
bash) bash)
execweb bash execweb bash