2019-12-11 15:26:47 -05:00
|
|
|
from taggit.managers import _TaggableManager
|
|
|
|
|
|
|
|
|
|
|
|
def is_taggable(obj):
|
|
|
|
"""
|
|
|
|
Return True if the instance can have Tags assigned to it; False otherwise.
|
|
|
|
"""
|
|
|
|
if hasattr(obj, 'tags'):
|
|
|
|
if issubclass(obj.tags.__class__, _TaggableManager):
|
|
|
|
return True
|
|
|
|
return False
|
2020-03-14 03:03:22 -04:00
|
|
|
|
|
|
|
|
2020-05-07 16:59:27 -04:00
|
|
|
def image_upload(instance, filename):
|
|
|
|
"""
|
2023-02-19 13:58:01 -05:00
|
|
|
Return a path for uploading image attachments.
|
2020-05-07 16:59:27 -04:00
|
|
|
"""
|
|
|
|
path = 'image-attachments/'
|
|
|
|
|
|
|
|
# Rename the file to the provided name, if any. Attempt to preserve the file extension.
|
|
|
|
extension = filename.rsplit('.')[-1].lower()
|
|
|
|
if instance.name and extension in ['bmp', 'gif', 'jpeg', 'jpg', 'png']:
|
|
|
|
filename = '.'.join([instance.name, extension])
|
|
|
|
elif instance.name:
|
|
|
|
filename = instance.name
|
|
|
|
|
2024-03-01 16:34:52 -05:00
|
|
|
return '{}{}_{}_{}'.format(path, instance.object_type.name, instance.object_id, filename)
|
2020-05-07 16:59:27 -04:00
|
|
|
|
|
|
|
|
2023-03-24 21:00:36 -04:00
|
|
|
def is_script(obj):
|
|
|
|
"""
|
2024-02-07 09:02:09 -08:00
|
|
|
Returns True if the object is a Script or Report.
|
2023-03-24 21:00:36 -04:00
|
|
|
"""
|
2024-02-07 09:02:09 -08:00
|
|
|
from .reports import Report
|
2023-03-24 21:00:36 -04:00
|
|
|
from .scripts import Script
|
|
|
|
try:
|
2024-02-07 09:02:09 -08:00
|
|
|
return (issubclass(obj, Report) and obj != Report) or (issubclass(obj, Script) and obj != Script)
|
2023-03-24 21:00:36 -04:00
|
|
|
except TypeError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def is_report(obj):
|
|
|
|
"""
|
|
|
|
Returns True if the given object is a Report.
|
|
|
|
"""
|
|
|
|
from .reports import Report
|
|
|
|
try:
|
|
|
|
return issubclass(obj, Report) and obj != Report
|
|
|
|
except TypeError:
|
|
|
|
return False
|