Skip to content
This repository was archived by the owner on Jan 19, 2024. It is now read-only.

Commit b93fb90

Browse files
committed
First pass
0 parents  commit b93fb90

18 files changed

+578
-0
lines changed

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
*.pyc
2+
*.db
3+
*~
4+
.*
5+
6+
html/
7+
htmlcov/
8+
coverage/
9+
build/
10+
dist/
11+
*.egg-info/
12+
MANIFEST
13+
14+
bin/
15+
include/
16+
lib/
17+
local/
18+
19+
!.gitignore
20+
!.travis.yml

.travis.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
language: python
2+
3+
sudo: false
4+
5+
env:
6+
- TOX_ENV=py27-flake8
7+
- TOX_ENV=py27-docs
8+
- TOX_ENV=py27-django1.6-drf2.4
9+
- TOX_ENV=py27-django1.6-drf3.0
10+
- TOX_ENV=py27-django1.6-drf3.1
11+
- TOX_ENV=py27-django1.7-drf2.4
12+
- TOX_ENV=py27-django1.7-drf3.0
13+
- TOX_ENV=py27-django1.7-drf3.1
14+
- TOX_ENV=py27-django1.8-drf2.4
15+
- TOX_ENV=py27-django1.8-drf3.0
16+
- TOX_ENV=py27-django1.8-drf3.1
17+
- TOX_ENV=py33-django1.6-drf2.4
18+
- TOX_ENV=py33-django1.6-drf3.0
19+
- TOX_ENV=py33-django1.6-drf3.1
20+
- TOX_ENV=py33-django1.7-drf2.4
21+
- TOX_ENV=py33-django1.7-drf3.0
22+
- TOX_ENV=py33-django1.7-drf3.1
23+
- TOX_ENV=py33-django1.8-drf2.4
24+
- TOX_ENV=py33-django1.8-drf3.0
25+
- TOX_ENV=py33-django1.8-drf3.1
26+
- TOX_ENV=py34-django1.6-drf2.4
27+
- TOX_ENV=py34-django1.6-drf3.0
28+
- TOX_ENV=py34-django1.6-drf3.1
29+
- TOX_ENV=py34-django1.7-drf2.4
30+
- TOX_ENV=py34-django1.7-drf3.0
31+
- TOX_ENV=py34-django1.7-drf3.1
32+
- TOX_ENV=py34-django1.8-drf2.4
33+
- TOX_ENV=py34-django1.8-drf3.0
34+
- TOX_ENV=py34-django1.8-drf3.1
35+
36+
matrix:
37+
fast_finish: true
38+
39+
install:
40+
- pip install tox
41+
42+
script:
43+
- tox -e $TOX_ENV

LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2015, Tom Christie <tom@tomchristie.com>
2+
3+
Permission to use, copy, modify, and/or distribute this software for any
4+
purpose with or without fee is hereby granted, provided that the above
5+
copyright notice and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

MANIFEST.in

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include README.rst LICENSE
2+
recursive-exclude * __pycache__
3+
recursive-exclude * *.py[co]

README.rst

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
django-rest-marshmallow
2+
======================================
3+
4+
|build-status-image| |pypi-version|
5+
6+
Overview
7+
--------
8+
9+
Marshmallow schemas for Django REST framework
10+
11+
Requirements
12+
------------
13+
14+
- Python (2.7, 3.3, 3.4)
15+
- Django (1.6, 1.7, 1.8)
16+
- Django REST Framework (2.4, 3.0, 3.1)
17+
18+
Installation
19+
------------
20+
21+
Install using ``pip``\
22+
23+
.. code:: bash
24+
25+
$ pip install django-rest-marshmallow
26+
27+
Example
28+
-------
29+
30+
TODO: Write example.
31+
32+
Testing
33+
-------
34+
35+
Install testing requirements.
36+
37+
.. code:: bash
38+
39+
$ pip install -r requirements.txt
40+
41+
Run with runtests.
42+
43+
.. code:: bash
44+
45+
$ ./runtests.py
46+
47+
You can also use the excellent `tox`_ testing tool to run the tests
48+
against all supported versions of Python and Django. Install tox
49+
globally, and then simply run:
50+
51+
.. code:: bash
52+
53+
$ tox
54+
55+
Documentation
56+
-------------
57+
58+
To build the documentation, you’ll need to install ``mkdocs``.
59+
60+
.. code:: bash
61+
62+
$ pip install mkdocs
63+
64+
To preview the documentation:
65+
66+
.. code:: bash
67+
68+
$ mkdocs serve
69+
Running at: http://127.0.0.1:8000/
70+
71+
To build the documentation:
72+
73+
.. code:: bash
74+
75+
$ mkdocs build
76+
77+
.. _tox: http://tox.readthedocs.org/en/latest/
78+
79+
.. |build-status-image| image:: https://secure.travis-ci.org/tomchristie/django-rest-marshmallow.svg?branch=master
80+
:target: http://travis-ci.org/tomchristie/django-rest-marshmallow?branch=master
81+
.. |pypi-version| image:: https://img.shields.io/pypi/v/django-rest-marshmallow.svg
82+
:target: https://pypi.python.org/pypi/django-rest-marshmallow

docs/css/extra.css

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
body.homepage div.col-md-9 h1:first-of-type {
2+
text-align: center;
3+
font-size: 60px;
4+
font-weight: 300;
5+
margin-top: 0;
6+
}
7+
8+
body.homepage div.col-md-9 p:first-of-type {
9+
text-align: center;
10+
}
11+
12+
body.homepage .badges {
13+
text-align: right;
14+
}
15+
16+
body.homepage .badges a {
17+
display: inline-block;
18+
}
19+
20+
body.homepage .badges a img {
21+
padding: 0;
22+
margin: 0;
23+
}

docs/index.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<div class="badges">
2+
<a href="http://travis-ci.org/tomchristie/django-rest-marshmallow">
3+
<img src="https://travis-ci.org/tomchristie/django-rest-marshmallow.svg?branch=master">
4+
</a>
5+
<a href="https://pypi.python.org/pypi/django-rest-marshmallow">
6+
<img src="https://img.shields.io/pypi/v/django-rest-marshmallow.svg">
7+
</a>
8+
</div>
9+
10+
---
11+
12+
# django-rest-marshmallow
13+
14+
Marshmallow schemas for Django REST framework
15+
16+
---
17+
18+
## Overview
19+
20+
Marshmallow schemas for Django REST framework
21+
22+
## Requirements
23+
24+
* Python (2.7, 3.3, 3.4)
25+
* Django (1.6, 1.7)
26+
27+
## Installation
28+
29+
Install using `pip`...
30+
31+
```bash
32+
$ pip install django-rest-marshmallow
33+
```
34+
35+
## Example
36+
37+
TODO: Write example.
38+
39+
## Testing
40+
41+
Install testing requirements.
42+
43+
```bash
44+
$ pip install -r requirements.txt
45+
```
46+
47+
Run with runtests.
48+
49+
```bash
50+
$ ./runtests.py
51+
```
52+
53+
You can also use the excellent [tox](http://tox.readthedocs.org/en/latest/) testing tool to run the tests against all supported versions of Python and Django. Install tox globally, and then simply run:
54+
55+
```bash
56+
$ tox
57+
```
58+
59+
## Documentation
60+
61+
To build the documentation, you'll need to install `mkdocs`.
62+
63+
```bash
64+
$ pip install mkdocs
65+
```
66+
67+
To preview the documentation:
68+
69+
```bash
70+
$ mkdocs serve
71+
Running at: http://127.0.0.1:8000/
72+
```
73+
74+
To build the documentation:
75+
76+
```bash
77+
$ mkdocs build
78+
```

env/pip-selfcheck.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"last_check":"2015-09-11T09:06:09Z","pypi_version":"7.1.2"}

mkdocs.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
site_name: django-rest-marshmallow
2+
site_description: Marshmallow schemas for Django REST framework
3+
repo_url: https://github.com/tomchristie/django-rest-marshmallow
4+
site_dir: html

requirements.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Minimum Django and REST framework version
2+
Django==1.8.4
3+
djangorestframework==3.2.3
4+
marshmallow==1.2.6
5+
6+
# Test requirements
7+
pytest-django==2.8.0
8+
pytest==2.5.2
9+
pytest-cov==1.6
10+
flake8==2.2.2
11+
12+
# wheel for PyPI installs
13+
wheel==0.24.0
14+
15+
# MkDocs for documentation previews/deploys
16+
mkdocs==0.11.1

rest_marshmallow/__init__.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from rest_framework.serializers import BaseSerializer, ValidationError
2+
3+
4+
__version__ = '1.0.0'
5+
6+
7+
def create_serializer_class(schema_class):
8+
return type('Test', (MarshmallowSerializer,), {'_schema_class': schema_class})
9+
10+
11+
class MarshmallowSerializer(BaseSerializer):
12+
def __init__(self, *args, **kwargs):
13+
super(MarshmallowSerializer, self).__init__(*args, **kwargs)
14+
self._schema = self._schema_class(many=kwargs.get('many', False))
15+
16+
def to_representation(self, instance):
17+
return self._schema.dump(instance).data
18+
19+
def to_internal_value(self, data):
20+
ret = self._schema.load(data)
21+
if ret.errors:
22+
raise ValidationError(ret.errors)
23+
return ret.data

0 commit comments

Comments
 (0)