diff --git a/app/core/views/common.py b/app/core/views/common.py
index fef95df0..f1baac20 100644
--- a/app/core/views/common.py
+++ b/app/core/views/common.py
@@ -1,9 +1,12 @@
+from django.template import Template, Context
+from django.utils.html import escape
from django.views import generic
from access.mixin import OrganizationPermission
from core.exceptions import MissingAttribute
+from settings.models.external_link import ExternalLink
from settings.models.user_settings import UserSettings
@@ -50,6 +53,61 @@ class ChangeView(View, generic.UpdateView):
template_name:str = 'form.html.j2'
+ # ToDo: on migrating all views to seperate display and change views, external_links will not be required in `ChangView`
+ def get_context_data(self, **kwargs):
+ """ Get template context
+
+ For items that have the ability to have external links, this function
+ adds the external link details to the context.
+
+ !!! Danger "Requirement"
+ This function may be overridden with the caveat that this function is still called.
+ by the overriding function. i.e. `super().get_context_data(skwargs)`
+
+ !!! note
+ The adding of `external_links` within this view is scheduled to be removed.
+
+ Returns:
+ (dict): Context for the template to use inclusive of 'external_links'
+ """
+
+ context = super().get_context_data(**kwargs)
+
+ external_links_query = None
+
+
+ if self.model._meta.model_name == 'device':
+
+ external_links_query = ExternalLink.objects.filter(devices=True)
+
+ elif self.model._meta.model_name == 'software':
+
+ external_links_query = ExternalLink.objects.filter(software=True)
+
+
+ if external_links_query:
+
+ external_links: list = []
+
+ user_context = Context(context)
+
+ for external_link in external_links_query:
+
+ user_string = Template(external_link)
+ external_link_context: dict = {
+ 'name': escape(external_link.name),
+ 'link': escape(user_string.render(user_context)),
+ }
+
+ if external_link.colour:
+
+ external_link_context.update({'colour': external_link.colour })
+ external_links += [ external_link_context ]
+
+ context['external_links'] = external_links
+
+
+ return context
class DeleteView(OrganizationPermission, generic.DeleteView):
@@ -64,6 +122,60 @@ class DisplayView(OrganizationPermission, generic.DetailView):
template_name:str = 'form.html.j2'
+ # ToDo: on migrating all views to seperate display and change views, external_links will not be required in `ChangView`
+ def get_context_data(self, **kwargs):
+ """ Get template context
+
+ For items that have the ability to have external links, this function
+ adds the external link details to the context.
+
+ !!! Danger "Requirement"
+ This function may be overridden with the caveat that this function is still called.
+ by the overriding function. i.e. `super().get_context_data(skwargs)`
+
+ Returns:
+ (dict): Context for the template to use inclusive of 'external_links'
+ """
+
+ context = super().get_context_data(**kwargs)
+
+ external_links_query = None
+
+
+ if self.model._meta.model_name == 'device':
+
+ external_links_query = ExternalLink.objects.filter(devices=True)
+
+ elif self.model._meta.model_name == 'software':
+
+ external_links_query = ExternalLink.objects.filter(software=True)
+
+
+ if external_links_query:
+
+ external_links: list = []
+
+ user_context = Context(context)
+
+ for external_link in external_links_query:
+
+ user_string = Template(external_link)
+ external_link_context: dict = {
+ 'name': escape(external_link.name),
+ 'link': escape(user_string.render(user_context)),
+ }
+
+ if external_link.colour:
+
+ external_link_context.update({'colour': external_link.colour })
+ external_links += [ external_link_context ]
+
+ context['external_links'] = external_links
+
+
+ return context
+
+
class IndexView(View, generic.ListView):
diff --git a/app/core/views/history.py b/app/core/views/history.py
index be6d44bc..5b95b5ab 100644
--- a/app/core/views/history.py
+++ b/app/core/views/history.py
@@ -41,6 +41,8 @@ class View(OrganizationPermission, generic.View):
from config_management.models.groups import ConfigGroups
+ from settings.models.external_link import ExternalLink
+
if not hasattr(self, 'model'):
match self.kwargs['model_name']:
@@ -61,6 +63,10 @@ class View(OrganizationPermission, generic.View):
self.model = DeviceType
+ case 'externallink':
+
+ self.model = ExternalLink
+
case 'manufacturer':
self.model = Manufacturer
diff --git a/app/itam/templates/itam/device.html.j2 b/app/itam/templates/itam/device.html.j2
index e145329f..15c9beb5 100644
--- a/app/itam/templates/itam/device.html.j2
+++ b/app/itam/templates/itam/device.html.j2
@@ -83,7 +83,9 @@
Details
- {% include 'icons/issue_link.html.j2' with issue=6 %}
+ {% for external_link in external_links %}
+ {% include 'icons/external_link.html.j2' with external_link=external_link %}
+ {% endfor %}