4
4
from viur .core .bones import FileBone , StringBone
5
5
from viur .core .skeleton import RelSkel
6
6
7
+ from .actions import *
8
+
9
+ __all__ = [
10
+ "ImageBone" ,
11
+ "ImageBoneRelSkel" ,
12
+ ]
13
+
7
14
8
15
class ImageBoneRelSkel (RelSkel ):
16
+ """
17
+ RelSkel designed to use as using skeleton in a ``ImageBone``.
18
+ """
19
+
9
20
alt = StringBone (
10
21
descr = i18n .translate ("viur.assistant.imagebone.alt.descr" , "Alternative text" , public = True ),
11
22
searchable = True ,
@@ -15,15 +26,43 @@ class ImageBoneRelSkel(RelSkel):
15
26
16
27
17
28
class ImageBone (FileBone ):
29
+ """
30
+ A specialized ``FileBone`` for image files.
31
+
32
+ This bone type extends ``FileBone`` by:
33
+
34
+ - Restricting accepted MIME types to images (by default).
35
+ - Has a using skel with an alt ``StringBone``.
36
+ - Optionally enabling the *Describe Image* bone action, which allows AI to generate an alt-text or caption
37
+ for the uploaded image via an admin-triggerable action.
38
+ """
39
+
18
40
type = FileBone .type + ".image"
19
41
20
42
def __init__ (
21
43
self ,
22
44
* ,
23
45
using : t .Type [RelSkel ] = ImageBoneRelSkel ,
24
46
validMimeTypes : None | t .Iterable [str ] = ("image/*" ,),
47
+ enable_describe_image : bool = True ,
25
48
** kwargs ,
26
49
):
50
+ """
51
+ Initialize an ImageBone, a file-based bone specialized for handling image uploads.
52
+
53
+ Optionally adds a bone action that allows AI-based image description (alt-text generation)
54
+ to be triggered from within the admin interface.
55
+
56
+ :param using: The relational skeleton class used for additional data of this image.
57
+ Defaults to ``ImageBoneRelSkel``, including the alt ``StringBone``.
58
+ :param validMimeTypes: A list of accepted MIME types. Defaults to only allow image types (``("image/*",)``).
59
+ :param enable_describe_image: If ``True``, the bone will include the ``DESCRIBE_IMAGE`` bone action,
60
+ allowing AI-assisted image description via the vi-admin UI.
61
+ :param kwargs: Additional keyword arguments passed to the base ``FileBone``.
62
+ """
63
+ if enable_describe_image :
64
+ params = kwargs .setdefault ("params" , {})
65
+ params [BONE_ACTION_KEY ] = [* params .get (BONE_ACTION_KEY , []), BoneAction .DESCRIBE_IMAGE ]
27
66
super ().__init__ (
28
67
using = using ,
29
68
validMimeTypes = validMimeTypes ,
0 commit comments