mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Merge 6985169db6
into 6df0a02d8d
This commit is contained in:
commit
b15ed1fa33
@ -139,6 +139,10 @@ social-auth-app-django
|
|||||||
# https://github.com/python-social-auth/social-core/blob/master/CHANGELOG.md
|
# https://github.com/python-social-auth/social-core/blob/master/CHANGELOG.md
|
||||||
social-auth-core
|
social-auth-core
|
||||||
|
|
||||||
|
# Image thumbnail generation
|
||||||
|
# https://github.com/jazzband/sorl-thumbnail/blob/master/CHANGES.rst
|
||||||
|
sorl-thumbnail
|
||||||
|
|
||||||
# Strawberry GraphQL
|
# Strawberry GraphQL
|
||||||
# https://github.com/strawberry-graphql/strawberry/blob/main/CHANGELOG.md
|
# https://github.com/strawberry-graphql/strawberry/blob/main/CHANGELOG.md
|
||||||
strawberry-graphql
|
strawberry-graphql
|
||||||
|
@ -686,6 +686,10 @@ def register_models(*models):
|
|||||||
register_model_view(model, 'jobs', kwargs={'model': model})(
|
register_model_view(model, 'jobs', kwargs={'model': model})(
|
||||||
'netbox.views.generic.ObjectJobsView'
|
'netbox.views.generic.ObjectJobsView'
|
||||||
)
|
)
|
||||||
|
if issubclass(model, ImageAttachmentsMixin):
|
||||||
|
register_model_view(model, 'image-attachments', kwargs={'model': model})(
|
||||||
|
'netbox.views.generic.ObjectImageAttachmentsView'
|
||||||
|
)
|
||||||
if issubclass(model, SyncedDataMixin):
|
if issubclass(model, SyncedDataMixin):
|
||||||
register_model_view(model, 'sync', kwargs={'model': model})(
|
register_model_view(model, 'sync', kwargs={'model': model})(
|
||||||
'netbox.views.generic.ObjectSyncDataView'
|
'netbox.views.generic.ObjectSyncDataView'
|
||||||
|
@ -424,6 +424,7 @@ INSTALLED_APPS = [
|
|||||||
'mptt',
|
'mptt',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'social_django',
|
'social_django',
|
||||||
|
'sorl.thumbnail',
|
||||||
'taggit',
|
'taggit',
|
||||||
'timezone_field',
|
'timezone_field',
|
||||||
'core',
|
'core',
|
||||||
|
@ -10,7 +10,7 @@ from django.views.generic import View
|
|||||||
from core.models import Job, ObjectChange
|
from core.models import Job, ObjectChange
|
||||||
from core.tables import JobTable, ObjectChangeTable
|
from core.tables import JobTable, ObjectChangeTable
|
||||||
from extras.forms import JournalEntryForm
|
from extras.forms import JournalEntryForm
|
||||||
from extras.models import JournalEntry
|
from extras.models import ImageAttachment, JournalEntry
|
||||||
from extras.tables import JournalEntryTable
|
from extras.tables import JournalEntryTable
|
||||||
from tenancy.models import ContactAssignment
|
from tenancy.models import ContactAssignment
|
||||||
from tenancy.tables import ContactAssignmentTable
|
from tenancy.tables import ContactAssignmentTable
|
||||||
@ -25,6 +25,7 @@ __all__ = (
|
|||||||
'BulkSyncDataView',
|
'BulkSyncDataView',
|
||||||
'ObjectChangeLogView',
|
'ObjectChangeLogView',
|
||||||
'ObjectContactsView',
|
'ObjectContactsView',
|
||||||
|
'ObjectImageAttachmentsView',
|
||||||
'ObjectJobsView',
|
'ObjectJobsView',
|
||||||
'ObjectJournalView',
|
'ObjectJournalView',
|
||||||
'ObjectSyncDataView',
|
'ObjectSyncDataView',
|
||||||
@ -84,6 +85,52 @@ class ObjectChangeLogView(ConditionalLoginRequiredMixin, View):
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
class ObjectImageAttachmentsView(ConditionalLoginRequiredMixin, View):
|
||||||
|
"""
|
||||||
|
Render a list of all Job assigned to an object. For example:
|
||||||
|
|
||||||
|
path(
|
||||||
|
'data-sources/<int:pk>/jobs/',
|
||||||
|
ObjectJobsView.as_view(),
|
||||||
|
name='datasource_jobs',
|
||||||
|
kwargs={'model': DataSource}
|
||||||
|
)
|
||||||
|
|
||||||
|
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.imageattachments.count(),
|
||||||
|
permission='extras.view_imageattachment',
|
||||||
|
weight=6000
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_object(self, request, **kwargs):
|
||||||
|
return get_object_or_404(self.model.objects.restrict(request.user, 'view'), **kwargs)
|
||||||
|
|
||||||
|
def get(self, request, model, **kwargs):
|
||||||
|
self.model = model
|
||||||
|
obj = self.get_object(request, **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):
|
class ObjectJournalView(ConditionalLoginRequiredMixin, View):
|
||||||
"""
|
"""
|
||||||
Show all journal entries for an object. The model class must be passed as a keyword argument when referencing this
|
Show all journal entries for an object. The model class must be passed as a keyword argument when referencing this
|
||||||
|
26
netbox/templates/extras/object_imageattachments.html
Normal file
26
netbox/templates/extras/object_imageattachments.html
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{% extends base_template %}
|
||||||
|
{% load render_table from django_tables2 %}
|
||||||
|
{% load thumbnail %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row row-cards">
|
||||||
|
{% for object in image_attachments %}
|
||||||
|
<div class="col">
|
||||||
|
<div class="card card-sm">
|
||||||
|
{% thumbnail object.image "200x200" crop="center" as tn %}
|
||||||
|
<a href="{{ object.get_absolute_url }}" class="d-block">
|
||||||
|
<img src="{{ tn.url }}" width="{{ tn.width }}" height="{{ tn.height }}" class="card-img-top" />
|
||||||
|
</a>
|
||||||
|
{% endthumbnail %}
|
||||||
|
<div class="card-body p-1">
|
||||||
|
<div class="text-center">
|
||||||
|
<small class="text-secondary">{{ object }}</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -33,6 +33,7 @@ requests==2.32.4
|
|||||||
rq==2.4.0
|
rq==2.4.0
|
||||||
social-auth-app-django==5.5.1
|
social-auth-app-django==5.5.1
|
||||||
social-auth-core==4.7.0
|
social-auth-core==4.7.0
|
||||||
|
sorl-thumbnail==12.11.0
|
||||||
strawberry-graphql==0.276.0
|
strawberry-graphql==0.276.0
|
||||||
strawberry-graphql-django==0.60.0
|
strawberry-graphql-django==0.60.0
|
||||||
svgwrite==1.4.3
|
svgwrite==1.4.3
|
||||||
|
Loading…
Reference in New Issue
Block a user