Skip to content

Commit

Permalink
add drf integration; some clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed May 17, 2017
1 parent 59926a6 commit 6fb4eb6
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 100 deletions.
24 changes: 22 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
Release history
===============
Release history and notes
=========================
`Sequence based identifiers
<http://en.wikipedia.org/wiki/Software_versioning#Sequence-based_identifiers>`_
are used for versioning (schema follows below):

.. code-block:: none
major.minor[.revision]
- It's always safe to upgrade within the same minor version (for example, from
0.3 to 0.3.4).
- Minor version changes might be backwards incompatible. Read the
release notes carefully before upgrading (for example, when upgrading from
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.2
---
2016-05-17

- Add ``NoneField`` for Django REST framework.

0.1
---
Expand Down
2 changes: 1 addition & 1 deletion LICENSE_GPL2.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

django-nonefield - None field for Django.
Copyright (C) 2013-2015 Artur Barseghyan
Copyright (C) 2013-2017 Artur Barseghyan

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion LICENSE_LGPL_2.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.

django-nonefield - None field for Django.
Copyright (C) 2013-2015 Artur Barseghyan
Copyright (C) 2013-2017 Artur Barseghyan

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
44 changes: 26 additions & 18 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
================
django-nonefield
================
`django-nonefield` is a None field for Django.
``django-nonefield`` is a None field for Django.

Prerequisites
=============
- Django 1.5, 1.6, 1.7, 1.8
- Python 2.6.8+, 2.7, 3.3
- Django 1.5, 1.6, 1.7, 1.8, 1.9, 1.10, 1.11.
- Python 2.7, 3.4, 3.5, 3.6

Installation
============

1. Install latest stable version from PyPI::
(1) Install latest stable version from PyPI:

$ pip install django-nonefield
.. code-block:: sh
Or latest stable version from GitHub::
pip install django-nonefield
$ pip install -e git+https://github.com/barseghyanartur/django-nonefield@stable
Or latest stable version from GitHub:

Or latest stable version from BitBucket::
.. code-block:: sh
$ pip install -e hg+https://bitbucket.org/barseghyanartur/django-nonefield@stable
pip install https://github.com/barseghyanartur/django-nonefield/archive/stable.tar.gz
2. Add `nonefield` to ``INSTALLED_APPS`` of the your projects' Django settings.
Or latest stable version from BitBucket:

.. code-block:: python
.. code-block:: sh
pip install https://bitbucket.org/barseghyanartur/django-fobi/get/stable.tar.gz
(2) Add ``nonefield`` to ``INSTALLED_APPS`` of the your projects' Django
settings.

INSTALLED_APPS = (
# ...
# None field
'nonefield',
# ...
)
.. code-block:: python
INSTALLED_APPS = (
# ...
# None field
'nonefield',
# ...
)
Usage
=====
Expand All @@ -44,6 +51,7 @@ forms.py
from nonefield.fields import NoneField
class MyForm(forms.Form):
name = forms.CharField(max_length=255)
some_text = NoneField(initial='Lorem ipsum')
Expand All @@ -59,7 +67,7 @@ GPL 2.0/LGPL 2.1

Support
=======
For any issues contact me at the e-mail given in the `Author` section.
For any issues contact me at the e-mail given in the `Author`_ section.

Author
======
Expand Down
44 changes: 26 additions & 18 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
================
django-nonefield
================
`django-nonefield` is a None field for Django.
``django-nonefield`` is a None field for Django.

Prerequisites
=============
- Django 1.5, 1.6, 1.7, 1.8
- Python 2.6.8+, 2.7, 3.3
- Django 1.5, 1.6, 1.7, 1.8, 1.9, 1.10, 1.11.
- Python 2.7, 3.4, 3.5, 3.6

Installation
============

1. Install latest stable version from PyPI::
(1) Install latest stable version from PyPI::

$ pip install django-nonefield
.. code-block:: sh

Or latest stable version from GitHub::
pip install django-nonefield

$ pip install -e git+https://github.com/barseghyanartur/django-nonefield@stable
Or latest stable version from GitHub::

Or latest stable version from BitBucket::
.. code-block:: sh

$ pip install -e hg+https://bitbucket.org/barseghyanartur/django-nonefield@stable
pip install https://github.com/barseghyanartur/django-nonefield/archive/stable.tar.gz

2. Add `nonefield` to ``INSTALLED_APPS`` of the your projects' Django settings.
Or latest stable version from BitBucket::

.. code-block:: python
.. code-block:: sh

pip install https://bitbucket.org/barseghyanartur/django-fobi/get/stable.tar.gz

(2) Add ``nonefield`` to ``INSTALLED_APPS`` of the your projects' Django
settings.

INSTALLED_APPS = (
# ...
# None field
'nonefield',
# ...
)
.. code-block:: python
INSTALLED_APPS = (
# ...
# None field
'nonefield',
# ...
)
Usage
=====
Expand All @@ -44,6 +51,7 @@ forms.py
from nonefield.fields import NoneField
class MyForm(forms.Form):
name = forms.CharField(max_length=255)
some_text = NoneField(initial='Lorem ipsum')
Expand All @@ -59,7 +67,7 @@ GPL 2.0/LGPL 2.1

Support
=======
For any issues contact me at the e-mail given in the `Author` section.
For any issues contact me at the e-mail given in the `Author`_ section.

Author
======
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
# debug_toolbar
MIDDLEWARE_CLASSES += (
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
)

INSTALLED_APPS += (
'debug_toolbar',
Expand Down
34 changes: 5 additions & 29 deletions examples/simple/urls.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url

from django.conf import settings
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls.static import static
from django.views.generic import TemplateView

from fobi.settings import DEFAULT_THEME

admin.autodiscover()

# Mapping.
fobi_theme_home_template_mapping = {
'bootstrap3': 'home/bootstrap3.html',
'foundation5': 'home/foundation5.html',
}

# Get the template to be used.
fobi_home_template = fobi_theme_home_template_mapping.get(DEFAULT_THEME, 'home/base.html')

urlpatterns = patterns('',
# django-fobi URLs:
url(r'^fobi/', include('fobi.urls')),

url(r'^admin_tools/', include('admin_tools.urls')),

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),

# django-registration URLs:
(r'^accounts/', include('registration.backends.default.urls')),

# foo URLs:
url(r'^foo/', include('foo.urls')),

url(r'^$', TemplateView.as_view(template_name=fobi_home_template)),

# django-fobi public forms contrib app:
#url(r'^', include('fobi.contrib.apps.public_forms.urls')),
)
# # foo URLs:
# url(r'^foo/', include('foo.urls')),
]

if settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()
Expand Down
31 changes: 16 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
except:
readme = ''

version = '0.1'
version = '0.2'

install_requires = [
]
Expand All @@ -21,29 +21,30 @@
pass

setup(
name = 'django-nonefield',
version = version,
description = ("A None field for Django."),
long_description = readme,
classifiers = [
name='django-nonefield',
version=version,
description="A None field for Django.",
long_description=readme,
classifiers=[
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Environment :: Web Environment",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
"License :: OSI Approved :: GNU Lesser General Public License v2 or "
"later (LGPLv2+)",
"Framework :: Django",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Development Status :: 3 - Alpha",
],
keywords = 'forms, django, none field, django none field',
author = 'Artur Barseghyan',
author_email = 'artur.barseghyan@gmail.com',
url = 'https://github.com/barseghyanartur/django-nonefield/',
package_dir = {'':'src'},
packages = find_packages(where='./src'),
license = 'GPL 2.0/LGPL 2.1',
install_requires = install_requires,
keywords='forms, django, none field, django none field',
author='Artur Barseghyan',
author_email='artur.barseghyan@gmail.com',
url='https://github.com/barseghyanartur/django-nonefield/',
package_dir={'': 'src'},
packages=find_packages(where='./src'),
license='GPL 2.0/LGPL 2.1',
install_requires=install_requires,
)
6 changes: 3 additions & 3 deletions src/nonefield/__init__.py
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.
44 changes: 44 additions & 0 deletions src/nonefield/contrib/drf_integration/fields.py
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))

0 comments on commit 6fb4eb6

Please sign in to comment.