from django.conf import settings
from django.forms import widgets

#JS_URL is the url to the filepicker.io javascript library
JS_VERSION = 1
JS_URL = "//api.filepicker.io/v%d/filepicker.js" % (JS_VERSION)

if hasattr(settings, 'FILEPICKER_INPUT_TYPE'):
    INPUT_TYPE = settings.FILEPICKER_INPUT_TYPE
else:
    INPUT_TYPE = 'filepicker-dragdrop'


class FPFileWidget(widgets.Input):
    input_type = INPUT_TYPE
    needs_multipart_form = False

    def value_from_datadict_old(self, data, files, name):
        #If we are using the middleware, then the data will already be
        #in FILES, if not it will be in POST
        if name not in data:
            return super(FPFileWidget, self).value_from_datadict(
                    data, files, name)

        return data

    class Media:
        js = (JS_URL,)

from django.conf import settings
from django.forms import widgets

#JS_URL is the url to the filepicker.io javascript library
JS_VERSION = getattr(settings, "FILEPICKER_JS_VERSION", 0)
JS_URL = "//api.filepicker.io/v%d/filepicker.js" % (JS_VERSION)

INPUT_TYPE = getattr(settings, "FILEPICKER_INPUT_TYPE", "filepicker-dragdrop")

class FPFileWidget(widgets.Input):
    input_type = INPUT_TYPE
    needs_multipart_form = False

    def value_from_datadict_old(self, data, files, name):
        #If we are using the middleware, then the data will already be
        #in FILES, if not it will be in POST
        if name not in data:
            return super(FPFileWidget, self).value_from_datadict(
                    data, files, name)

        return data

    class Media:
        js = (JS_URL,)

Allow Filepicker JS version to be configured
Allow Filepicker JS version to be configured

Filepicker JS version can now be configured
using FILEPICKER_JS_VERSION. Version 0 is
default.

Changed the logic of INPUT_TYPE to use
getattr instead of hasattr and an if
statement.
  from django.conf import settings
  from django.forms import widgets
  
  #JS_URL is the url to the filepicker.io javascript library
- JS_VERSION = 1
+ JS_VERSION = getattr(settings, "FILEPICKER_JS_VERSION", 0)
  JS_URL = "//api.filepicker.io/v%d/filepicker.js" % (JS_VERSION)
  
+ INPUT_TYPE = getattr(settings, "FILEPICKER_INPUT_TYPE", "filepicker-dragdrop")
- if hasattr(settings, 'FILEPICKER_INPUT_TYPE'):
-     INPUT_TYPE = settings.FILEPICKER_INPUT_TYPE
- else:
-     INPUT_TYPE = 'filepicker-dragdrop'
- 
  
  class FPFileWidget(widgets.Input):
      input_type = INPUT_TYPE
      needs_multipart_form = False
  
      def value_from_datadict_old(self, data, files, name):
          #If we are using the middleware, then the data will already be
          #in FILES, if not it will be in POST
          if name not in data:
              return super(FPFileWidget, self).value_from_datadict(
                      data, files, name)
  
          return data
  
      class Media:
          js = (JS_URL,)
  
Allow Filepicker JS version to be configured
## Code Before:
from django.conf import settings
from django.forms import widgets

#JS_URL is the url to the filepicker.io javascript library
JS_VERSION = 1
JS_URL = "//api.filepicker.io/v%d/filepicker.js" % (JS_VERSION)

if hasattr(settings, 'FILEPICKER_INPUT_TYPE'):
    INPUT_TYPE = settings.FILEPICKER_INPUT_TYPE
else:
    INPUT_TYPE = 'filepicker-dragdrop'


class FPFileWidget(widgets.Input):
    input_type = INPUT_TYPE
    needs_multipart_form = False

    def value_from_datadict_old(self, data, files, name):
        #If we are using the middleware, then the data will already be
        #in FILES, if not it will be in POST
        if name not in data:
            return super(FPFileWidget, self).value_from_datadict(
                    data, files, name)

        return data

    class Media:
        js = (JS_URL,)

## Instruction:
Allow Filepicker JS version to be configured
## Code After:
from django.conf import settings
from django.forms import widgets

#JS_URL is the url to the filepicker.io javascript library
JS_VERSION = getattr(settings, "FILEPICKER_JS_VERSION", 0)
JS_URL = "//api.filepicker.io/v%d/filepicker.js" % (JS_VERSION)

INPUT_TYPE = getattr(settings, "FILEPICKER_INPUT_TYPE", "filepicker-dragdrop")

class FPFileWidget(widgets.Input):
    input_type = INPUT_TYPE
    needs_multipart_form = False

    def value_from_datadict_old(self, data, files, name):
        #If we are using the middleware, then the data will already be
        #in FILES, if not it will be in POST
        if name not in data:
            return super(FPFileWidget, self).value_from_datadict(
                    data, files, name)

        return data

    class Media:
        js = (JS_URL,)
