Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions river_admin/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.conf.urls import url
from django.urls import include, re_path

Choose a reason for hiding this comment

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

medium

The include function is imported but not used in this file. It's good practice to remove unused imports to keep the code clean.

Suggested change
from django.urls import include, re_path
from django.urls import re_path

from rest_framework.authtoken.views import obtain_auth_token

from river_admin.views import urls

urlpatterns = [
url(r'^api-token-auth/', obtain_auth_token),
re_path(r'^api-token-auth/', obtain_auth_token),
] + urls
4 changes: 2 additions & 2 deletions river_admin/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path
from django.db import IntegrityError
from django.db.models import ProtectedError
from rest_framework import serializers
Expand All @@ -17,7 +17,7 @@ def decorator(view):
authentications = options.get("authentication_classes", [TokenAuthentication])
renderers = options.get("renderer_classes", [JSONRenderer])
new_view = api_view([method])(authentication_classes(authentications)(renderer_classes(renderers)(view)))
urls.append(url(path, new_view))
urls.append(re_path(path, new_view))
return new_view

return decorator
Expand Down
14 changes: 7 additions & 7 deletions river_admin/views/workflow_object_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
from river_admin.views.serializers import StateDto, WorkflowObjectStateDto, TransitionDto, TransitionApprovalDto


@get(r'^workflow-object/identify/(?P<workflow_pk>\w+)/(?P<object_id>\w+)/$')
@get(r'^workflow-object/identify/(?P<workflow_pk>[-\w]+)/(?P<object_id>[-\w]+)/$')
def get_identifier(request, workflow_pk, object_id):
workflow = get_object_or_404(Workflow.objects.all(), pk=workflow_pk)
model_class = workflow.content_type.model_class()
workflow_object = get_object_or_404(model_class.objects.all(), pk=object_id)
return Response(str(workflow_object), status=status.HTTP_200_OK)


@get(r'^workflow-object/current-state/(?P<workflow_pk>\w+)/(?P<object_id>\w+)/$')
@get(r'^workflow-object/current-state/(?P<workflow_pk>[-\w]+)/(?P<object_id>[-\w]+)/$')
def get_current_state(request, workflow_pk, object_id):
workflow = get_object_or_404(Workflow.objects.all(), pk=workflow_pk)
model_class = workflow.content_type.model_class()
Expand All @@ -26,7 +26,7 @@ def get_current_state(request, workflow_pk, object_id):
return Response(StateDto(current_state).data, status=status.HTTP_200_OK)


@get(r'^workflow-object/current-iteration/(?P<workflow_pk>\w+)/(?P<object_id>\w+)/$')
@get(r'^workflow-object/current-iteration/(?P<workflow_pk>[-\w]+)/(?P<object_id>[-\w]+)/$')
def get_current_iteration(request, workflow_pk, object_id):
workflow = get_object_or_404(Workflow.objects.all(), pk=workflow_pk)
model_class = workflow.content_type.model_class()
Expand All @@ -44,7 +44,7 @@ def get_current_iteration(request, workflow_pk, object_id):
return Response(last_iteration, status=status.HTTP_200_OK)


@delete(r'^workflow-object/delete/(?P<workflow_pk>\w+)/(?P<object_id>\w+)/$')
@delete(r'^workflow-object/delete/(?P<workflow_pk>[-\w]+)/(?P<object_id>[-\w]+)/$')

Choose a reason for hiding this comment

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

high

The view function decorated here, get_identifier (defined on the next line), performs a delete operation. This name is misleading. Furthermore, it redefines another function with the same name from line 12. To avoid confusion and improve code clarity, the function on line 48 should be renamed to reflect its purpose, for example, delete_workflow_object.

def get_identifier(request, workflow_pk, object_id):
workflow = get_object_or_404(Workflow.objects.all(), pk=workflow_pk)
model_class = workflow.content_type.model_class()
Expand All @@ -53,7 +53,7 @@ def get_identifier(request, workflow_pk, object_id):
return Response(status=status.HTTP_200_OK)


@get(r'^workflow-object/state/list/(?P<workflow_id>\w+)/(?P<object_id>\w+)/$')
@get(r'^workflow-object/state/list/(?P<workflow_id>[-\w]+)/(?P<object_id>[-\w]+)/$')
def list_states(request, workflow_id, object_id):
workflow = get_object_or_404(Workflow.objects.all(), pk=workflow_id)
model_class = workflow.content_type.model_class()
Expand All @@ -78,7 +78,7 @@ def list_states(request, workflow_id, object_id):
return Response(WorkflowObjectStateDto(states, many=True).data, status=HTTP_200_OK)


@get(r'^workflow-object/transition/list/(?P<workflow_id>\w+)/(?P<object_id>\w+)/$')
@get(r'^workflow-object/transition/list/(?P<workflow_id>[-\w]+)/(?P<object_id>[-\w]+)/$')
def list_transitions(request, workflow_id, object_id):
workflow = get_object_or_404(Workflow.objects.all(), pk=workflow_id)
model_class = workflow.content_type.model_class()
Expand All @@ -87,7 +87,7 @@ def list_transitions(request, workflow_id, object_id):
return Response(TransitionDto(workflow.transitions.filter(object_id=workflow_object.pk), many=True).data, status=HTTP_200_OK)


@get(r'^workflow-object/transition-approval/list/(?P<workflow_id>\w+)/(?P<object_id>\w+)/$')
@get(r'^workflow-object/transition-approval/list/(?P<workflow_id>[-\w]+)/(?P<object_id>[-\w]+)/$')
def list_transition_approvals(request, workflow_id, object_id):
workflow = get_object_or_404(Workflow.objects.all(), pk=workflow_id)
model_class = workflow.content_type.model_class()
Expand Down