~homeworkprod/byceps

fb0c08e8f8b4a4a87318f3aa4d319de24e4e4a8b — Jochen Kupperschmidt 1 year, 7 months ago e6b1d29
Assemble news image filename automatically from image ID and type
M byceps/blueprints/admin/news/forms.py => byceps/blueprints/admin/news/forms.py +0 -1
@@ 30,7 30,6 @@ class _ImageFormBase(LocalizedForm):

class ImageCreateForm(_ImageFormBase):
    image = FileField('Bilddatei', [InputRequired()])
    filename = StringField('Dateiname', [InputRequired(), Length(max=80)])


class ImageUpdateForm(_ImageFormBase):

M byceps/blueprints/admin/news/templates/admin/news/image_create_form.html => byceps/blueprints/admin/news/templates/admin/news/image_create_form.html +0 -1
@@ 26,7 26,6 @@
          Maximale Dateigröße: 150 KB
        {%- endfilter %}
      {%- endcall %}
      {{ form_field(form.filename, maxlength=80, required='required') }}
      {{ form_field(form.alt_text, required='required') }}
      {{ form_field(form.caption) }}
      {{ form_field(form.attribution) }}

M byceps/blueprints/admin/news/views.py => byceps/blueprints/admin/news/views.py +0 -2
@@ 167,7 167,6 @@ def image_create(item_id):

    creator_id = g.current_user.id
    image = request.files.get('image')
    filename = form.filename.data.strip()
    alt_text = form.alt_text.data.strip()
    caption = form.caption.data.strip()
    attribution = form.attribution.data.strip()


@@ 180,7 179,6 @@ def image_create(item_id):
            creator_id,
            item.id,
            image.stream,
            filename,
            alt_text=alt_text,
            caption=caption,
            attribution=attribution,

M byceps/services/news/image_service.py => byceps/services/news/image_service.py +4 -2
@@ 10,7 10,7 @@ from typing import BinaryIO, Optional

from flask import current_app

from ...database import db
from ...database import db, generate_uuid
from ...typing import UserID
from ...util import upload
from ...util.image.models import Dimensions, ImageType


@@ 37,7 37,6 @@ def create_image(
    creator_id: UserID,
    item_id: ItemID,
    stream: BinaryIO,
    filename: str,
    *,
    alt_text: Optional[str] = None,
    caption: Optional[str] = None,


@@ 59,9 58,12 @@ def create_image(
        image_dimensions = image_service.determine_dimensions(stream)
        _check_image_dimensions(image_dimensions)

    image_id = generate_uuid()
    number = _get_next_available_number(item.id)
    filename = f'{image_id}.{image_type.name}'

    image = DbImage(
        image_id,
        creator_id,
        item.id,
        number,

M byceps/services/news/models/image.py => byceps/services/news/models/image.py +5 -3
@@ 9,11 9,11 @@ byceps.services.news.models.image
from datetime import datetime
from typing import Optional

from ....database import db, generate_uuid
from ....database import db
from ....typing import UserID
from ....util.instances import ReprBuilder

from ..transfer.models import ItemID
from ..transfer.models import ImageID, ItemID

from .item import Item



@@ 26,7 26,7 @@ class Image(db.Model):
        db.UniqueConstraint('item_id', 'number'),
    )

    id = db.Column(db.Uuid, default=generate_uuid, primary_key=True)
    id = db.Column(db.Uuid, primary_key=True)
    created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
    creator_id = db.Column(db.Uuid, db.ForeignKey('users.id'), nullable=False)
    item_id = db.Column(db.Uuid, db.ForeignKey('news_items.id'), index=True, nullable=False)


@@ 39,6 39,7 @@ class Image(db.Model):

    def __init__(
        self,
        image_id: ImageID,
        creator_id: UserID,
        item_id: ItemID,
        number: int,


@@ 48,6 49,7 @@ class Image(db.Model):
        caption: Optional[str] = None,
        attribution: Optional[str] = None,
    ) -> None:
        self.id = image_id
        self.creator_id = creator_id
        self.item_id = item_id
        self.number = number