import os
from datetime import datetime
from django.http import HttpResponseRedirect
from django.utils.http import urlquote
from django.conf import settings


def project_required(func):
    """
    Decorator function for other actions that
    require a project to be open in the session.
    """
    def wrapper(request, *args, **kwargs):
        path = urlquote(request.get_full_path())
        if not request.session.get("project"):
            return HttpResponseRedirect("/projects/list/?next=%s" % path)
        return func(request, *args, **kwargs)
    return wrapper


def saves_files(func):
    """
    Decorator function for other actions that
    require a project to be open in the session.
    """
    def wrapper(request, *args, **kwargs):
        temp = request.path.startswith("/ocr/")
        project = request.session.get("project")
        output_path = None
        if project is None:
            temp = True
        if temp:
            output_path = os.path.join(
                settings.MEDIA_ROOT,
                settings.TEMP_PATH,
                request.user.username,
                datetime.now().strftime("%Y%m%d%H%M%S")
            )
        else:            
            output_path = os.path.join(
                settings.MEDIA_ROOT,
                settings.USER_FILES_PATH, 
                project.slug
            )
        request.__class__.output_path = output_path
        return func(request, *args, **kwargs)
    return wrapper




import os
from datetime import datetime
from django.http import HttpResponseRedirect
from django.utils.http import urlquote
from django.conf import settings


def project_required(func):
    """
    Decorator function for other actions that
    require a project to be open in the session.
    """
    def wrapper(request, *args, **kwargs):
        path = urlquote(request.get_full_path())
        if not request.session.get("project"):
            return HttpResponseRedirect("/projects/list/?next=%s" % path)
        return func(request, *args, **kwargs)
    return wrapper


def saves_files(func):
    """
    Decorator function for other actions that
    require a project to be open in the session.
    """
    def wrapper(request, *args, **kwargs):
        temp = request.path.startswith(("/ocr/", "/plugins/"))
        project = request.session.get("project")
        output_path = None
        if project is None:
            temp = True
        if temp:
            output_path = os.path.join(
                settings.MEDIA_ROOT,
                settings.TEMP_PATH,
                request.user.username,
                datetime.now().strftime("%Y%m%d%H%M%S")
            )
        else:            
            output_path = os.path.join(
                settings.MEDIA_ROOT,
                settings.USER_FILES_PATH, 
                project.slug
            )
        request.__class__.output_path = output_path
        return func(request, *args, **kwargs)
    return wrapper




Add plugins to the domains which handle temp files
Add plugins to the domains which handle temp files

  import os
  from datetime import datetime
  from django.http import HttpResponseRedirect
  from django.utils.http import urlquote
  from django.conf import settings
  
  
  def project_required(func):
      """
      Decorator function for other actions that
      require a project to be open in the session.
      """
      def wrapper(request, *args, **kwargs):
          path = urlquote(request.get_full_path())
          if not request.session.get("project"):
              return HttpResponseRedirect("/projects/list/?next=%s" % path)
          return func(request, *args, **kwargs)
      return wrapper
  
  
  def saves_files(func):
      """
      Decorator function for other actions that
      require a project to be open in the session.
      """
      def wrapper(request, *args, **kwargs):
-         temp = request.path.startswith("/ocr/")
+         temp = request.path.startswith(("/ocr/", "/plugins/"))
          project = request.session.get("project")
          output_path = None
          if project is None:
              temp = True
          if temp:
              output_path = os.path.join(
                  settings.MEDIA_ROOT,
                  settings.TEMP_PATH,
                  request.user.username,
                  datetime.now().strftime("%Y%m%d%H%M%S")
              )
          else:            
              output_path = os.path.join(
                  settings.MEDIA_ROOT,
                  settings.USER_FILES_PATH, 
                  project.slug
              )
          request.__class__.output_path = output_path
          return func(request, *args, **kwargs)
      return wrapper
  
  
  
  
Add plugins to the domains which handle temp files
## Code Before:
import os
from datetime import datetime
from django.http import HttpResponseRedirect
from django.utils.http import urlquote
from django.conf import settings


def project_required(func):
    """
    Decorator function for other actions that
    require a project to be open in the session.
    """
    def wrapper(request, *args, **kwargs):
        path = urlquote(request.get_full_path())
        if not request.session.get("project"):
            return HttpResponseRedirect("/projects/list/?next=%s" % path)
        return func(request, *args, **kwargs)
    return wrapper


def saves_files(func):
    """
    Decorator function for other actions that
    require a project to be open in the session.
    """
    def wrapper(request, *args, **kwargs):
        temp = request.path.startswith("/ocr/")
        project = request.session.get("project")
        output_path = None
        if project is None:
            temp = True
        if temp:
            output_path = os.path.join(
                settings.MEDIA_ROOT,
                settings.TEMP_PATH,
                request.user.username,
                datetime.now().strftime("%Y%m%d%H%M%S")
            )
        else:            
            output_path = os.path.join(
                settings.MEDIA_ROOT,
                settings.USER_FILES_PATH, 
                project.slug
            )
        request.__class__.output_path = output_path
        return func(request, *args, **kwargs)
    return wrapper




## Instruction:
Add plugins to the domains which handle temp files
## Code After:
import os
from datetime import datetime
from django.http import HttpResponseRedirect
from django.utils.http import urlquote
from django.conf import settings


def project_required(func):
    """
    Decorator function for other actions that
    require a project to be open in the session.
    """
    def wrapper(request, *args, **kwargs):
        path = urlquote(request.get_full_path())
        if not request.session.get("project"):
            return HttpResponseRedirect("/projects/list/?next=%s" % path)
        return func(request, *args, **kwargs)
    return wrapper


def saves_files(func):
    """
    Decorator function for other actions that
    require a project to be open in the session.
    """
    def wrapper(request, *args, **kwargs):
        temp = request.path.startswith(("/ocr/", "/plugins/"))
        project = request.session.get("project")
        output_path = None
        if project is None:
            temp = True
        if temp:
            output_path = os.path.join(
                settings.MEDIA_ROOT,
                settings.TEMP_PATH,
                request.user.username,
                datetime.now().strftime("%Y%m%d%H%M%S")
            )
        else:            
            output_path = os.path.join(
                settings.MEDIA_ROOT,
                settings.USER_FILES_PATH, 
                project.slug
            )
        request.__class__.output_path = output_path
        return func(request, *args, **kwargs)
    return wrapper



