Changeset 7d9089b in flexograder
- Timestamp:
- 01/19/26 16:55:02 (2 months ago)
- Branches:
- fake-data, main, master
- Children:
- 5739768
- Parents:
- e92c42d
- Files:
-
- 2 added
- 1 edited
-
examples/demo/new_export2.json (added)
-
examples/demo/new_export3.json (added)
-
flexograder/core_entities/media_items.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
flexograder/core_entities/media_items.py
re92c42d r7d9089b 1 1 import mimetypes 2 import hashlib3 from pathlib import Path4 2 5 from dat etime import datetime6 from dataclasses import dataclass, field7 from flexoentity import FlexOID, EntityType, EntityState, FlexoEntity, logger3 from dataclasses import dataclass 4 from abc import ABC, abstractmethod 5 from flexoentity import EntityType, FlexoEntity, logger 8 6 9 7 @dataclass 10 class MediaItem(FlexoEntity ):8 class MediaItem(FlexoEntity, ABC): 11 9 12 10 ENTITY_TYPE = EntityType.MEDIA … … 21 19 # Derived property 22 20 # ────────────────────────────────────────────────────────────── 21 23 22 @property 23 @abstractmethod 24 24 def mtype(self) -> str: 25 """Semantic media type (image, audio, video, download).""" 26 raise NotImplementedError 27 28 @property 29 def mime_category(self) -> str: 25 30 """Infer type from src path using MIME detection.""" 26 31 mime, _ = mimetypes.guess_type(self.src) … … 46 51 return f"{self.src}|{self.title}|{self.caption}|{self.mtype}" 47 52 48 def to_dict(self): 49 base = super().to_dict() # includes OID, state, version, etc. 50 base.update({ 53 def _serialize_content(self) -> dict: 54 content = super()._serialize_content() or {} 55 content.update({ 56 "type": self.mtype, 51 57 "src": self.src, 52 58 "title": self.title, 53 59 "caption": self.caption, 54 " type": self.mtype,60 "author": self.author 55 61 }) 56 return base62 return content 57 63 58 @classmethod 59 def from_dict(cls, data): 60 flexo_id = FlexOID(data["flexo_id"]) if "flexo_id" in data else None 61 62 obj = cls( 63 flexo_id=flexo_id, 64 src=data.get("src", ""), 65 title=data.get("title", ""), 66 caption=data.get("caption", ""), 67 author=data.get("author", ""), 68 fingerprint=data.get("fingerprint"), 69 state=EntityState(data["state"]) if "state" in data else EntityState(flexo_id.state_code), 70 version=data.get("version"), 71 _in_factory=True, 72 ) 73 74 return obj 64 def _deserialize_content(self, content: dict): 65 super()._deserialize_content(content) 66 self.src = content.get("src", "") 67 self.title = content.get("title", "") 68 self.caption = content.get("caption", "") 69 self.author = content.get("author", "") 75 70 76 71 def to_html(self): … … 113 108 114 109 @property 115 def type(self):110 def mtype(self): 116 111 return "download" 117 112
Note:
See TracChangeset
for help on using the changeset viewer.
