Skip to content

Commit

Permalink
- added staff assistance request to detailed admin
Browse files Browse the repository at this point in the history
- implemented API endpoints and viewset for staff assistance requests
- updated splash pad data with a staff assistance request
  • Loading branch information
rptmat57 committed Feb 20, 2025
1 parent b8ef328 commit 75a71ec
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 19 deletions.
31 changes: 24 additions & 7 deletions NEMO/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
ScheduledOutageCategory,
StaffAbsence,
StaffAbsenceType,
StaffAssistanceRequest,
StaffAvailability,
StaffAvailabilityCategory,
StaffCharge,
Expand Down Expand Up @@ -1576,15 +1577,8 @@ def get_schedule_display_with_times(self, tpa: TemporaryPhysicalAccess) -> str:
return tpa.physical_access_level.get_schedule_display_with_times()


class TemporaryPhysicalAccessRequestFormAdmin(forms.ModelForm):
class Meta:
model = TemporaryPhysicalAccessRequest
fields = "__all__"


@register(TemporaryPhysicalAccessRequest)
class TemporaryPhysicalAccessRequestAdmin(admin.ModelAdmin):
form = TemporaryPhysicalAccessRequestFormAdmin
list_display = (
"creator",
"creation_time",
Expand Down Expand Up @@ -1945,6 +1939,29 @@ def is_tool_visible(self, obj: Configuration):
return obj.tool.visible


@register(StaffAssistanceRequest)
class StaffAssistanceRequestAdmin(admin.ModelAdmin):
list_display = (
"user",
"creation_time",
"other_users_display",
"resolved",
"deleted",
)
list_filter = (
"resolved",
"deleted",
("user", admin.RelatedOnlyFieldListFilter),
)
date_hierarchy = "creation_time"
readonly_fields = ["creation_time"]
autocomplete_fields = ["user"]

@admin.display(description="Staff members")
def other_users_display(self, obj: StaffAssistanceRequest):
return mark_safe("<br>".join([u.username for u in obj.creator_and_reply_users() if u != obj.user]))


@register(EmailLog)
class EmailLogAdmin(admin.ModelAdmin):
list_display = ["id", "category", "sender", "to", "subject", "when", "ok"]
Expand Down
3 changes: 3 additions & 0 deletions NEMO/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4388,6 +4388,9 @@ class StaffAssistanceRequest(BaseModel):
default=False, help_text="Indicates the request has been deleted and won't be shown anymore."
)

class Meta:
ordering = ["-creation_time"]

@property
def creator(self) -> User:
return self.user
Expand Down
11 changes: 11 additions & 0 deletions NEMO/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
Reservation,
Resource,
ScheduledOutage,
StaffAssistanceRequest,
StaffCharge,
Task,
TaskHistory,
Expand Down Expand Up @@ -528,6 +529,16 @@ class Meta:
}


class StaffAssistanceRequestsSerializer(FlexFieldsSerializerMixin, ModelSerializer):
class Meta:
model = StaffAssistanceRequest
fields = "__all__"
expandable_fields = {
"tool": "NEMO.serializers.ToolSerializer",
"user": "NEMO.serializers.UserSerializer",
}


class PermissionSerializer(FlexFieldsSerializerMixin, ModelSerializer):
users = PrimaryKeyRelatedField(
source="user_set", many=True, queryset=User.objects.all(), allow_null=True, required=False
Expand Down
16 changes: 16 additions & 0 deletions NEMO/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
Reservation,
Resource,
ScheduledOutage,
StaffAssistanceRequest,
StaffCharge,
Task,
TemporaryPhysicalAccessRequest,
Expand Down Expand Up @@ -85,6 +86,7 @@
ReservationSerializer,
ResourceSerializer,
ScheduledOutageSerializer,
StaffAssistanceRequestsSerializer,
StaffChargeSerializer,
TaskSerializer,
TemporaryPhysicalAccessRequestSerializer,
Expand Down Expand Up @@ -771,6 +773,20 @@ class ToolCredentialsViewSet(ModelViewSet):
}


class StaffAssistanceRequestsViewSet(ModelViewSet):
filename = "staff_assistance_requests"
queryset = StaffAssistanceRequest.objects.all()
serializer_class = StaffAssistanceRequestsSerializer
filterset_fields = {
"id": key_filters,
"user": key_filters,
"creation_time": datetime_filters,
"description": string_filters,
"resolved": boolean_filters,
"deleted": boolean_filters,
}


class GroupViewSet(ModelViewSet):
filename = "groups"
queryset = Group.objects.all()
Expand Down
15 changes: 7 additions & 8 deletions NEMO/views/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,13 @@ def create_staff_assistance_request_notification(staff_assistance_request: Staff
users: List[User] = User.objects.filter(is_active=True, is_staff=True).exclude(id=staff_assistance_request.user_id)
expiration = datetime.max.replace(tzinfo=timezone.get_default_timezone()) - timedelta(days=1)
for u in users:
if u.get_preferences().display_new_buddy_request_notification:
Notification.objects.update_or_create(
user=u,
notification_type=Notification.Types.STAFF_ASSISTANCE_REQUEST,
content_type=ContentType.objects.get_for_model(staff_assistance_request),
object_id=staff_assistance_request.id,
defaults={"expiration": expiration},
)
Notification.objects.update_or_create(
user=u,
notification_type=Notification.Types.STAFF_ASSISTANCE_REQUEST,
content_type=ContentType.objects.get_for_model(staff_assistance_request),
object_id=staff_assistance_request.id,
defaults={"expiration": expiration},
)


def create_request_message_notification(reply: RequestMessage, notification_type: str, expiration: datetime):
Expand Down
68 changes: 64 additions & 4 deletions resources/fixtures/splash_pad.json
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,9 @@
"fields": {
"name": "Cleanroom door",
"welcome_message": "<h2><center>Welcome to the cleanroom!</center></h2>",
"areas": [1],
"areas": [
1
],
"interlock": 1
}
},
Expand Down Expand Up @@ -1202,6 +1204,13 @@
"value": "enabled"
}
},
{
"model": "NEMO.customization",
"pk": "staff_assistance_requests_enabled",
"fields": {
"value": "enabled"
}
},
{
"model": "NEMO.news",
"pk": 1,
Expand Down Expand Up @@ -8585,7 +8594,9 @@
"value": 203,
"default_value": 0,
"counter_direction": 1,
"tool": ["Unaxis ICP Etcher"],
"tool": [
"Unaxis ICP Etcher"
],
"tool_usage_question": "gold_used",
"last_reset_value": null,
"last_reset": null,
Expand All @@ -8605,7 +8616,9 @@
"value": 50,
"default_value": 100,
"counter_direction": -1,
"tool": ["790 RIE Right"],
"tool": [
"790 RIE Right"
],
"tool_usage_question": "etch_time",
"last_reset_value": null,
"last_reset": null,
Expand Down Expand Up @@ -9117,7 +9130,11 @@
"account": [
"Cleanroom Staff"
],
"project_types": [["CHIPS"]],
"project_types": [
[
"CHIPS"
]
],
"discipline": null,
"active": true,
"allow_consumable_withdrawals": true,
Expand Down Expand Up @@ -9767,6 +9784,38 @@
"object_id": 4
}
},
{
"model": "NEMO.notification",
"pk": 10,
"fields": {
"user": [
"captain"
],
"expiration": "2099-02-24T04:59:59.999Z",
"notification_type": "staffassistancerequest",
"content_type": [
"NEMO",
"staffassistancerequest"
],
"object_id": 1
}
},
{
"model": "NEMO.notification",
"pk": 11,
"fields": {
"user": [
"professor"
],
"expiration": "2099-02-24T04:59:59.999Z",
"notification_type": "staffassistancerequest",
"content_type": [
"NEMO",
"staffassistancerequest"
],
"object_id": 1
}
},
{
"model": "NEMO.scheduledoutage",
"pk": 1,
Expand Down Expand Up @@ -9939,5 +9988,16 @@
"User training"
]
}
},
{
"model": "NEMO.staffassistancerequest",
"pk": 1,
"fields": {
"creation_time": "2025-02-20T03:29:14.451Z",
"description": "I need help in the lab with a tool",
"user": 3,
"resolved": false,
"deleted": false
}
}
]

0 comments on commit 75a71ec

Please sign in to comment.