@@ -32,12 +32,12 @@ class UserResource(Model):
3232 )
3333 created_at = models .DateTimeField (auto_now_add = True )
3434 modified_at = models .DateTimeField (auto_now = True )
35- created_by = models .ForeignKey (
35+ created_by : User = models .ForeignKey ( # type: ignore[reportIncompatibleVariableOverride]
3636 User ,
3737 related_name = "%(class)s_created" ,
3838 on_delete = models .PROTECT ,
3939 )
40- modified_by = models .ForeignKey (
40+ modified_by : User = models .ForeignKey ( # type: ignore[reportIncompatibleVariableOverride]
4141 User ,
4242 related_name = "%(class)s_modified" ,
4343 on_delete = models .PROTECT ,
@@ -60,7 +60,7 @@ def __str__(self):
6060class ArchivableResource (Model ):
6161 is_archived = models .BooleanField (default = False )
6262 archived_at = models .DateTimeField (null = True , blank = True )
63- archived_by = models .ForeignKey (
63+ archived_by : User = models .ForeignKey ( # type: ignore[reportIncompatibleVariableOverride]
6464 User ,
6565 related_name = "+" ,
6666 on_delete = models .SET_NULL ,
@@ -161,3 +161,75 @@ def update_firebase_push_status(
161161
162162 class Meta (TypedModelMeta ): # type: ignore[reportIncompatibleVariableOverride]
163163 abstract = True
164+
165+
166+ class AssetMimetypeEnum (models .IntegerChoices ):
167+ GEOJSON = 100 , "application/geo+json"
168+
169+ IMAGE_JPEG = 201 , "image/jpeg"
170+ IMAGE_PNG = 202 , "image/png"
171+ IMAGE_GIF = 203 , "image/gif"
172+
173+ @classmethod
174+ def get_display (cls , value : typing .Self | int ) -> str :
175+ if value in cls :
176+ return str (cls (value ).label )
177+ return "Unknown"
178+
179+ @classmethod
180+ def is_valid_mimetype (cls , mimetype : str ) -> bool :
181+ """
182+ Check if the given mimetype is valid for project assets.
183+ """
184+ return mimetype in [choice .label for choice in cls ]
185+
186+ @classmethod
187+ def get_mimetype_by_label (cls , label : str ) -> typing .Self | None :
188+ for choice in cls :
189+ if choice .label == label :
190+ return choice
191+ return None
192+
193+
194+ # FIXME(tnagorra): Finalize the enum labels
195+ class AssetTypeEnum (models .IntegerChoices ):
196+ INPUT = 100 , "Input"
197+ OUTPUT = 200 , "Output"
198+ STATS = 300 , "Stats"
199+
200+ @classmethod
201+ def get_display (cls , value : typing .Self | int ) -> str :
202+ if value in cls :
203+ return str (cls (value ).label )
204+ return "Unknown"
205+
206+
207+ class CommonAsset (Model ):
208+ Mimetype = AssetMimetypeEnum
209+ MAX_FILE_SIZE : int = 10 * 1024 * 1024 # MB
210+ Type = AssetTypeEnum
211+
212+ type = IntegerChoicesField (
213+ choices_enum = AssetTypeEnum ,
214+ )
215+
216+ mimetype = IntegerChoicesField (
217+ choices_enum = AssetMimetypeEnum ,
218+ )
219+
220+ file_size = models .PositiveIntegerField (
221+ help_text = gettext_lazy ("The size of the file in bytes" ),
222+ )
223+
224+ marked_as_deleted = models .BooleanField (
225+ default = False ,
226+ help_text = gettext_lazy ("If this flag is enabled, this project asset will be deleted in the future" ),
227+ )
228+
229+ class Meta (TypedModelMeta ): # type: ignore[reportIncompatibleVariableOverride]
230+ abstract = True
231+
232+ @classmethod
233+ def usable_objects (cls ):
234+ """Returns objects that are mot marked for deletion"""
235+ return cls .objects .filter (marked_as_deleted = False )
0 commit comments