-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59926a6
commit 6fb4eb6
Showing
14 changed files
with
166 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
__title__ = 'django-nonefield' | ||
__version__ = '0.1' | ||
__build__ = 0x000001 | ||
__version__ = '0.2' | ||
__build__ = 0x000002 | ||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>' | ||
__copyright__ = 'Copyright (c) 2013-2014 Artur Barseghyan' | ||
__copyright__ = '2013-2017 Artur Barseghyan' | ||
__license__ = 'GPL 2.0/LGPL 2.1' |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import six | ||
|
||
from django.utils.safestring import mark_safe | ||
|
||
from rest_framework.fields import empty, Field | ||
|
||
__title__ = 'nonefield.contrib.drf_integration.fields' | ||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>' | ||
__copyright__ = '2013-2017 Artur Barseghyan' | ||
__license__ = 'GPL 2.0/LGPL 2.1' | ||
__all__ = ('NoneField',) | ||
|
||
|
||
class NoneField(Field): | ||
"""NoneField.""" | ||
|
||
default_error_messages = {} | ||
initial = '' | ||
default_empty_html = '' | ||
|
||
def __init__(self, **kwargs): | ||
self.allow_blank = True | ||
self.trim_whitespace = kwargs.pop('trim_whitespace', True) | ||
self.raw_data = kwargs.pop('raw_data', {}) | ||
super(NoneField, self).__init__(**kwargs) | ||
|
||
def run_validation(self, data=empty): | ||
return '' | ||
|
||
def to_internal_value(self, data): | ||
# We're lenient with allowing basic numerics to be coerced into | ||
# strings, but other types should fail. Eg. unclear if booleans | ||
# should represent as `true` or `True`, and composites such as lists | ||
# are likely user error. | ||
_not_isinstance_str_int_float = not isinstance( | ||
data, six.string_types + six.integer_types + (float,) | ||
) | ||
if isinstance(data, bool) or _not_isinstance_str_int_float: | ||
self.fail('invalid') | ||
value = six.text_type(data) | ||
return value.strip() if self.trim_whitespace else value | ||
|
||
def to_representation(self, value): | ||
return mark_safe(six.text_type(value)) |
Oops, something went wrong.