API terminée

This commit is contained in:
Michel Roux 2016-02-14 17:51:54 +01:00
parent 66cc4cd008
commit 1039d1e6d6
4 changed files with 38 additions and 1 deletions

View File

@ -1,3 +1,4 @@
# coding=utf-8
""" """
Django settings for Lengow project. Django settings for Lengow project.
@ -36,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'rest_framework',
] ]
MIDDLEWARE_CLASSES = [ MIDDLEWARE_CLASSES = [
@ -115,3 +117,14 @@ USE_TZ = True
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATICFILES_DIRS = ['static'] STATICFILES_DIRS = ['static']
# Rest Framework
# TODO: Gérer l'authentification pour la modification / suppression via l'API
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
}

View File

@ -13,13 +13,21 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include 1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
""" """
from django.conf.urls import url from django.conf.urls import url, include
from django.contrib import admin from django.contrib import admin
from rest_framework import routers
from orders import views from orders import views
from orders.views import OrderViewSet
router = routers.DefaultRouter()
router.register(r'orders', OrderViewSet)
urlpatterns = [ urlpatterns = [
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^$', views.OrderIndexView.as_view(), name='index'), url(r'^$', views.OrderIndexView.as_view(), name='index'),
url(r'^(?P<pk>[-\w]+)/$', views.OrderDetailView.as_view(), name='detail'), url(r'^(?P<pk>[-\w]+)/$', views.OrderDetailView.as_view(), name='detail'),
url(r'^api/', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
] ]

View File

@ -1,5 +1,7 @@
from django.views.generic import ListView, DetailView from django.views.generic import ListView, DetailView
from rest_framework import serializers, viewsets
from orders.models import Order from orders.models import Order
@ -11,3 +13,16 @@ class OrderIndexView(ListView):
class OrderDetailView(DetailView): class OrderDetailView(DetailView):
template_name = 'orders/order/detail.html' template_name = 'orders/order/detail.html'
model = Order model = Order
class OrderSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Order
fields = ('marketplace', 'idFlux', 'order_id', 'order_mrid', 'order_refid', 'order_external_id',
'order_purchase', 'order_amount', 'order_tax', 'order_shipping', 'order_commission',
'order_processing_fee', 'order_comments', 'customer_id', 'order_ip', 'order_items')
class OrderViewSet(viewsets.ModelViewSet):
queryset = Order.objects.all()
serializer_class = OrderSerializer

View File

@ -1,2 +1,3 @@
django django
pytz pytz
djangorestframework