Commit 877e964d by Tom Christie

Don't need to support Django 1.4 with FilePathField.

parent 8d7c0a84
...@@ -257,21 +257,3 @@ def set_rollback(): ...@@ -257,21 +257,3 @@ def set_rollback():
else: else:
# transaction not managed # transaction not managed
pass pass
def get_filepathfield(path, match=None, recursive=False, allow_files=True,
allow_folders=False, required=None):
"""Create proper Django FilePathField with allowed kwargs."""
if django.VERSION < (1, 5):
# django field doesn't have allow_folders, allow_files kwargs
field = DjangoFilePathField(
path, match=match, recursive=recursive, required=required
)
else:
field = DjangoFilePathField(
path, match=match, recursive=recursive, allow_files=allow_files,
allow_folders=allow_folders, required=required
)
return field
...@@ -12,6 +12,7 @@ from django.conf import settings ...@@ -12,6 +12,7 @@ from django.conf import settings
from django.core.exceptions import ValidationError as DjangoValidationError from django.core.exceptions import ValidationError as DjangoValidationError
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.validators import RegexValidator, ip_address_validators from django.core.validators import RegexValidator, ip_address_validators
from django.forms import FilePathField as DjangoFilePathField
from django.forms import ImageField as DjangoImageField from django.forms import ImageField as DjangoImageField
from django.utils import six, timezone from django.utils import six, timezone
from django.utils.dateparse import parse_date, parse_datetime, parse_time from django.utils.dateparse import parse_date, parse_datetime, parse_time
...@@ -23,7 +24,7 @@ from rest_framework import ISO_8601 ...@@ -23,7 +24,7 @@ from rest_framework import ISO_8601
from rest_framework.compat import ( from rest_framework.compat import (
EmailValidator, MaxLengthValidator, MaxValueValidator, MinLengthValidator, EmailValidator, MaxLengthValidator, MaxValueValidator, MinLengthValidator,
MinValueValidator, OrderedDict, URLValidator, duration_string, MinValueValidator, OrderedDict, URLValidator, duration_string,
get_filepathfield, parse_duration, unicode_repr, unicode_to_repr parse_duration, unicode_repr, unicode_to_repr
) )
from rest_framework.exceptions import ValidationError from rest_framework.exceptions import ValidationError
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
...@@ -713,8 +714,9 @@ class FilePathField(CharField): ...@@ -713,8 +714,9 @@ class FilePathField(CharField):
allow_folders=False, required=None, **kwargs): allow_folders=False, required=None, **kwargs):
super(FilePathField, self).__init__(**kwargs) super(FilePathField, self).__init__(**kwargs)
# create field and get options to avoid code duplication # Defer to Django's FilePathField implmentation to get the
field = get_filepathfield( # valid set of choices.
field = DjangoFilePathField(
path, match=match, recursive=recursive, allow_files=allow_files, path, match=match, recursive=recursive, allow_files=allow_files,
allow_folders=allow_folders, required=required allow_folders=allow_folders, required=required
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment