mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
#8366: Misc cleanup
This commit is contained in:
@ -2,7 +2,7 @@ from django import forms
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from utilities.forms import BootstrapMixin, DateTimePicker
|
from utilities.forms import BootstrapMixin, DateTimePicker, SelectDurationWidget
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ReportForm',
|
'ReportForm',
|
||||||
@ -20,6 +20,7 @@ class ReportForm(BootstrapMixin, forms.Form):
|
|||||||
required=False,
|
required=False,
|
||||||
min_value=1,
|
min_value=1,
|
||||||
label=_("Recurs every"),
|
label=_("Recurs every"),
|
||||||
|
widget=SelectDurationWidget(),
|
||||||
help_text=_("Interval at which this report is re-run (in minutes)")
|
help_text=_("Interval at which this report is re-run (in minutes)")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,3 +30,10 @@ class ReportForm(BootstrapMixin, forms.Form):
|
|||||||
raise forms.ValidationError(_('Scheduled time must be in the future.'))
|
raise forms.ValidationError(_('Scheduled time must be in the future.'))
|
||||||
|
|
||||||
return scheduled_time
|
return scheduled_time
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# Annotate the current system time for reference
|
||||||
|
now = timezone.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
self.fields['schedule_at'].help_text += f' (current time: <strong>{now}</strong>)'
|
||||||
|
@ -2,7 +2,7 @@ from django import forms
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from utilities.forms import BootstrapMixin, DateTimePicker
|
from utilities.forms import BootstrapMixin, DateTimePicker, SelectDurationWidget
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ScriptForm',
|
'ScriptForm',
|
||||||
@ -26,12 +26,17 @@ class ScriptForm(BootstrapMixin, forms.Form):
|
|||||||
required=False,
|
required=False,
|
||||||
min_value=1,
|
min_value=1,
|
||||||
label=_("Recurs every"),
|
label=_("Recurs every"),
|
||||||
|
widget=SelectDurationWidget(),
|
||||||
help_text=_("Interval at which this script is re-run (in minutes)")
|
help_text=_("Interval at which this script is re-run (in minutes)")
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# Annotate the current system time for reference
|
||||||
|
now = timezone.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
self.fields['_schedule_at'].help_text += f' (current time: <strong>{now}</strong>)'
|
||||||
|
|
||||||
# Move _commit and _schedule_at to the end of the form
|
# Move _commit and _schedule_at to the end of the form
|
||||||
schedule_at = self.fields.pop('_schedule_at')
|
schedule_at = self.fields.pop('_schedule_at')
|
||||||
interval = self.fields.pop('_interval')
|
interval = self.fields.pop('_interval')
|
||||||
|
@ -34,33 +34,32 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<div role="tabpanel" class="tab-pane active" id="report">
|
<div role="tabpanel" class="tab-pane active" id="report">
|
||||||
{% if perms.extras.run_report %}
|
{% if perms.extras.run_report %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<form action="{% url 'extras:report' module=report.module name=report.class_name %}" method="post" class="form-object-edit">
|
<form action="{% url 'extras:report' module=report.module name=report.class_name %}" method="post" class="form-object-edit">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% render_form form %}
|
{% render_form form %}
|
||||||
<div class="float-end">
|
<div class="float-end">
|
||||||
<button type="submit" name="_run" class="btn btn-primary">
|
<button type="submit" name="_run" class="btn btn-primary">
|
||||||
{% if report.result %}
|
{% if report.result %}
|
||||||
<i class="mdi mdi-replay"></i> Run Again
|
<i class="mdi mdi-replay"></i> Run Again
|
||||||
{% else %}
|
{% else %}
|
||||||
<i class="mdi mdi-play"></i> Run Report
|
<i class="mdi mdi-play"></i> Run Report
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col col-md-12">
|
<div class="col col-md-12">
|
||||||
{% if report.result %}
|
{% if report.result %}
|
||||||
Last run: <a href="{% url 'extras:report_result' job_result_pk=report.result.pk %}">
|
Last run: <a href="{% url 'extras:report_result' job_result_pk=report.result.pk %}">
|
||||||
<strong>{{ report.result.created|annotated_date }}</strong>
|
<strong>{{ report.result.created|annotated_date }}</strong>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
@ -17,6 +17,7 @@ __all__ = (
|
|||||||
'DatePicker',
|
'DatePicker',
|
||||||
'DateTimePicker',
|
'DateTimePicker',
|
||||||
'NumericArrayField',
|
'NumericArrayField',
|
||||||
|
'SelectDurationWidget',
|
||||||
'SelectSpeedWidget',
|
'SelectSpeedWidget',
|
||||||
'SelectWithPK',
|
'SelectWithPK',
|
||||||
'SlugWidget',
|
'SlugWidget',
|
||||||
@ -108,6 +109,13 @@ class SelectSpeedWidget(forms.NumberInput):
|
|||||||
template_name = 'widgets/select_speed.html'
|
template_name = 'widgets/select_speed.html'
|
||||||
|
|
||||||
|
|
||||||
|
class SelectDurationWidget(forms.NumberInput):
|
||||||
|
"""
|
||||||
|
Dropdown to select one of several common options for a time duration (in minutes).
|
||||||
|
"""
|
||||||
|
template_name = 'widgets/select_duration.html'
|
||||||
|
|
||||||
|
|
||||||
class NumericArrayField(SimpleArrayField):
|
class NumericArrayField(SimpleArrayField):
|
||||||
|
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
|
11
netbox/utilities/templates/widgets/select_duration.html
Normal file
11
netbox/utilities/templates/widgets/select_duration.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<div class="input-group">
|
||||||
|
{% include 'django/forms/widgets/number.html' %}
|
||||||
|
<button type="button" class="btn btn-outline-dark border-input dropdown-toggle" data-bs-toggle="dropdown"></button>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-end">
|
||||||
|
<li><a href="#" target="id_{{ widget.name }}" data="60" class="set_speed dropdown-item">Hourly</a></li>
|
||||||
|
<li><a href="#" target="id_{{ widget.name }}" data="720" class="set_speed dropdown-item">12 hours</a></li>
|
||||||
|
<li><a href="#" target="id_{{ widget.name }}" data="1440" class="set_speed dropdown-item">Daily</a></li>
|
||||||
|
<li><a href="#" target="id_{{ widget.name }}" data="10080" class="set_speed dropdown-item">Weekly</a></li>
|
||||||
|
<li><a href="#" target="id_{{ widget.name }}" data="43200" class="set_speed dropdown-item">30 days</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
Reference in New Issue
Block a user