-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/DanSheps/netbox-support-…
…contract into develop
- Loading branch information
Showing
6 changed files
with
179 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
from django.contrib.contenttypes.models import ContentType | ||
from django.template import Template | ||
from netbox.plugins import PluginTemplateExtension | ||
|
||
from .models import hardware, contract | ||
|
||
|
||
class DeviceHardwareInfoExtension(PluginTemplateExtension): | ||
def right_page(self): | ||
object = self.context.get('object') | ||
support_contract = contract.SupportContractAssignment.objects.filter(device_id=self.context['object'].id).first() | ||
match self.kind: | ||
case "device": | ||
content_type = ContentType.objects.get(app_label="dcim", model="devicetype") | ||
lifecycle_info = hardware.HardwareLifecycle.objects.filter(assigned_object_id=self.context['object'].device_type_id, | ||
assigned_object_type_id=content_type.id).first() | ||
case "module": | ||
content_type = ContentType.objects.get(app_label="dcim", model="moduletype") | ||
lifecycle_info = hardware.HardwareLifecycle.objects.filter(assigned_object_id=self.context['object'].module_type_id, | ||
assigned_object_type_id=content_type.id).first() | ||
case "devicetype" | "moduletype": | ||
content_type = ContentType.objects.get(app_label="dcim", model=self.kind) | ||
lifecycle_info = hardware.HardwareLifecycle.objects.filter(assigned_object_id=self.context['object'].id, | ||
assigned_object_type_id=content_type.id).first() | ||
context = {'support_contract': support_contract, 'lifecycle_info': lifecycle_info} | ||
return self.render('netbox_lifecycle/inc/support_contract_info.html', extra_context=context) | ||
|
||
|
||
class TypeInfoExtension(PluginTemplateExtension): | ||
def right_page(self): | ||
object = self.context.get('object') | ||
match self.kind: | ||
case "device": | ||
content_type = ContentType.objects.get(app_label="dcim", model="devicetype") | ||
lifecycle_info = hardware.HardwareLifecycle.objects.filter(assigned_object_id=self.context['object'].device_type_id, | ||
assigned_object_type_id=content_type.id).first() | ||
case "module": | ||
content_type = ContentType.objects.get(app_label="dcim", model="moduletype") | ||
lifecycle_info = hardware.HardwareLifecycle.objects.filter(assigned_object_id=self.context['object'].module_type_id, | ||
assigned_object_type_id=content_type.id).first() | ||
case "devicetype" | "moduletype": | ||
content_type = ContentType.objects.get(app_label="dcim", model=self.kind) | ||
lifecycle_info = hardware.HardwareLifecycle.objects.filter(assigned_object_id=self.context['object'].id, | ||
assigned_object_type_id=content_type.id).first() | ||
|
||
context = {'lifecycle_info': lifecycle_info} | ||
return self.render('netbox_lifecycle/inc/hardware_lifecycle_info.html', extra_context=context) | ||
|
||
|
||
class DeviceHardwareLifecycleInfo(DeviceHardwareInfoExtension): | ||
model = 'dcim.device' | ||
kind = 'device' | ||
|
||
|
||
class ModuleHardwareLifecycleInfo(TypeInfoExtension): | ||
model = 'dcim.module' | ||
kind = 'module' | ||
|
||
|
||
class DeviceTypeHardwareLifecycleInfo(TypeInfoExtension): | ||
model = 'dcim.devicetype' | ||
kind = 'devicetype' | ||
|
||
|
||
class ModuleTypeHardwareLifecycleInfo(TypeInfoExtension): | ||
model = 'dcim.moduletype' | ||
kind = 'moduletype' | ||
|
||
|
||
template_extensions = ( | ||
DeviceHardwareLifecycleInfo, | ||
ModuleHardwareLifecycleInfo, | ||
DeviceTypeHardwareLifecycleInfo, | ||
ModuleTypeHardwareLifecycleInfo, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
netbox_lifecycle/templates/netbox_lifecycle/inc/hardware_lifecycle_info.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
{% load filters %} | ||
{% load helpers %} | ||
{# renders panel on object with lifecycle info assigned to it #} | ||
|
||
<div class="card"> | ||
<h5 class="card-header">Lifecycle Dates</h5> | ||
{% if lifecycle_info %} | ||
<table class="table table-hover attr-table"> | ||
<tr> | ||
<td>End of Sale</td> | ||
<td><span {{ lifecycle_info.end_of_sale|date_badge_class }}>{{ lifecycle_info.end_of_sale }}</span></td> | ||
</tr> | ||
<tr> | ||
<td>End of Maintenance Updates</td> | ||
<td><span {{ lifecycle_info.end_of_maintenance|date_badge_class }}>{{ lifecycle_info.end_of_maintenance }}</span></td> | ||
</tr> | ||
<tr> | ||
<td>End of Security Updates</td> | ||
<td><span {{ lifecycle_info.end_of_security|date_badge_class }}>{{ lifecycle_info.end_of_security }}</span></td> | ||
</tr> | ||
<tr> | ||
<td>Last Support Contract Purchase Date</td> | ||
<td><span {{ lifecycle_info.last_contract_date|date_badge_class }}>{{ lifecycle_info.last_contract_date }}</span></td> | ||
</tr> | ||
<tr> | ||
<td>End of Support</td> | ||
<td><span {{ lifecycle_info.end_of_support|date_badge_class }}>{{ lifecycle_info.end_of_support }}</span></td> | ||
</tr> | ||
</table> | ||
{% else %} | ||
<div class="card-body"><span class="text-muted">No Lifecycle Dates Defined</span></div> | ||
{% endif %} | ||
</div> |
36 changes: 36 additions & 0 deletions
36
netbox_lifecycle/templates/netbox_lifecycle/inc/support_contract_info.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
{% load filters %} | ||
{% load helpers %} | ||
{# renders panel on object (device) with support contract info assigned to it #} | ||
|
||
<div class="card"> | ||
<h5 class="card-header">Support Contract</h5> | ||
{% if support_contract %} | ||
<table class="table table-hover attr-table"> | ||
<tr> | ||
<th scope="row"><span title="Contract Number">Contract Number</span></th> | ||
<td>{{ support_contract.contract.contract_id|linkify|placeholder }}</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Support SKU</th> | ||
<td>{{ support_contract.sku }}</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Start Date</th> | ||
<td>{{ support_contract.contract.start }}</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">End Date</th> | ||
{% if support_contract.end == None %} | ||
<td><span {{ support_contract.contract.end|date_badge_class }}>{{ support_contract.contract.end }}</span></td> | ||
{% else %} | ||
<td><span {{ support_contract.end|date_badge_class }}>{{ support_contract.end }}</span></td> | ||
{% endif %} | ||
</tr> | ||
</table> | ||
{% else %} | ||
<div class="card-body"><span class="text-muted">No Support Contract Assigned<span></div> | ||
{% endif %} | ||
</div> | ||
|
||
{% include "netbox_lifecycle/inc/hardware_lifecycle_info.html" %} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from datetime import datetime, date | ||
from dateutil.relativedelta import relativedelta | ||
from django import template | ||
from django.utils.safestring import mark_safe | ||
|
||
register = template.Library() | ||
|
||
|
||
def is_expired(value): | ||
return value < datetime.now().date() | ||
|
||
|
||
def expires_within_six_months(value): | ||
return value < (date.today() + relativedelta(months=+6)) | ||
|
||
|
||
@register.filter(is_safe=True) | ||
def date_badge_class(value): | ||
if not value: | ||
return | ||
|
||
if is_expired(value): | ||
return mark_safe('class="badge text-bg-danger"') | ||
elif expires_within_six_months(value): | ||
return mark_safe('class="badge text-bg-warning"') | ||
else: | ||
return mark_safe('class="badge text-bg-success"') |