Skip to content

Commit

Permalink
Merge pull request #214 from usnistgov/5.5.0.dev
Browse files Browse the repository at this point in the history
5.5.0.dev
  • Loading branch information
rptmat57 authored Apr 17, 2024
2 parents 1488755 + 811605b commit b36a6e2
Show file tree
Hide file tree
Showing 72 changed files with 3,561 additions and 405 deletions.
5 changes: 5 additions & 0 deletions NEMO/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ def adjustment_requests_export_csv(modeladmin, request, queryset):
return adjustments_csv_export(queryset.all())


@admin.action(description="Mark selected adjustment requests as applied")
def adjustment_requests_mark_as_applied(modeladmin, request, queryset):
return queryset.update(applied=True, applied_by=request.user)


@admin.action(description="Export selected access requests in CSV")
def access_requests_export_csv(modeladmin, request, queryset):
return access_csv_export(queryset.all())
Expand Down
53 changes: 51 additions & 2 deletions NEMO/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import datetime
import json

from django import forms
from django.contrib import admin
from django.contrib import admin, messages
from django.contrib.admin import register
from django.contrib.admin.decorators import display
from django.contrib.admin.widgets import FilteredSelectMultiple
Expand All @@ -18,6 +19,7 @@
from NEMO.actions import (
access_requests_export_csv,
adjustment_requests_export_csv,
adjustment_requests_mark_as_applied,
create_next_interlock,
disable_selected_cards,
duplicate_configuration,
Expand Down Expand Up @@ -102,6 +104,7 @@
ToolDocuments,
ToolQualificationGroup,
ToolUsageCounter,
ToolWaitList,
TrainingSession,
UsageEvent,
User,
Expand Down Expand Up @@ -183,6 +186,22 @@ def __init__(self, *args, **kwargs):
self.fields["required_resources"].initial = self.instance.required_resource_set.all()
self.fields["nonrequired_resources"].initial = self.instance.nonrequired_resource_set.all()

def clean__pre_usage_questions(self):
questions = self.cleaned_data["_pre_usage_questions"]
try:
return json.dumps(json.loads(questions), indent=4)
except:
pass
return questions

def clean__post_usage_questions(self):
questions = self.cleaned_data["_post_usage_questions"]
try:
return json.dumps(json.loads(questions), indent=4)
except:
pass
return questions

def clean(self):
cleaned_data = super().clean()
image = cleaned_data.get("_image")
Expand Down Expand Up @@ -240,6 +259,7 @@ class ToolAdmin(admin.ModelAdmin):
"name",
"parent_tool",
"_category",
"_operation_mode",
"qualified_users",
"_qualifications_never_expire",
"_pre_usage_questions",
Expand Down Expand Up @@ -322,6 +342,13 @@ def save_model(self, request, obj, form, change):
"""
Explicitly record any project membership changes on non-child tools.
"""
if not obj.allow_wait_list() and obj.current_wait_list():
obj.current_wait_list().update(deleted=True)
messages.warning(
request,
f"The wait list for {obj} has been deleted because the current operation mode does not allow it.",
)

if obj.parent_tool:
super(ToolAdmin, self).save_model(request, obj, form, change)
else:
Expand All @@ -334,6 +361,12 @@ def save_model(self, request, obj, form, change):
obj.nonrequired_resource_set.set(form.cleaned_data["nonrequired_resources"])


@register(ToolWaitList)
class ToolWaitList(admin.ModelAdmin):
list_display = ["tool", "user", "date_entered", "date_exited", "expired", "deleted"]
list_filter = ["deleted", "expired", "tool"]


@register(ToolQualificationGroup)
class ToolQualificationGroup(admin.ModelAdmin):
list_display = ["name", "get_tools"]
Expand Down Expand Up @@ -484,16 +517,22 @@ class ConfigurationAdmin(admin.ModelAdmin):
list_display = (
"id",
"tool",
"is_tool_visible",
"name",
"enabled",
"qualified_users_are_maintainers",
"display_order",
"exclude_from_configuration_agenda",
)
list_filter = ["enabled", ("tool", admin.RelatedOnlyFieldListFilter), "tool__visible"]
filter_horizontal = ("maintainers",)
actions = [duplicate_configuration]
autocomplete_fields = ["tool"]

@admin.display(ordering="tool__visible", boolean=True, description="Tool visible")
def is_tool_visible(self, obj: Configuration):
return obj.tool.visible


@register(ConfigurationHistory)
class ConfigurationHistoryAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -637,6 +676,14 @@ class Media:
js = ("admin/dynamic_form_preview/dynamic_form_preview.js",)
css = {"": ("admin/dynamic_form_preview/dynamic_form_preview.css",)}

def clean_questions(self):
questions = self.cleaned_data["questions"]
try:
return json.dumps(json.loads(questions), indent=4)
except:
pass
return questions

def clean(self):
cleaned_data = super().clean()
reservation_questions = cleaned_data.get("questions")
Expand Down Expand Up @@ -1648,16 +1695,18 @@ class AdjustmentRequestAdmin(admin.ModelAdmin):
"get_time_difference",
"get_status_display",
"reply_count",
"applied",
"deleted",
)
list_filter = (
"status",
"deleted",
"applied",
("creator", admin.RelatedOnlyFieldListFilter),
("reviewer", admin.RelatedOnlyFieldListFilter),
)
date_hierarchy = "last_updated"
actions = [adjustment_requests_export_csv]
actions = [adjustment_requests_export_csv, adjustment_requests_mark_as_applied]

@admin.display(description="Diff")
def get_time_difference(self, adjustment_request: AdjustmentRequest):
Expand Down
2 changes: 1 addition & 1 deletion NEMO/apps/area_access/templates/area_access/alerts.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h2>Alerts and outages</h2>
<span style="font-weight:bold">{{ a.title }}</span>
<br>
{% endif %}
{{ a.contents|linebreaks }}
{{ a.contents|safe|linebreaksbr }}
</td>
</tr>
</table>
Expand Down
5 changes: 4 additions & 1 deletion NEMO/apps/area_access/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.utils.formats import localize
from django.views.decorators.http import require_GET, require_POST

from NEMO.decorators import postpone
from NEMO.decorators import disable_session_expiry_refresh, postpone
from NEMO.exceptions import (
InactiveUserError,
MaximumCapacityReachedError,
Expand Down Expand Up @@ -352,6 +352,9 @@ def get_badge_reader(request) -> BadgeReader:
return badge_reader


@login_required
@disable_session_expiry_refresh
@require_GET
def get_alerts(request):
dictionary = {
"alerts": Alert.objects.filter(user=None, debut_time__lte=timezone.now(), expired=False, deleted=False),
Expand Down
42 changes: 42 additions & 0 deletions NEMO/apps/contracts/migrations/0003_documents_display_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 3.2.25 on 2024-04-08 11:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("contracts", "0002_increase_document_path_length"),
]

operations = [
migrations.AlterModelOptions(
name="contractoragreementdocuments",
options={
"ordering": ["display_order", "-uploaded_at"],
"verbose_name_plural": "Contractor agreement documents",
},
),
migrations.AlterModelOptions(
name="procurementdocuments",
options={"ordering": ["display_order", "-uploaded_at"], "verbose_name_plural": "Procurement documents"},
),
migrations.AddField(
model_name="contractoragreementdocuments",
name="display_order",
field=models.IntegerField(
default=1,
help_text="The order in which choices are displayed on the landing page, from left to right, top to bottom. Lower values are displayed first.",
),
preserve_default=False,
),
migrations.AddField(
model_name="procurementdocuments",
name="display_order",
field=models.IntegerField(
default=1,
help_text="The order in which choices are displayed on the landing page, from left to right, top to bottom. Lower values are displayed first.",
),
preserve_default=False,
),
]
65 changes: 65 additions & 0 deletions NEMO/apps/kiosk/templates/kiosk/kiosk.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,42 @@ <h1 style="color:lightgrey" id="badge_number"></h1>
status_element.html("<h1>Loading tool information...</h1>").show();
ajax_get(url, undefined, load_complete);
}
function tool_report_problem(url)
{
default_content_element.hide();
error_element.hide();
error_interlock_element.hide();
let data = $('#tool_control').serialize();
status_element.html("<h1>Loading report a problem...</h1>").show();
ajax_post(url, data, load_complete);
}
function report_problem()
{
default_content_element.hide();
error_element.hide();
error_interlock_element.hide();
let data = $('#tool_report_problem').serialize();
status_element.html("<h1>Reporting problem...</h1>").show();
ajax_post('{% url 'report_problem_from_kiosk' %}', data, load_complete);
}
function tool_post_comment(url)
{
default_content_element.hide();
error_element.hide();
error_interlock_element.hide();
let data = $('#tool_control').serialize();
status_element.html("<h1>Loading post a comment...</h1>").show();
ajax_post(url, data, load_complete);
}
function post_comment()
{
default_content_element.hide();
error_element.hide();
error_interlock_element.hide();
let data = $('#tool_post_comment').serialize();
status_element.html("<h1>Posting comment...</h1>").show();
ajax_post('{% url 'post_comment_from_kiosk' %}', data, load_complete);
}
function view_category(url)
{
default_content_element.hide();
Expand Down Expand Up @@ -262,6 +298,35 @@ <h1 style="color:lightgrey" id="badge_number"></h1>
{
ajax_post(url, data, function(response, status, xml_http_request) {interlock_success_callback(response, status, xml_http_request)}, function(response, status, xml_http_request) { return interlock_failure_callback(response, status, xml_http_request, url, data) })
}

function enter_wait_list(tool_id, customer_id)
{
default_content_element.hide();
error_element.hide();
error_interlock_element.hide();
let url = "{% url 'enter_wait_list_from_kiosk' %}";
status_element.html("<h1>Entering wait list...</h1>").show();
let data = {
tool_id: tool_id,
customer_id: customer_id
};
ajax_post(url, data, load_complete);
}

function exit_wait_list(tool_id, customer_id)
{
default_content_element.hide();
error_element.hide();
error_interlock_element.hide();
let url = "{% url 'exit_wait_list_from_kiosk' %}";
status_element.html("<h1>Exiting wait list...</h1>").show();
let data = {
tool_id: tool_id,
customer_id: customer_id
};
ajax_post(url, data, load_complete);
}

function enable_tool(tool_id)
{
default_content_element.hide();
Expand Down
Loading

0 comments on commit b36a6e2

Please sign in to comment.