Skip to content

Master bug fixes #2

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

Merged
merged 13 commits into from
Sep 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ rest_framework_docs/static/rest_framework_docs/js/dist.min.js

rest_framework_docs/static/node_modules/
rest_framework_docs/static/rest_framework_docs/js/dist.min.js.map
.idea
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,24 @@ You can find detailed information about the package's settings at [the docs](htt

REST_FRAMEWORK_DOCS = {
'HIDE_DOCS': True # Default: False
'MODULE_ROUTERS': {},
'DEFAULT_MODULE_ROUTER': 'router',
'DEFAULT_ROUTER': None,
}


### Credits

First of all thanks to the [Django](http://www.djangoproject.com/) core team and to all the contributors of [Django REST Framework](http://www.django-rest-framework.org/) for their amazing work. Also I would like to thank [Marc Gibbons](https://github.com/marcgibbons) for his *django-rest-framework-docs* project. Both projects share the same idea, it is just that Marc's is not maintained anymore and does not support DRF 3+ & Python 3.

[travis-image]: https://travis-ci.org/ekonstantinidis/django-rest-framework-docs.svg?branch=master
[travis-url]: https://travis-ci.org/ekonstantinidis/django-rest-framework-docs
[travis-image]: https://travis-ci.org/manosim/django-rest-framework-docs.svg?branch=master
[travis-url]: https://travis-ci.org/manosim/django-rest-framework-docs

[pypi-image]: https://badge.fury.io/py/drfdocs.svg
[pypi-url]: https://pypi.python.org/pypi/drfdocs/

[codecov-image]: https://codecov.io/github/ekonstantinidis/django-rest-framework-docs/coverage.svg?branch=master
[codecov-url]:https://codecov.io/github/ekonstantinidis/django-rest-framework-docs?branch=master
[codecov-image]: https://codecov.io/github/manosim/django-rest-framework-docs/coverage.svg?branch=master
[codecov-url]:https://codecov.io/github/manosim/django-rest-framework-docs?branch=master

[slack-image]: https://img.shields.io/badge/slack-pythondev/drfdocs-e01563.svg
[slack-url]: https://pythondev.slack.com
12 changes: 11 additions & 1 deletion demo/project/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
from django.conf.urls import url
from django.conf.urls import url, include
from rest_framework import routers
from project.accounts import views


router = routers.DefaultRouter()
router.register(
r'user_viewset',
views.UserModelViewSet,
)


urlpatterns = [
url(r'^test/$', views.TestView.as_view(), name="test-view"),

url(r'^login/$', views.LoginView.as_view(), name="login"),
url(r'^register/$', views.UserRegistrationView.as_view(), name="register"),
url(r'^register/$', views.UserRegistrationView.as_view(), name="register"),
url(r'^reset-password/$', view=views.PasswordResetView.as_view(), name="reset-password"),
url(r'^reset-password/confirm/$', views.PasswordResetConfirmView.as_view(), name="reset-password-confirm"),

url(r'^user/profile/$', views.UserProfileView.as_view(), name="profile"),

url(r'^viewset_test/', include(router.urls), name="user_viewset"),
]
6 changes: 6 additions & 0 deletions demo/project/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet
from project.accounts.models import User
from project.accounts.serializers import (
UserRegistrationSerializer, UserProfileSerializer, ResetPasswordSerializer
Expand Down Expand Up @@ -81,3 +82,8 @@ def post(self, request, *args, **kwargs):
if not serializer.is_valid():
return Response({'errors': serializer.errors}, status=status.HTTP_400_BAD_REQUEST)
return Response({"msg": "Password updated successfully."}, status=status.HTTP_200_OK)


class UserModelViewSet(ModelViewSet):
queryset = User.objects.all()
serializer_class = UserProfileSerializer
13 changes: 11 additions & 2 deletions demo/project/organisations/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
from django.conf.urls import url
from django.conf.urls import url, include
from rest_framework import routers
from project.organisations import views


router = routers.DefaultRouter()
router.register(
r'organisation_viewset',
views.OrganisationViewSet,
)


urlpatterns = [

url(r'^create/$', view=views.CreateOrganisationView.as_view(), name="create"),
url(r'^(?P<slug>[\w-]+)/$', view=views.RetrieveOrganisationView.as_view(), name="organisation"),
url(r'^(?P<slug>[\w-]+)/members/$', view=views.OrganisationMembersView.as_view(), name="members"),
url(r'^(?P<slug>[\w-]+)/leave/$', view=views.LeaveOrganisationView.as_view(), name="leave")
url(r'^(?P<slug>[\w-]+)/leave/$', view=views.LeaveOrganisationView.as_view(), name="leave"),

url(r'^', include(router.urls), name="organisation_viewset"),
]
9 changes: 8 additions & 1 deletion demo/project/organisations/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from rest_framework import generics, status
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from project.organisations.models import Organisation, Membership
from project.organisations.serializers import (
CreateOrganisationSerializer, OrganisationMembersSerializer, RetrieveOrganisationSerializer
CreateOrganisationSerializer, OrganisationMembersSerializer,
RetrieveOrganisationSerializer, OrganisationDetailSerializer
)


Expand Down Expand Up @@ -34,3 +36,8 @@ def delete(self, request, *args, **kwargs):
instance = self.get_object()
self.perform_destroy(instance)
return Response(status=status.HTTP_204_NO_CONTENT)


class OrganisationViewSet(ModelViewSet):
queryset = Organisation.objects.all()
serializer_class = OrganisationDetailSerializer
8 changes: 8 additions & 0 deletions demo/project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@
)
}

REST_FRAMEWORK_DOCS = {
'HIDE_DOCS': False,
'MODULE_ROUTERS': {
'project.accounts.urls': 'router',
},
'DEFAULT_MODULE_ROUTER': 'router',
}

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

Expand Down
4 changes: 4 additions & 0 deletions demo/project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
from django.conf.urls import include, url
from django.contrib import admin


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

# API
url(r'^accounts/', view=include('project.accounts.urls', namespace='accounts')),


url(r'^organisations/', view=include('project.organisations.urls', namespace='organisations')),

]
2 changes: 1 addition & 1 deletion docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source_filename: contributing
### Development
If you want to **use the demo** app to work on this package:

In the project [repository](https://github.com/ekonstantinidis/django-rest-framework-docs) you can find the demo app(at /demo). It is a project with Django & Django Rest Framework that will allow you to work with this project.
In the project [repository](https://github.com/manosim/django-rest-framework-docs) you can find the demo app(at /demo). It is a project with Django & Django Rest Framework that will allow you to work with this project.

From the root of the repository:

Expand Down
35 changes: 30 additions & 5 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ source_filename: settings
To set DRF docs' settings just include the dictionary below in Django's `settings.py` file.

REST_FRAMEWORK_DOCS = {
'HIDE_DOCS': True
'HIDE_DOCS': True,
'MODULE_ROUTERS': {
'project.accounts.urls': 'accounts_router',
},
'DEFAULT_MODULE_ROUTER': 'router',
'DEFAULT_ROUTER': 'project.urls.default_router',
}


Expand All @@ -21,9 +26,29 @@ You can use hidden to prevent your docs from showing up in different environment

Then set the value of the environment variable `HIDE_DRFDOCS` for each environment (ie. Use `.env` files)

##### MODULE_ROUTERS
Use this setting to manually bind url modules to a router instance. The router must be defined in the module, or imported in the module.
For instance, if the router of an app called 'gifts' is 'gifts_router', and the router of another app called 'scuba_diving' is 'scuba_diving_router', the MODULE_ROUTERS setting should look like:

'MODULE_ROUTERS': {
'gifts.urls': 'gift_router',
'scuba_diving.urls': 'scuba_diving_router'
}

If there is no entry for a given module, if this setting is not set, or if it is set to None, the value of the DEFAULT_MODULE_ROUTER setting is used.

##### DEFAULT_MODULE_ROUTER
When set, the value of this setting will be used to find a router for a urls module. If there is no router having the DEFAULT_MODULE_ROUTER name, the setting is ignored and the value of DEFAULT_ROUTER is used.

##### DEFAULT_ROUTER
When defined, this setting must describe a python dotted path leading to the router that should be used when MODULE_ROUTERS and DEFAULT_MODULE_ROUTER are not set.
This parameter is useful when there is only one router for your whole API.

### List of Settings

| Setting | Type | Options | Default |
|---------|---------|-----------------|---------|
|HIDE_DOCS| Boolean | `True`, `False` | `False` |
| | | | |
| Setting | Type | Options | Default |
|---------------------|-----------------------------------------------------------|-----------------|---------|
|HIDE_DOCS | Boolean | `True`, `False` | `False` |
|MODULE_ROUTERS | dict of python dotted paths -> router instance name | | `None` |
|DEFAULT_MODULE_ROUTER| str representing a default router instance name | | `None` |
|DEFAULT_ROUTER | str representing a python dotted path to a router instance| | `None` |
4 changes: 2 additions & 2 deletions docs/template/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@

<footer class="col-md-12 footer">
<div class="links">
<a href="http://www.iamemmanouil.com"><i class="fa fa-link"></i></a>
<a href="http://www.github.com/ekonstantinidis"><i class="fa fa-github"></i></a>
<a href="http://www.manos.im/"><i class="fa fa-link"></i></a>
<a href="http://www.github.com/manosim"><i class="fa fa-github"></i></a>
<a href="http://www.twitter.com/iamemmanouil"><i class="fa fa-twitter"></i></a>
</div>
{% if copyright %}
Expand Down
2 changes: 1 addition & 1 deletion docs/template/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
{{ content }}

{% for filename in meta.source_filename %}
<a class="btn btn-default btn-edit" href="https://github.com/ekonstantinidis/django-rest-framework-docs/blob/master/docs/{{ filename }}.md"><i class="fa fa-github"></i> Edit on Github</a>
<a class="btn btn-default btn-edit" href="https://github.com/manosim/django-rest-framework-docs/blob/master/docs/{{ filename }}.md"><i class="fa fa-github"></i> Edit on Github</a>
{% endfor %}
</div>
4 changes: 2 additions & 2 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ To hide the GitHub badge from the page, just override it with an empty block.
{% block footer %}
<div class="footer">
<div class="links">
<a href="http://www.iamemmanouil.com"><i class="fa fa-link"></i></a>
<a href="http://www.github.com/ekonstantinidis"><i class="fa fa-github"></i></a>
<a href="http://www.manosim.com"><i class="fa fa-link"></i></a>
<a href="http://www.github.com/manosim"><i class="fa fa-github"></i></a>
<a href="http://www.twitter.com/iamemmanouil"><i class="fa fa-twitter"></i></a>
</div>
Copyright © 2016 Emmanouil Konstantinidis.
Expand Down
4 changes: 2 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ extra_css:
extra_javascript:
- js/index.js

copyright: Copyright © 2015 Emmanouil Konstantinidis.
copyright: Copyright © 2016 Emmanouil Konstantinidis.
google_analytics: ['UA-71505240-1', 'drfdocs.com']
repo_url: https://github.com/ekonstantinidis/django-rest-framework-docs
repo_url: https://github.com/manosim/django-rest-framework-docs
Loading