javrasya / django-river

Django workflow library that supports on the fly changes ⛵
BSD 3-Clause "New" or "Revised" License
742 stars 105 forks source link

'ClassWorkflowObject' object has no attribute 'approve' #86

Closed rupin closed 5 years ago

rupin commented 5 years ago

I am trying to approve a Flow. The code works without error for

flow_objects_awaiting_approval = Flow.river.stage.get_on_approval_objects(as_user=logged_in_user)

but when the same line is changed to

approveObjects = Flow.river.stage.approve(as_user=logged_in_user)

It throws the error below

Environment:

Request Method: GET
Request URL: http://localhost:8000/getFormFields/

Django Version: 2.2.4
Python Version: 3.6.3
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'whitenoise.runserver_nostatic',
 'django.contrib.staticfiles',
 'import_export',
 'workflowengine',
 'river',
 'rest_framework',
 'rest_framework.authtoken',
 'rest_auth']
Installed Middleware:
('whitenoise.middleware.WhiteNoiseMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback:

File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.6/dist-packages/django/views/decorators/csrf.py" in wrapped_view
  54.         return view_func(*args, **kwargs)

File "/usr/local/lib/python3.6/dist-packages/django/views/generic/base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)

File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py" in dispatch
  497.             response = self.handle_exception(exc)

File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py" in handle_exception
  457.             self.raise_uncaught_exception(exc)

File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py" in raise_uncaught_exception
  468.         raise exc

File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py" in dispatch
  485.             self.initial(request, *args, **kwargs)

File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py" in initial
  403.         self.check_permissions(request)

File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py" in check_permissions
  332.             if not permission.has_permission(request, self):

File "/usr/local/lib/python3.6/dist-packages/rest_framework/permissions.py" in has_permission
  229.         queryset = self._queryset(view)

File "/usr/local/lib/python3.6/dist-packages/rest_framework/permissions.py" in _queryset
  212.             queryset = view.get_queryset()

File "/media/rupin/Backup/WorkflowEngine/workflowengine/apiviews/FormFieldAPIView.py" in get_queryset
  21.       flow_objects_awaiting_approval = Flow.river.stage.approve(as_user=logged_in_user)

Exception Type: AttributeError at /getFormFields/
Exception Value: 'ClassWorkflowObject' object has no attribute 'approve'

What am I doing wrong?

javrasya commented 5 years ago

approve is not a class API it is an instance API. You can access it per model object. Supposed to be something like this;

flow_object.river.stage.approve(as_user=logged_in_user)

Otherwise django-river can't know what object to approve.

rupin commented 5 years ago

Thanks!