Skip to content

Commit

Permalink
Merge pull request #31 from hsiaoyi0504/django-1.11
Browse files Browse the repository at this point in the history
Update syntax of build_attrs()
  • Loading branch information
scream4ik authored Mar 13, 2018
2 parents 79ba87d + 126982d commit f3cb2fb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion filebrowser/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, attrs=None):
def render(self, name, value, attrs=None):
if value is None:
value = ""
final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
final_attrs = self.build_attrs(self.attrs, attrs, type=self.input_type, name=name)
final_attrs['search_icon'] = os.path.join(
URL_FILEBROWSER_MEDIA, 'img/filebrowser_icon_show.gif'
)
Expand All @@ -55,6 +55,17 @@ def render(self, name, value, attrs=None):
pass
return render_to_string(_template() + "custom_field.html", locals())

def build_attrs(self, base_attrs, extra_attrs=None, **kwargs):
"""
Helper function for building an attribute dictionary.
Override Widget.build_attrs to support Django<=1.10 and Django>=1.11
at the same time.
"""
attrs = dict(base_attrs, **kwargs)
if extra_attrs:
attrs.update(extra_attrs)
return attrs


class FileBrowseFormField(forms.CharField):
default_error_messages = {
Expand Down

0 comments on commit f3cb2fb

Please sign in to comment.