Skip to content

Commit

Permalink
feat(itim): Ability to add and configure Cluster Types
Browse files Browse the repository at this point in the history
ref: #244 #71
  • Loading branch information
jon-nfc committed Aug 23, 2024
1 parent b65e577 commit 75203c0
Show file tree
Hide file tree
Showing 10 changed files with 405 additions and 21 deletions.
6 changes: 6 additions & 0 deletions app/core/views/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def get_object(self):

self.model = Cluster

case 'clustertype':

from itim.models.clusters import ClusterType

self.model = ClusterType

case 'configgroups':

self.model = ConfigGroups
Expand Down
84 changes: 84 additions & 0 deletions app/itim/forms/cluster_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from django import forms
from django.forms import ValidationError
from django.urls import reverse

from itim.models.clusters import ClusterType

from app import settings

from core.forms.common import CommonModelForm



class ClusterTypeForm(CommonModelForm):


class Meta:

fields = '__all__'

model = ClusterType

prefix = 'cluster_type'

def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)



class DetailForm(ClusterTypeForm):


tabs: dict = {
"details": {
"name": "Details",
"slug": "details",
"sections": [
{
"layout": "double",
"left": [
'name',
'organization',
'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:_cluster_type_change', args=(self.instance.pk,))
})

self.url_index_view = reverse('Settings:_cluster_types')

4 changes: 2 additions & 2 deletions app/itim/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Migration(migrations.Migration):
('organization', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='access.organization', validators=[access.models.TenancyObject.validatate_organization_exists])),
],
options={
'verbose_name': 'ClusterType',
'verbose_name_plural': 'ClusterTypes',
'verbose_name': 'Cluster Type',
'verbose_name_plural': 'Cluster Types',
'ordering': ['name'],
},
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.0.7 on 2024-08-18 03:57

import access.fields
import django.utils.timezone
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('itim', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='clustertype',
name='created',
field=access.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False),
),
migrations.AddField(
model_name='clustertype',
name='modified',
field=access.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False),
),
]
13 changes: 11 additions & 2 deletions app/itim/models/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class Meta:
'name',
]

verbose_name = "ClusterType"
verbose_name = "Cluster Type"

verbose_name_plural = "ClusterTypes"
verbose_name_plural = "Cluster Types"


id = models.AutoField(
Expand All @@ -39,6 +39,15 @@ class Meta:

slug = AutoSlugField()

created = AutoCreatedField()

modified = AutoLastModifiedField()


def __str__(self):

return self.name



class Cluster(TenancyObject):
Expand Down
22 changes: 22 additions & 0 deletions app/itim/templates/itim/cluster_type.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends 'detail.html.j2' %}

{% load json %}
{% load markdown %}


{% block tabs %}

<div id="details" class="content-tab">

{% include 'content/section.html.j2' with tab=form.tabs.details %}

</div>


<div id="notes" class="content-tab">

{% include 'content/section.html.j2' with tab=form.tabs.notes %}

</div>

{% endblock %}
47 changes: 47 additions & 0 deletions app/itim/templates/itim/cluster_type_index.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% extends 'base.html.j2' %}

{% block content %}

<input type="button" value="New Cluster Type" onclick="window.location='{% url 'Settings:_cluster_type_add' %}';">
<table class="data">
<tr>
<th>Title</th>
<th>&nbsp;</th>
<th>Organization</th>
<th>&nbsp;</th>
</tr>
{% if items %}
{% for item in items %}
<tr>
<td><a href="{% url 'Settings:_cluster_type_view' pk=item.id %}">{{ item.name }}</a></td>
<td>&nbsp;</td>
<td>{{ item.organization }}</td>
<td>&nbsp;</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="4">Nothing Found</td>
</tr>
{% endif %}
</table>
<br>
<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page=1">&laquo; first</a>
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}

<span class="current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>

{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a>
{% endif %}
</span>
</div>

{% endblock %}
Loading

0 comments on commit 75203c0

Please sign in to comment.