Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax Validation ImageField. Possibly bug? #331

Open
nikolaysm opened this issue Apr 5, 2018 · 1 comment
Open

Ajax Validation ImageField. Possibly bug? #331

nikolaysm opened this issue Apr 5, 2018 · 1 comment

Comments

@nikolaysm
Copy link

Hello,
I am using django 1.11.

When i do update object with Ajax i get error for ImageField.

That is "FileExtensionValidator" from django who expects an object for validation but a unicode is given.

Thanks for replying
Full Traceback

Traceback (most recent call last):
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/admin/development/hnj/company/views.py", line 67, in post
    if self.request.is_ajax():
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/forms/forms.py", line 183, in is_valid
    return self.is_bound and not self.errors
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/forms/forms.py", line 175, in errors
    self.full_clean()
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/forms/forms.py", line 384, in full_clean
    self._clean_fields()
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/forms/forms.py", line 400, in _clean_fields
    value = field.clean(value, initial)
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/forms/fields.py", line 600, in clean
    return super(FileField, self).clean(data)
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/forms/fields.py", line 162, in clean
    self.run_validators(value)
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/forms/fields.py", line 145, in run_validators
    v(value)
  File "/root/.virtualenvs/django-1.11/local/lib/python2.7/site-packages/django/core/validators.py", line 476, in __call__
    extension = os.path.splitext(value.name)[1][1:].lower()
AttributeError: 'unicode' object has no attribute 'name'
@nikolaysm nikolaysm changed the title Ajax Validation ImageField Ajax Validation ImageField Possibly bug Apr 6, 2018
@nikolaysm nikolaysm changed the title Ajax Validation ImageField Possibly bug Ajax Validation ImageField. Possibly bug? Apr 6, 2018
@nikolaysm
Copy link
Author

nikolaysm commented Apr 9, 2018

Could be solved by adding below function in "DropFileWidget"

def value_from_datadict(self, data, files, name):
        """
        Given a dictionary of data and this widget's name, return the value
        of this widget or None if it's not provided.
        """
        tmp = data.get(name)
        if tmp and len(tmp) == 1:
            tmp = tmp.get('current_file')
        return tmp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant