Giter Site home page Giter Site logo

Comments (3)

benoitbryon avatar benoitbryon commented on June 9, 2024

This feature may be implemented as follow:

  • "global backend" is configured in middlewares, as DOWNLOADVIEW_MIDDLEWARES items. This is not a single backend, but a set of backends. At least they are registered in a single location: settings.
  • the recommended practice (in documentation) is to use the global middlewares.
  • where you explicitely want a decorator and you do not want to care about the backend, you can use some generic decorator, which accepts most common backend arguments: source URL or path and destination URL.
  • where you explicitely want a decorator and you care about the backend, you can use a specific decorator, or a specific list of "middlewares" that can capture the response.

=> DOWNLOADVIEW_MIDDLEWARES makes most use cases easy.
=> Custom decorators allow fine-tuning for specific needs.

from django-downloadview.

benoitbryon avatar benoitbryon commented on June 9, 2024

Note about the previous comment...
"Download decorators" were introduced mostly to support multiple backend configurations. As of version 1.2, you cannot setup multiple (source, destination) rules for one middleware. So you actually have to setup per-view configuration via decorators.
With DOWNLOAD_MIDDLEWARES setting (a list of middlewares with initialization arguments), you can have multiple rules for a given backend. So decorators are no longer the easier way to go.

from django-downloadview.

benoitbryon avatar benoitbryon commented on June 9, 2024

Created #50 about multiple configuration support.
This ticket may not be resolved in version 1.3.
After #50 is resolved, a solution could be to create some "generic" middleware that accept a backend as argument (or use global "DOWNLOADVIEW_BACKEND" setting) and use sane defaults for backend-specific options.
Then we could have only one middleware class (or backend) and several "rewrite rules" for it.
Something like TRANSFER_MAPPINGS in https://github.com/smartfile/django-transfer/

MIDDLEWARE_CLASSES = [
    'django_downloadview.DownloadDispatcherMiddleware',
]
DOWNLOADVIEW_BACKEND = 'django_downloadview.nginx.XAccelRedirectMiddleware'
DOWNLOADVIEW_RULES = [
    (MEDIA_URL, '/optimized-download/'),  # *args
    {'source_url': MEDIA_URL, 'destination_url': '/optimized-download', 'limit_rate': 32},  # kwargs, with specific options
]

from django-downloadview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.