|
|
@@ -10,7 +10,7 @@ from django.views.generic import View
|
|
|
from core.models import Job, ObjectChange
|
|
|
from core.tables import JobTable, ObjectChangeTable
|
|
|
from extras.forms import JournalEntryForm
|
|
|
-from extras.models import JournalEntry
|
|
|
+from extras.models import ImageAttachment, JournalEntry
|
|
|
from extras.tables import JournalEntryTable
|
|
|
from tenancy.models import ContactAssignment
|
|
|
from tenancy.tables import ContactAssignmentTable
|
|
|
@@ -25,6 +25,7 @@ __all__ = (
|
|
|
'BulkSyncDataView',
|
|
|
'ObjectChangeLogView',
|
|
|
'ObjectContactsView',
|
|
|
+ 'ObjectImageAttachmentsView',
|
|
|
'ObjectJobsView',
|
|
|
'ObjectJournalView',
|
|
|
'ObjectSyncDataView',
|
|
|
@@ -84,6 +85,41 @@ class ObjectChangeLogView(ConditionalLoginRequiredMixin, View):
|
|
|
})
|
|
|
|
|
|
|
|
|
+class ObjectImageAttachmentsView(ConditionalLoginRequiredMixin, View):
|
|
|
+ """
|
|
|
+ Render all images attached to the object as linked thumbnails.
|
|
|
+
|
|
|
+ Attributes:
|
|
|
+ base_template: The name of the template to extend. If not provided, "{app}/{model}.html" will be used.
|
|
|
+ """
|
|
|
+ base_template = None
|
|
|
+ tab = ViewTab(
|
|
|
+ label=_('Images'),
|
|
|
+ badge=lambda obj: obj.images.count(),
|
|
|
+ permission='extras.view_imageattachment',
|
|
|
+ weight=6000
|
|
|
+ )
|
|
|
+
|
|
|
+ def get(self, request, model, **kwargs):
|
|
|
+ obj = get_object_or_404(model.objects.restrict(request.user, 'view'), **kwargs)
|
|
|
+ image_attachments = ImageAttachment.objects.filter(
|
|
|
+ object_type=ContentType.objects.get_for_model(obj),
|
|
|
+ object_id=obj.pk,
|
|
|
+ )
|
|
|
+
|
|
|
+ # Default to using "<app>/<model>.html" as the template, if it exists. Otherwise,
|
|
|
+ # fall back to using base.html.
|
|
|
+ if self.base_template is None:
|
|
|
+ self.base_template = f"{model._meta.app_label}/{model._meta.model_name}.html"
|
|
|
+
|
|
|
+ return render(request, 'extras/object_imageattachments.html', {
|
|
|
+ 'object': obj,
|
|
|
+ 'image_attachments': image_attachments,
|
|
|
+ 'base_template': self.base_template,
|
|
|
+ 'tab': self.tab,
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
class ObjectJournalView(ConditionalLoginRequiredMixin, View):
|
|
|
"""
|
|
|
Show all journal entries for an object. The model class must be passed as a keyword argument when referencing this
|