
from nagare.services import plugin


class PRGService(plugin.Plugin):
    LOAD_PRIORITY = 120

    @staticmethod
    def handle_request(chain, request, response, session_id, previous_state_id, **params):
        if (request.method == 'POST') and not request.is_xhr:
            response = request.create_redirect_response(
                response=response,
                _s=session_id,
                _c='%05d' % previous_state_id
            )
            response.use_same_state = True
        else:
            response = chain.next(
                request=request,
                response=response,
                session_id=session_id,
                previous_state_id=previous_state_id,
                **params
            )

        return response


from nagare.services import plugin


class PRGService(plugin.Plugin):
    LOAD_PRIORITY = 120

    @staticmethod
    def handle_request(chain, request, response, session_id, state_id, **params):
        if (request.method == 'POST') and not request.is_xhr:
            response = request.create_redirect_response(
                response=response,
                _s=session_id,
                _c='%05d' % state_id,
            )
        else:
            response = chain.next(
                request=request,
                response=response,
                session_id=session_id,
                state_id=state_id,
                **params
            )

        return response

Store in the current state, not the previous one
Store in the current state, not the previous one

  
  from nagare.services import plugin
  
  
  class PRGService(plugin.Plugin):
      LOAD_PRIORITY = 120
  
      @staticmethod
-     def handle_request(chain, request, response, session_id, previous_state_id, **params):
+     def handle_request(chain, request, response, session_id, state_id, **params):
          if (request.method == 'POST') and not request.is_xhr:
              response = request.create_redirect_response(
                  response=response,
                  _s=session_id,
-                 _c='%05d' % previous_state_id
+                 _c='%05d' % state_id,
              )
-             response.use_same_state = True
          else:
              response = chain.next(
                  request=request,
                  response=response,
                  session_id=session_id,
-                 previous_state_id=previous_state_id,
+                 state_id=state_id,
                  **params
              )
  
          return response
  
Store in the current state, not the previous one
## Code Before:

from nagare.services import plugin


class PRGService(plugin.Plugin):
    LOAD_PRIORITY = 120

    @staticmethod
    def handle_request(chain, request, response, session_id, previous_state_id, **params):
        if (request.method == 'POST') and not request.is_xhr:
            response = request.create_redirect_response(
                response=response,
                _s=session_id,
                _c='%05d' % previous_state_id
            )
            response.use_same_state = True
        else:
            response = chain.next(
                request=request,
                response=response,
                session_id=session_id,
                previous_state_id=previous_state_id,
                **params
            )

        return response

## Instruction:
Store in the current state, not the previous one
## Code After:

from nagare.services import plugin


class PRGService(plugin.Plugin):
    LOAD_PRIORITY = 120

    @staticmethod
    def handle_request(chain, request, response, session_id, state_id, **params):
        if (request.method == 'POST') and not request.is_xhr:
            response = request.create_redirect_response(
                response=response,
                _s=session_id,
                _c='%05d' % state_id,
            )
        else:
            response = chain.next(
                request=request,
                response=response,
                session_id=session_id,
                state_id=state_id,
                **params
            )

        return response
