Permalink
Browse files

Merge pull request #13 from asilachev/master

Defining additional parameters to widget
  • Loading branch information...
2 parents d7a3710 + f8bd653 commit 420c3c993e93b4974e0e803e2ecb8233513cd80c @brettcvz brettcvz committed Jan 21, 2013
Showing with 14 additions and 1 deletion.
  1. +10 −1 django_filepicker/forms.py
  2. +4 −0 django_filepicker/models.py
@@ -14,13 +14,14 @@ class FPFieldMixin():
widget = FPFileWidget
default_mimetypes = "*/*"
- def initialize(self, apikey=None, mimetypes=None, services=None):
+ def initialize(self, apikey=None, mimetypes=None, services=None, additional_params=None):
"""
Initializes the Filepicker field.
Valid arguments:
* apikey. This string is required if it isn't set as settings.FILEPICKER_API_KEY
* mimetypes. Optional, the allowed mimetypes for files. Defaults to "*/*" (all files)
* services. Optional, the allowed services to pull from.
+ * additional_params. Optional, additional parameters to be applied.
"""
self.apikey = apikey or getattr(settings, 'FILEPICKER_API_KEY', None)
@@ -38,6 +39,7 @@ def initialize(self, apikey=None, mimetypes=None, services=None):
self.mimetypes = str(self.mimetypes)
self.services = services or getattr(settings, 'FILEPICKER_SERVICES', None)
+ self.additional_params = additional_params or getattr(settings, 'FILEPICKER_ADDITIONAL_PARAMS', None)
def widget_attrs(self, widget):
attrs = {
@@ -48,6 +50,9 @@ def widget_attrs(self, widget):
if self.services:
attrs['data-fp-option-services'] = self.services
+ if self.additional_params:
+ attrs = dict(attrs.items() + self.additional_params.items())
+
return attrs
@@ -62,11 +67,13 @@ def __init__(self, *args, **kwargs):
* apikey. This string is required if it isn't set as settings.FILEPICKER_API_KEY
* mimetypes. Optional, the allowed mimetypes for files. Defaults to "*/*" (all files)
* services. Optional, the allowed services to pull from.
+ * additional_params. Optional, additional parameters to be applied.
"""
self.initialize(
apikey=kwargs.pop('apikey', None),
mimetypes=kwargs.pop('mimetypes', None),
services=kwargs.pop('services', None),
+ additional_params=kwargs.pop('additional_params', None),
)
super(FPUrlField, self).__init__(*args, **kwargs)
@@ -79,11 +86,13 @@ def __init__(self, *args, **kwargs):
* apikey. This string is required if it isn't set as settings.FILEPICKER_API_KEY
* mimetypes. Optional, the allowed mimetypes for files. Defaults to "*/*" (all files)
* services. Optional, the allowed services to pull from.
+ * additional_params. Optional, additional parameters to be applied.
"""
self.initialize(
apikey=kwargs.pop('apikey', None),
mimetypes=kwargs.pop('mimetypes', None),
services=kwargs.pop('services', None),
+ additional_params=kwargs.pop('additional_params', None),
)
super(FPFileField, self).__init__(*args, **kwargs)
@@ -14,10 +14,12 @@ def __init__(self, *args, **kwargs):
* apikey. This string is required if it isn't set as settings.FILEPICKER_API_KEY
* mimetypes. Optional, the allowed mimetypes for files. Defaults to "*/*" (all files)
* services. Optional, the allowed services to pull from.
+ * additional_params. Optional, additional parameters to be applied.
"""
self.apikey = kwargs.pop("apikey", None)
self.mimetypes = kwargs.pop("mimetypes", None)
self.services = kwargs.pop("services", None)
+ self.additional_params=kwargs.pop("additional_params", None)
super(FPFileField, self).__init__(*args, **kwargs)
@@ -34,6 +36,8 @@ def formfield(self, **kwargs):
defaults['mimetypes'] = self.mimetypes
if self.services:
defaults['services'] = self.services
+ if self.additional_params:
+ defaults['additional_params'] = self.additional_params
defaults.update(kwargs)
return super(FPFileField, self).formfield(**defaults)

0 comments on commit 420c3c9

Please sign in to comment.