Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: #18241 - Script results log_threshold should default to Default #18501

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion netbox/extras/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ class LogLevelChoices(ChoiceSet):
LOG_FAILURE = 'failure'

CHOICES = (
(LOG_DEBUG, _('Debug'), 'teal'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed? I think the ordering is supposed to be of increasing severity. Also this should stay consistent with the order of the constants above and in LOG_LEVEL_RANK.

Is there something gained by changing the order here and the .first to .last in the template?

(LOG_DEFAULT, _('Default'), 'gray'),
(LOG_INFO, _('Info'), 'cyan'),
(LOG_SUCCESS, _('Success'), 'green'),
(LOG_WARNING, _('Warning'), 'yellow'),
(LOG_FAILURE, _('Failure'), 'red'),
(LOG_DEBUG, _('Debug'), 'teal'),
)

SYSTEM_LEVELS = {
Expand Down
8 changes: 4 additions & 4 deletions netbox/extras/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,9 +1315,9 @@ def get_table(self, job, request, bulk_actions=True):
index = 0

try:
log_threshold = LOG_LEVEL_RANK[request.GET.get('log_threshold', LogLevelChoices.LOG_DEBUG)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these supposed to be changed?

log_threshold = LOG_LEVEL_RANK[request.GET.get('log_threshold', LogLevelChoices.LOG_DEFAULT)]
except KeyError:
log_threshold = LOG_LEVEL_RANK[LogLevelChoices.LOG_DEBUG]
log_threshold = LOG_LEVEL_RANK[LogLevelChoices.LOG_DEFAULT]
if job.data:

if 'log' in job.data:
Expand Down Expand Up @@ -1374,9 +1374,9 @@ def get(self, request, **kwargs):
if job.completed:
table = self.get_table(job, request, bulk_actions=False)

log_threshold = request.GET.get('log_threshold', LogLevelChoices.LOG_DEBUG)
log_threshold = request.GET.get('log_threshold', LogLevelChoices.LOG_DEFAULT)
if log_threshold not in LOG_LEVEL_RANK:
log_threshold = LogLevelChoices.LOG_DEBUG
log_threshold = LogLevelChoices.LOG_DEFAULT

context = {
'script': job.object,
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/extras/script_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<div class="dropdown-menu">
{% for level, name in log_levels.items %}
<a class="dropdown-item d-flex justify-content-between" href="{% url 'extras:script_result' job_pk=job.pk %}?log_threshold={{ level }}">
{{ name }}{% if forloop.first %} ({% trans "All" %}){% endif %}
{{ name }}{% if forloop.last %} ({% trans "All" %}){% endif %}
{% if level == log_threshold %}<span class="badge bg-green ms-auto"></span>{% endif %}
</a>
{% endfor %}
Expand Down
Loading