From e46cf447753f8e5c8987ff62cdd7d52d56019385 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 18 Aug 2024 15:41:05 +0930 Subject: [PATCH] feat(itim): Ability to add external link to cluster ref: #244 #71 #6 --- app/core/views/common.py | 6 +- app/itim/templates/itim/cluster.html.j2 | 14 +- app/itim/views/clusters.py | 2 +- app/settings/forms/external_links.py | 69 ++++++- .../migrations/0004_externallink_cluster.py | 18 ++ app/settings/models/external_link.py | 7 + .../templates/settings/external_link.html.j2 | 191 ++---------------- app/settings/views/external_link.py | 4 +- .../user/settings/external_links.md | 4 +- 9 files changed, 123 insertions(+), 192 deletions(-) create mode 100644 app/settings/migrations/0004_externallink_cluster.py diff --git a/app/core/views/common.py b/app/core/views/common.py index a1350afa2..42f86c920 100644 --- a/app/core/views/common.py +++ b/app/core/views/common.py @@ -83,7 +83,11 @@ def get_context_data(self, **kwargs): context['open_tab'] = None - if self.model._meta.model_name == 'device': + if self.model._meta.model_name == 'cluster': + + external_links_query = ExternalLink.objects.filter(cluster=True) + + elif self.model._meta.model_name == 'device': external_links_query = ExternalLink.objects.filter(devices=True) diff --git a/app/itim/templates/itim/cluster.html.j2 b/app/itim/templates/itim/cluster.html.j2 index ad5415630..f04afe842 100644 --- a/app/itim/templates/itim/cluster.html.j2 +++ b/app/itim/templates/itim/cluster.html.j2 @@ -21,8 +21,8 @@ Name Organization - {% if item.nodes.all %} - {% for node in item.nodes.all %} + {% if cluster.nodes.all %} + {% for node in cluster.nodes.all %} {{ node }} {{ node.organization }} @@ -46,8 +46,8 @@ Name Organization - {% if item.devices.all %} - {% for device in item.devices.all %} + {% if cluster.devices.all %} + {% for device in cluster.devices.all %} {{ device }} {{ device.organization }} @@ -73,8 +73,8 @@ Name Ports - {% if item.services.all %} - {% for device in item.devices.all %} + {% if cluster.services.all %} + {% for device in cluster.devices.all %} @@ -91,7 +91,7 @@

Config

-
{{ item.config | json_pretty }}
+
{{ cluster.config | json_pretty }}
diff --git a/app/itim/views/clusters.py b/app/itim/views/clusters.py index a62f4a999..e02806ede 100644 --- a/app/itim/views/clusters.py +++ b/app/itim/views/clusters.py @@ -134,7 +134,7 @@ def get_context_data(self, **kwargs): class View(ChangeView): - context_object_name = "item" + context_object_name = "cluster" form_class = DetailForm diff --git a/app/settings/forms/external_links.py b/app/settings/forms/external_links.py index 51061defc..4537e264c 100644 --- a/app/settings/forms/external_links.py +++ b/app/settings/forms/external_links.py @@ -1,10 +1,12 @@ -from django import forms -from django.db.models import Q -from django.contrib.auth.models import User +from django import forms +# from django.contrib.auth.models import User +from django.urls import reverse from access.models import Organization, TeamUsers +from app import settings + from core.forms.common import CommonModelForm from settings.models.external_link import ExternalLink @@ -19,3 +21,64 @@ class Meta: fields = '__all__' model = ExternalLink + + + +class DetailForm(ExternalLinksForm): + + tabs: dict = { + "details": { + "name": "Details", + "slug": "details", + "sections": [ + { + "layout": "double", + "left": [ + 'organization', + 'name', + 'template', + 'colour', + 'cluster', + 'devices' + 'software', + 'c_created', + 'c_modified', + ], + "right": [ + 'model_notes', + ] + } + ] + }, + "notes": { + "name": "Notes", + "slug": "notes", + "sections": [] + }, + } + + + def __init__(self, *args, **kwargs): + + super().__init__(*args, **kwargs) + + + self.fields['c_created'] = forms.DateTimeField( + label = 'Created', + input_formats=settings.DATETIME_FORMAT, + disabled = True, + initial = self.instance.created, + ) + + self.fields['c_modified'] = forms.DateTimeField( + label = 'Modified', + input_formats=settings.DATETIME_FORMAT, + disabled = True, + initial = self.instance.modified, + ) + + self.tabs['details'].update({ + "edit_url": reverse('Settings:_external_link_change', args=(self.instance.pk,)) + }) + + self.url_index_view = reverse('Settings:External Links') diff --git a/app/settings/migrations/0004_externallink_cluster.py b/app/settings/migrations/0004_externallink_cluster.py new file mode 100644 index 000000000..0581ed06e --- /dev/null +++ b/app/settings/migrations/0004_externallink_cluster.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.7 on 2024-08-18 05:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('settings', '0003_alter_externallink_options'), + ] + + operations = [ + migrations.AddField( + model_name='externallink', + name='cluster', + field=models.BooleanField(default=False, help_text='Render link for clusters', verbose_name='Clusters'), + ), + ] diff --git a/app/settings/models/external_link.py b/app/settings/models/external_link.py index 427811f3d..92b5e622a 100644 --- a/app/settings/models/external_link.py +++ b/app/settings/models/external_link.py @@ -47,6 +47,13 @@ class Meta: verbose_name = 'Button Colour', ) + cluster = models.BooleanField( + default = False, + blank = False, + help_text = 'Render link for clusters', + verbose_name = 'Clusters', + ) + devices = models.BooleanField( default = False, blank = False, diff --git a/app/settings/templates/settings/external_link.html.j2 b/app/settings/templates/settings/external_link.html.j2 index e16e75e1a..086cea639 100644 --- a/app/settings/templates/settings/external_link.html.j2 +++ b/app/settings/templates/settings/external_link.html.j2 @@ -1,194 +1,31 @@ -{% extends 'base.html.j2' %} +{% extends 'detail.html.j2' %} +{% load json %} {% load markdown %} -{% block title %}{{ externallink.name }}{% endblock %} -{% block content %} +{% block tabs %} - - -
- - -
- -
- {% csrf_token %} - - -
-

- Details - {% for external_link in external_links %} - {% include 'icons/external_link.html.j2' with external_link=external_link %} - {% endfor %} -

-
- -
- -
- - {{ externallink.organization }} -
- -
- - {{ form.name.value }} -
- -
- - {{ externallink.template }} -
-
- - - {% if form.colour.value %} - {{ form.colour.value }} - {% else %} -   - {% endif %} - -
-
- - {{ form.devices.value }} -
+
-
- - {{ externallink.software }} -
- -
- - {{ externallink.created }} -
- -
- - {{ externallink.modified }} -
- -
- -
-
- - -
- {% if form.model_notes.value %} - {{ form.model_notes.value | markdown | safe }} - {% else %} -   - {% endif %} -
-
-
-
- - - - - - - {% if not tab %} - - {% endif %} - -
- - - - -
-

- Notes -

+ {% include 'content/section.html.j2' with tab=form.tabs.notes %} {{ notes_form }}
- {% if notes %} - {% for note in notes%} - {% include 'note.html.j2' %} - {% endfor %} - {% endif %} + {% if notes %} + {% for note in notes%} + {% include 'note.html.j2' %} + {% endfor %} + {% endif %}
- {% if tab == 'notes' %} - - {% endif %} -
- +
-
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/settings/views/external_link.py b/app/settings/views/external_link.py index 6ebc2b1bd..f25d762a3 100644 --- a/app/settings/views/external_link.py +++ b/app/settings/views/external_link.py @@ -9,7 +9,7 @@ from core.views.common import AddView, ChangeView, DeleteView, DisplayView, IndexView -from settings.forms.external_links import ExternalLinksForm +from settings.forms.external_links import DetailForm, ExternalLinksForm from settings.models.external_link import ExternalLink @@ -44,7 +44,7 @@ class View(ChangeView): context_object_name = "externallink" - form_class = ExternalLinksForm + form_class = DetailForm model = ExternalLink diff --git a/docs/projects/centurion_erp/user/settings/external_links.md b/docs/projects/centurion_erp/user/settings/external_links.md index 1f20e5c99..4cb428d16 100644 --- a/docs/projects/centurion_erp/user/settings/external_links.md +++ b/docs/projects/centurion_erp/user/settings/external_links.md @@ -11,8 +11,10 @@ External Links allow an end user to specify by means of a jinja template a link ## Create a link -- Software context is under key `software` +- Cluster context is under key `cluster` - Device context is under key `device` +- Software context is under key `software` + To add a templated link within the `Link Template` field enter your url, with the variable within jinja braces. for example to add a link that will expand with the devices id, specify `{{ device.id }}`. i.e. `https://domainname.tld/{{ device.id }}`. If the link is for software use key `software`. Available fields under context key all of those that are available at the time the page is rendered.