Exemplo n.º 1
0
from django.conf.urls.defaults import patterns, url
from django.views.decorators.cache import cache_page
from serene.views import CreatableInstanceModelView, PaginatedListOrCreateModelView

from product.resources import CategoryResource, ProductResource, PriceResource


# TODO: cache_page breaks urlreverse

urlpatterns = patterns('',
    url(r'^categories/?$', PaginatedListOrCreateModelView.as_view(resource=CategoryResource), name='category_list_or_create'),
    url(r'^categories/(?P<id>\d+)/?$', CreatableInstanceModelView.as_view(resource=CategoryResource), name='category_instance'),
    url(r'^products/?$', PaginatedListOrCreateModelView.as_view(resource=ProductResource), name='product_list_or_create'),
    url(r'^products/(?P<id>\d+)/?$', CreatableInstanceModelView.as_view(resource=ProductResource), name='product_instance'),
)
Exemplo n.º 2
0
from django.conf import settings
from django.conf.urls.defaults import patterns, include, url
from django.utils import simplejson
from djangorestframework.tests.testcases import SettingsTestCase

from serene.tests.models import Brand, Product
from serene.tests.resources import BrandResource, ProductResource
from serene.views import CreatableInstanceModelView, PaginatedListOrCreateModelView


urlpatterns = patterns('',
    url(r'^brands/?$', PaginatedListOrCreateModelView.as_view(resource=BrandResource), name='brand_list_or_create'),
    url(r'^brands/(?P<id>\d+)/?$', CreatableInstanceModelView.as_view(resource=BrandResource), name='brand_instance'),
    url(r'^products/?$', PaginatedListOrCreateModelView.as_view(resource=ProductResource), name='product_list_or_create'),
    url(r'^products/(?P<id>\d+)/?$', CreatableInstanceModelView.as_view(resource=ProductResource), name='product_instance'),
)


#class TestInstanceModelView(TestCase):
#
#    def setUp(self):
#        super(TestInstanceModelView, self).setUp()
#
#    def tearDown(self):
#        if hasattr(Brand, 'get_absolute_url'): delattr(Brand, 'get_absolute_url')
#        super(TestInstanceModelView, self).tearDown()
#
#    def test_instance_model_view_without_get_absolute_url(self):
#        self.nike = Brand.objects.create(name='Nike')
#
#        r = self.client.get('/brands/%s' % self.nike.id)