Skip to content

Commit

Permalink
Remove loading of unnecessary objects in template content
Browse files Browse the repository at this point in the history
  • Loading branch information
Kani999 committed Aug 13, 2024
1 parent ca86de8 commit 09f5b62
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 30 deletions.
33 changes: 4 additions & 29 deletions netbox_attachments/template_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,9 @@


def create_attachments_panel(self):
obj = self.context["object"]
request = self.context["request"]
app_label, model = self.model.split(".")
app_label, _ = self.model.split(".")
try:
object_type_id = ObjectType.objects.get(app_label=app_label, model=model).id

return self.render(
"netbox_attachments/netbox_attachment_panel.html",
extra_context={
"netbox_attachments": NetBoxAttachment.objects.filter(
object_type_id=object_type_id, object_id=obj.id
).restrict(request.user, "view"),
},
)
return self.render("netbox_attachments/netbox_attachment_panel.html")
except ObjectType.DoesNotExist:
logging.error(f"ObjectType for {app_label} {self.model} does not exist")
return ""
Expand Down Expand Up @@ -73,7 +62,7 @@ def buttons(self):
return Button


def create_tab_view(model, base_template_name="generic/object_children.html"):
def create_tab_view(model):
"""Creates attachment tab. Append it to the passed model
Args:
Expand Down Expand Up @@ -105,21 +94,7 @@ def __init__(self, *args, **kwargs):
)

def get_children(self, request, parent):
childrens = self.child_model.objects.filter(
object_type=ObjectType.objects.get_for_model(parent),
object_id=parent.id,
).restrict(request.user, "view")
return childrens

def get_extra_context(self, request, instance):
data = {
"base_template_name": base_template_name,
"netbox_attachments": self.child_model.objects.filter(
object_type=ObjectType.objects.get_for_model(instance),
object_id=instance.id,
).restrict(request.user, "view"),
}
return data
super()

register_model_view(model, name=name, path=path)(View)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends base_template_name %}
{% extends "generic/object_children.html" %}
{% load render_table from django_tables2 %}
{% load static %}
{% load helpers %}
Expand Down

0 comments on commit 09f5b62

Please sign in to comment.