diff --git a/inventory/api_views.py b/inventory/api_views.py
new file mode 100644
index 0000000..bc8a0c4
--- /dev/null
+++ b/inventory/api_views.py
@@ -0,0 +1,69 @@
+# Copyright 2013 Jack David Baucum
+#
+# This file is part of Orthosie.
+#
+# Orthosie is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Orthosie is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Orthosie. If not, see .
+
+from rest_framework import viewsets, generics
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+from rest_framework.reverse import reverse
+from inventory.serializers import ItemSerializer, GrocerySerializer
+from inventory.serializers import ProduceSerializer, VendorSerializer
+from inventory.models import Item, Grocery, Produce, Vendor
+
+
+@api_view(['GET'])
+def api_root(request, format=None):
+ """
+ The entry endpoint of our API.
+ """
+ return Response({
+ 'item': reverse('item-list', request=request),
+ 'grocery': reverse('grocery-list', request=request),
+ 'produce': reverse('produce-list', request=request),
+ 'vendor': reverse('vendor-list', request=request)
+ })
+
+
+class ItemViewSet(viewsets.ModelViewSet):
+ """
+ API endpoint that allows items to be viewed or edited.
+ """
+ queryset = Item.objects.all()
+ serializer_class = ItemSerializer
+
+
+class GroceryViewSet(viewsets.ModelViewSet):
+ """
+ API endpoint that allows groceries to be viewed or edited.
+ """
+ queryset = Grocery.objects.all()
+ serializer_class = GrocerySerializer
+
+
+class ProduceViewSet(viewsets.ModelViewSet):
+ """
+ API endpoint that allows produce to be viewed or edited.
+ """
+ queryset = Produce.objects.all()
+ serializer_class = ProduceSerializer
+
+
+class VendorViewSet(viewsets.ModelViewSet):
+ """
+ API endpoint that allows vendors to be viewed or edited.
+ """
+ queryset = Vendor.objects.all()
+ serializer_class = VendorSerializer
diff --git a/inventory/serializers.py b/inventory/serializers.py
new file mode 100644
index 0000000..5053cac
--- /dev/null
+++ b/inventory/serializers.py
@@ -0,0 +1,43 @@
+# Copyright 2013 Jack David Baucum
+#
+# This file is part of Orthosie.
+#
+# Orthosie is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Orthosie is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Orthosie. If not, see .
+
+from inventory.models import Item, Grocery, Produce, Vendor
+from rest_framework import serializers
+
+
+class ItemSerializer(serializers.HyperlinkedModelSerializer):
+ class Meta:
+ model = Item
+ depth = 1
+
+
+class GrocerySerializer(serializers.HyperlinkedModelSerializer):
+ class Meta:
+ model = Grocery
+ depth = 1
+
+
+class ProduceSerializer(serializers.HyperlinkedModelSerializer):
+ class Meta:
+ model = Produce
+ depth = 1
+
+
+class VendorSerializer(serializers.HyperlinkedModelSerializer):
+ class Meta:
+ model = Vendor
+ depth = 1
diff --git a/inventory/tests.py b/inventory/tests.py
index 69cc84f..559a7dd 100644
--- a/inventory/tests.py
+++ b/inventory/tests.py
@@ -71,4 +71,4 @@ def test_verify_check_digit_passes(self):
def test_verify_check_digit_fails(self):
self.test_upc = Upc('008274000065')
- self.assertFalse(self.test_upc.verify_check_digit())
\ No newline at end of file
+ self.assertFalse(self.test_upc.verify_check_digit())
diff --git a/inventory/urls.py b/inventory/urls.py
index bcdbd17..14cc4f8 100644
--- a/inventory/urls.py
+++ b/inventory/urls.py
@@ -1,7 +1,8 @@
from django.conf.urls import patterns, url
from inventory import views
-urlpatterns = patterns('',
+urlpatterns = patterns(
+ '',
url(r'^$', views.index, name='index'),
url(r'update_grocery', views.update_grocery, name='update_grocery'),
url(r'create_grocery', views.create_grocery, name='create_grocery'),
diff --git a/inventory/views.py b/inventory/views.py
index 89a8fc1..397feee 100644
--- a/inventory/views.py
+++ b/inventory/views.py
@@ -1,6 +1,6 @@
from django.shortcuts import render, get_object_or_404
-from inventory.models import Grocery, Produce, Vendor
from django.core.exceptions import ObjectDoesNotExist
+from inventory.models import Item, Grocery, Produce, Vendor
def index(request):
diff --git a/orthosie/urls.py b/orthosie/urls.py
index 0658031..4162de6 100644
--- a/orthosie/urls.py
+++ b/orthosie/urls.py
@@ -1,43 +1,50 @@
+# Copyright 2013 Jack David Baucum
+#
+# This file is part of Orthosie.
+#
+# Orthosie is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Orthosie is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Orthosie. If not, see .
+
from django.conf.urls import patterns, include, url
from rest_framework.urlpatterns import format_suffix_patterns
-from orthosie.views import ItemList, ItemDetail, VendorList, VendorDetail, ShiftList, ShiftDetail, TransactionList, TransactionDetail, LineItemList, LineItemDetail
+from rest_framework import routers
+from inventory.api_views import ItemViewSet, GroceryViewSet, ProduceViewSet, VendorViewSet
+from register.api_views import ShiftViewSet, TransactionViewSet, LineItemViewSet
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
-urlpatterns = patterns('',
+urlpatterns = patterns(
+ '',
url(r'^register/', include('register.urls')),
url(r'^inventory/', include('inventory.urls')),
- url(r'^$', 'api_root'),
- url(r'^items/$', ItemList.as_view(), name='item-list'),
- url(r'^items/(?P\d+)/$', ItemDetail.as_view(), name='item-detail'),
- url(r'^vendors/$', VendorList.as_view(), name='vendor-list'),
- url(
- r'^vendors/(?P\d+)/$',
- VendorDetail.as_view(),
- name='vendor-detail'
- ),
- url(r'^shifts/$', ShiftList.as_view(), name='shift-list'),
- url(r'^shifts/(?P\d+)/$', ShiftDetail.as_view(), name='shift-detail'),
- url(r'^transactions/$', TransactionList.as_view(), name='transaction-list'),
- url(
- r'^transactions/(?P\d+)/$',
- TransactionDetail.as_view(),
- name='transaction-detail'
- ),
- url(r'^line_items/$', LineItemList.as_view(), name='lineitem-list'),
- url(
- r'^line_items/(?P\d+)/$',
- LineItemDetail.as_view(),
- name='lineitem-detail'
- ),
-
)
urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'api'])
-urlpatterns += patterns('',
+router = routers.DefaultRouter()
+router.register(r'items', ItemViewSet)
+router.register(r'groceries', GroceryViewSet)
+router.register(r'produce', ProduceViewSet)
+router.register(r'vendors', VendorViewSet)
+router.register(r'shifts', ShiftViewSet)
+router.register(r'transactions', TransactionViewSet)
+router.register(r'line-items', LineItemViewSet)
+
+urlpatterns += patterns(
+ '',
+ url(r'^', include(router.urls)),
url(
r'^api-auth/',
include('rest_framework.urls', namespace='rest_framework')
diff --git a/orthosie/views.py b/orthosie/views.py
deleted file mode 100644
index f21ce38..0000000
--- a/orthosie/views.py
+++ /dev/null
@@ -1,118 +0,0 @@
-# Copyright 2013 Jack David Baucum
-#
-# This file is part of Orthosie.
-#
-# Orthosie is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Orthosie is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Orthosie. If not, see .
-
-from inventory.models import Item, Vendor
-from register.models import Shift, Transaction, LineItem
-from rest_framework import generics
-from rest_framework.decorators import api_view
-from rest_framework.reverse import reverse
-from rest_framework.response import Response
-from orthosie.serializers import ItemSerializer, VendorSerializer, ShiftSerializer, TransactionSerializer, LineItemSerializer
-
-
-@api_view(['GET'])
-def api_root(request, format=None):
- """
- The entry endpoint of our API.
- """
- return Response({
- 'item': reverse('item-list', request=request),
- 'vendor': reverse('vendor-list', request=request),
- 'shift': reverse('shift-list', request=request),
- 'transaction': reverse('transaction-list', request=request),
- 'lineitem': reverse('lineitem-list', request=request),
- })
-
-
-class ItemList(generics.ListCreateAPIView):
- """
- API endpoint that represents a list of items.
- """
- model = Item
- serializer_class = ItemSerializer
-
-
-class ItemDetail(generics.RetrieveUpdateDestroyAPIView):
- """
- API endpoint that represents a single item.
- """
- model = Item
- serializer_class = ItemSerializer
-
-
-class VendorList(generics.ListCreateAPIView):
- """
- API endpoint that represents a list of vendors.
- """
- model = Vendor
- serializer_class = VendorSerializer
-
-
-class VendorDetail(generics.RetrieveUpdateDestroyAPIView):
- """
- API endpoint that represents a single vendor.
- """
- model = Vendor
- serializer_class = VendorSerializer
-
-
-class ShiftList(generics.ListCreateAPIView):
- """
- API endpoint that represents a list of shift.
- """
- model = Shift
- serializer_class = ShiftSerializer
-
-
-class ShiftDetail(generics.RetrieveUpdateDestroyAPIView):
- """
- API endpoint that represents a single vendor.
- """
- model = Shift
- serializer_class = ShiftSerializer
-
-
-class TransactionList(generics.ListCreateAPIView):
- """
- API endpoint that represents a list of transaction.
- """
- model = Transaction
- serializer_class = TransactionSerializer
-
-
-class TransactionDetail(generics.RetrieveUpdateDestroyAPIView):
- """
- API endpoint that represents a single transaction.
- """
- model = Transaction
- serializer_class = TransactionSerializer
-
-
-class LineItemList(generics.ListCreateAPIView):
- """
- API endpoint that represents a list of line items.
- """
- model = LineItem
- serializer_class = LineItemSerializer
-
-
-class LineItemDetail(generics.RetrieveUpdateDestroyAPIView):
- """
- API endpoint that represents a single line items.
- """
- model = LineItem
- serializer_class = LineItemSerializer
\ No newline at end of file
diff --git a/register/api_views.py b/register/api_views.py
new file mode 100644
index 0000000..fbe3080
--- /dev/null
+++ b/register/api_views.py
@@ -0,0 +1,60 @@
+# Copyright 2013 Jack David Baucum
+#
+# This file is part of Orthosie.
+#
+# Orthosie is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Orthosie is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Orthosie. If not, see .
+
+from rest_framework import viewsets, generics
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+from rest_framework.reverse import reverse
+from register.models import Shift, Transaction, LineItem
+from register.serializers import ShiftSerializer, TransactionSerializer
+from register.serializers import LineItemSerializer
+
+
+@api_view(['GET'])
+def api_root(request, format=None):
+ """
+ The entry endpoint of our API.
+ """
+ return Response({
+ 'shift': reverse('shift-list', request=request),
+ 'transaction': reverse('transaction-list', request=request),
+ 'lineitem': reverse('lineitem-list', request=request),
+ })
+
+
+class ShiftViewSet(viewsets.ModelViewSet):
+ """
+ API endpoint that allows shifts to be viewed or edited.
+ """
+ queryset = Shift.objects.all()
+ serializer_class = ShiftSerializer
+
+
+class TransactionViewSet(viewsets.ModelViewSet):
+ """
+ API endpoint that allows transactions to be viewed or edited.
+ """
+ queryset = Transaction.objects.all()
+ serializer_class = TransactionSerializer
+
+
+class LineItemViewSet(viewsets.ModelViewSet):
+ """
+ API endpoint that allows line items to be viewed or edited.
+ """
+ queryset = LineItem.objects.all()
+ serializer_class = LineItemSerializer
diff --git a/register/models.py b/register/models.py
index 23224b4..190bbb5 100644
--- a/register/models.py
+++ b/register/models.py
@@ -169,7 +169,7 @@ class LineItem(models.Model):
def __unicode__(self):
return str(self.scale) + ' x ' + self.description + ' ' +\
- self.description
+ self.description
def total(self):
return self.price * self.quantity
diff --git a/orthosie/serializers.py b/register/serializers.py
similarity index 59%
rename from orthosie/serializers.py
rename to register/serializers.py
index 203d1b2..99c081b 100644
--- a/orthosie/serializers.py
+++ b/register/serializers.py
@@ -15,53 +15,20 @@
# You should have received a copy of the GNU General Public License
# along with Orthosie. If not, see .
-from inventory.models import Item, Vendor
from register.models import Shift, Transaction, LineItem
from rest_framework import serializers
-class ItemSerializer(serializers.HyperlinkedModelSerializer):
- class Meta:
- model = Item
- fields = (
- 'url',
- 'upc',
- 'name',
- 'price',
- 'scalable',
- 'taxable',
- 'vendor'
- )
-
-
-class VendorSerializer(serializers.HyperlinkedModelSerializer):
- class Meta:
- model = Vendor
- fields = ('url', 'name')
-
-
class ShiftSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Shift
- fields = ('url', 'begin_date', 'finish_date')
class TransactionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Transaction
- fields = ('url', 'shift', 'begin_date', 'finish_date', 'status')
class LineItemSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = LineItem
- fields = (
- 'url',
- 'transaction',
- 'upc',
- 'quantity',
- 'scale',
- 'description',
- 'price',
- 'item'
- )
\ No newline at end of file