Skip to content

Commit

Permalink
Use slugify to add processing service
Browse files Browse the repository at this point in the history
  • Loading branch information
vanessavmac committed Jan 15, 2025
1 parent dc2e4be commit 6a98913
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
10 changes: 10 additions & 0 deletions ami/ml/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

from django.utils.text import slugify
from rest_framework import status
from rest_framework.decorators import action
from rest_framework.request import Request
from rest_framework.response import Response
Expand Down Expand Up @@ -72,6 +74,14 @@ class ProcessingServiceViewSet(DefaultViewSet):
filterset_fields = ["projects"]
ordering_fields = ["id", "created_at", "updated_at"]

def create(self, request, *args, **kwargs):
data = request.data.copy()
data["slug"] = slugify(data["name"])
serializer = self.get_serializer(data=data)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
return Response(serializer.data, status=status.HTTP_201_CREATED)

@action(detail=True, methods=["get"])
def status(self, request: Request, pk=None) -> Response:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { useFormError } from 'utils/useFormError'
import { DetailsFormProps, FormValues } from './types'

type ProcessingServiceFormValues = FormValues & {
slug: string
endpoint_url: string
}

Expand All @@ -28,13 +27,6 @@ const config: FormConfig = {
required: true,
},
},
slug: {
label: translate(STRING.FIELD_LABEL_SLUG),
description: 'A unique identifier for internal reference.',
rules: {
required: true,
},
},
endpoint_url: {
label: 'Endpoint URL',
description: 'Processing service endpoint.',
Expand All @@ -61,9 +53,8 @@ export const ProcessingServiceDetailsForm = ({
setError: setFieldError,
} = useForm<ProcessingServiceFormValues>({
defaultValues: {
name: processingService?.name ?? '',
slug: processingService?.slug ?? '',
endpoint_url: processingService?.endpointUrl ?? '',
name: processingService?.name,
endpoint_url: processingService?.endpointUrl,
description: processingService?.description ?? '',
},
mode: 'onChange',
Expand All @@ -78,7 +69,6 @@ export const ProcessingServiceDetailsForm = ({
name: values.name,
description: values.description,
customFields: {
slug: values.slug,
endpoint_url: values.endpoint_url,
},
})
Expand All @@ -100,19 +90,13 @@ export const ProcessingServiceDetailsForm = ({
control={control}
/>
<FormField
name="slug"
name="endpoint_url"
type="text"
config={config}
control={control}
/>
</FormRow>
<FormRow>
<FormField
name="endpoint_url"
type="text"
config={config}
control={control}
/>
<FormField
name="description"
type="text"
Expand Down

0 comments on commit 6a98913

Please sign in to comment.