本文整理汇总了Python中djangorestframework.views.ListOrCreateModelView类的典型用法代码示例。如果您正苦于以下问题:Python ListOrCreateModelView类的具体用法?Python ListOrCreateModelView怎么用?Python ListOrCreateModelView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ListOrCreateModelView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fifo_behaviour
def test_fifo_behaviour(self):
'''It's fine that the Blogposts are capped off at MAX_POSTS. But we want to make sure we see FIFO behaviour.'''
for post in range(15):
form_data = {'title': '%s' % post, 'content': 'This is the content of post #%s' % post}
request = self.factory.post('/blog-post', data=form_data)
view = ListOrCreateModelView.as_view(resource=urls.BlogPostResource)
view(request)
request = self.factory.get('/blog-post')
view = ListOrCreateModelView.as_view(resource=urls.BlogPostResource)
response = view(request)
response_posts = json.loads(response.content)
response_titles = [d['title'] for d in response_posts]
response_titles.reverse()
self.assertEquals(response_titles, ['%s' % i for i in range(models.MAX_POSTS - 5, models.MAX_POSTS + 5)])
示例2: get_colors_json
def get_colors_json():
"""
This is a surprising kludge to get the json from a
DRF resource, outside of a true request/response context
for a simple resource - most easily mocked by doing list(queryset.values(fields))
"""
resource_view = ListOrCreateModelView(resource=ColorResource)
dummy_request = HttpRequest()
response_obj = resource_view.get(dummy_request)
response = Response(status.HTTP_200_OK, response_obj)
jsonr = JSONRenderer(resource_view)
filtered_content = resource_view.filter_response(response_obj)
# json_string = jsonr.render(filtered_content)
return filtered_content
示例3: test_blogposts_not_exceed_MAX_POSTS
def test_blogposts_not_exceed_MAX_POSTS(self):
'''Posting blog-posts should not result in more than MAX_POSTS items stored.'''
for post in range(models.MAX_POSTS + 5):
form_data = {'title': 'This is post #%s' % post, 'content': 'This is the content of post #%s' % post}
request = self.factory.post('/blog-post', data=form_data)
view = ListOrCreateModelView.as_view(resource=urls.BlogPostResource)
view(request)
self.assertEquals(len(models.BlogPost.objects.all()),models.MAX_POSTS)
示例4: post
def post(self, request):
try:
obj = self.resource.model.objects.filter(
filename=request.POST.__getitem__('filename'),
revision=request.POST.__getitem__('revision'))
if obj.count() != 0:
return Response(status.HTTP_406_NOT_ACCEPTABLE,
headers={'Reason': 'Duplicate entry'})
except:
pass
return ListOrCreateModelView.post(self, request)
示例5: add_narcissus_urls
def add_narcissus_urls(urls):
urls += patterns('',
url(r'^dashboard/', include('narcissus.dashboard.urls')),
url(r'^api/user/(?P<pk>[^/]+)/$', InstanceModelView.as_view(
resource=UserResource, permissions=(SameUserOrReadOnly,),
), name='narcissus-user-detail'),
)
for name, posttype in posttypes.items():
urls += patterns('',
url(r'^api/%s/$' % name,
ListOrCreateModelView.as_view(
resource=posttype.resource,
permissions=(permissions.IsUserOrIsAnonReadOnly,),
),
name='narcissus-api-%s' % name),
url(r'^api/%s/(?P<pk>[^/]+)/$' % name,
InstanceModelView.as_view(
resource=posttype.resource,
permissions=(SameUserOrReadOnly,),
),
name='narcissus-api-%s-detail' % name),
)
return urls
示例6: BackupTaskResource
from scheduler.views import Todo
from views import *
class BackupTaskResource(ModelResource):
model = BackupTask
class BackupsTodo(Todo):
queryset = BackupTask.objects.all()
class TSMBackupsTodo(BackupsTodo):
queryset = TSMBackupTask.objects.all()
class R1BackupsTodo(BackupsTodo):
queryset = R1BackupTask.objects.all()
urlpatterns = patterns('',
url(r'^$', ListOrCreateModelView.as_view(resource=BackupTaskResource)),
url(r'^tsm/hosts/$', TSMHostsView.as_view(), name='tsm-hosts'),
url(r'^r1/todo/$', R1BackupsTodo.as_view(), name='r1-backups-todo'),
url(r'^todo/$', BackupsTodo.as_view(), name='backups-todo'),
url(r'^backupfilechecker/$', BackupFileCheckerView.as_view(), name='backup-file-checker'),
url(r'^filesToCompress$', FilesToCompressView.as_view(), name='backup-files-to-compress'),
url(r'^filesToDelete$', FilesToDeleteView.as_view(), name='backup-files-to-delete'),
url(r'^addBackupFile$', add_backup_file, name="addBackupFile"),
url(r'^BackupFileInfo$', GetBackupFileInfo.as_view(), name="BackupFileInfo"),
url(r'^addWindowsBackupFile$', add_backup_file, { 'windows':True }, name="addWindowsBackupFile"),
url(r'^registerFileFromChecker$', register_file_from_checker, name="register_file_from_checker"),
url(r'^addCompressedBackupFile$', add_compressed_backup_file, name="addCompressedBackupFile"),
url(r'^(?P<pk>[^/]+)/$', InstanceModelView.as_view(resource=BackupTaskResource)),
)
示例7: patterns
from django.conf.urls.defaults import patterns, include, url
from djangorestframework.views import InstanceModelView, ListOrCreateModelView
from resources import CardResource
urlpatterns = patterns('',
url(r'^cards/?$', ListOrCreateModelView.as_view(resource=CardResource), name='card_list_or_create_model_view'),
url(r'^cards/(?P<id>\d+)/?$', InstanceModelView.as_view(resource=CardResource), name='card_instance_model_view'),
)
示例8: patterns
try:
from django.conf.urls import patterns, url
except ImportError:
# Django < 1.4
from django.conf.urls.defaults import patterns, url
from djangorestframework.views import ListOrCreateModelView, InstanceModelView
from blogpost.resources import BlogPostResource, CommentResource
urlpatterns = patterns('',
url(r'^$', ListOrCreateModelView.as_view(resource=BlogPostResource), name='blog-posts-root'),
url(r'^(?P<key>[^/]+)/$', InstanceModelView.as_view(resource=BlogPostResource), name='blog-post'),
url(r'^(?P<blogpost>[^/]+)/comments/$', ListOrCreateModelView.as_view(resource=CommentResource), name='comments'),
url(r'^(?P<blogpost>[^/]+)/comments/(?P<id>[^/]+)/$', InstanceModelView.as_view(resource=CommentResource)),
)
示例9: patterns
from django.conf.urls.defaults import patterns, url
from djangorestframework.views import ListOrCreateModelView, InstanceModelView
from modelresourceexample.resources import MyModelResource
urlpatterns = patterns('',
url(r'^$', ListOrCreateModelView.as_view(resource=MyModelResource), name='model-resource-root'),
url(r'^(?P<pk>[0-9]+)/$', InstanceModelView.as_view(resource=MyModelResource)),
)
示例10: HackResource
from django.shortcuts import redirect
from bounty.board import models
from djangorestframework.resources import ModelResource
from djangorestframework.views import ListOrCreateModelView, InstanceModelView
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
# REST resources
class HackResource(ModelResource):
model = models.Hack
urlpatterns = patterns('bounty.board.views',
url(r'^$', 'home.home'),
#url(r'^$', redirect('home')),
# RESTful API
url(r'^api/hacks$', ListOrCreateModelView.as_view(resource=HackResource)),
# for Meetup API
url(r'', include('social_auth.urls')),
# standard django admin
url(r'^admin/', include(admin.site.urls)),
# debugging - remove me
url(r'^accounts/profile', 'debug.dump_user_info'),
)
示例11: patterns
from django.conf.urls.defaults import patterns, url, include
from djangorestframework.views import ListOrCreateModelView, InstanceModelView
from groupes.api import EleveResource, ImportationResource, ImpGroupeResource, \
ImpGroupeDetailResource
urlpatterns = patterns( '',
# Administration
url( r'^admin/', include( 'uiadmin.urls' ) ),
url( r'^groupes/', include( 'groupes.urls' ) ),
url( r'^periodes/', include( 'periode.urls' ) ),
url( r'^evaluations/', include( 'evaluations.urls' ) ),
# API
url( r'^api/v4/eleves/$', ListOrCreateModelView.as_view( resource=EleveResource ) ),
url( r'^api/v4/eleves/(?P<pk>[^/]+)/$', InstanceModelView.as_view( resource=EleveResource ) ),
url( r'^api/v4/importations/$', ListOrCreateModelView.as_view( resource=ImportationResource ) ),
url( r'^api/v4/importations/(?P<pk>[^/]+)/$', InstanceModelView.as_view( resource=ImportationResource ) ),
url( r'^api/v4/importations/(?P<importation>[^/]+)/groupes/$', ListOrCreateModelView.as_view( resource=ImpGroupeResource ) ),
url( r'^api/v4/importations/(?P<importation>[^/]+)/groupes/(?P<pk>[^/]+)/$', InstanceModelView.as_view( resource=ImpGroupeResource ) ),
url( r'^api/v4/importations/(?P<importation>[^/]+)/groupes/(?P<pk>[^/]+)/eleves/$', InstanceModelView.as_view( resource=ImpGroupeDetailResource ), name='importation-groupes-details' ),
)
示例12: url
url(r'^dump/$', DumpRoot.as_view(
permissions=(permissions.IsUserOrIsAnonReadOnly,)),
name='dump-rule'),
url(r'^apply/$', ApplyRoot.as_view(
permissions=(permissions.IsUserOrIsAnonReadOnly,)),
name='apply-rule'),
url(r'^description/(?P<pk>[0-9]+)/$', \
InstanceModelView.as_view(
resource=DescriptionResource,
permissions=(permissions.IsUserOrIsAnonReadOnly,)),
),
url(r'^description/$', \
ListOrCreateModelView.as_view(
resource=DescriptionResource,
permissions=(permissions.IsUserOrIsAnonReadOnly,)),
),
url(r'^token/(?P<pk>[0-9]+)/$', \
InstanceModelView.as_view(
resource=TokenResource,
permissions=(permissions.IsUserOrIsAnonReadOnly,)),
),
url(r'^token/$', \
ListOrCreateModelView.as_view(
resource=TokenResource,
permissions=(permissions.IsUserOrIsAnonReadOnly,)),
),
url(r'^regularisationtype/(?P<pk>[0-9]+)/$', \
示例13: patterns
foo = models.BooleanField()
bar = models.IntegerField(help_text='Must be an integer.')
baz = models.CharField(max_length=32, help_text='Free text. Max length 32 chars.')
model = MockResourceModel
fields = ('foo', 'bar', 'baz')
urlpatterns = patterns('djangorestframework.utils.staticviews',
url(r'^robots.txt$', 'deny_robots'),
url(r'^favicon.ico$', 'favicon'),
url(r'^accounts/login$', 'api_login'),
url(r'^accounts/logout$', 'api_logout'),
url(r'^mock/$', MockView.as_view()),
url(r'^mock/final/$', MockViewFinal.as_view()),
url(r'^resourcemock/$', ResourceMockView.as_view()),
url(r'^model/$', ListOrCreateModelView.as_view(resource=MockResource)),
url(r'^model/(?P<pk>[^/]+)/$', InstanceModelView.as_view(resource=MockResource)),
)
class BaseViewTests(TestCase):
"""Test the base view class of djangorestframework"""
urls = 'djangorestframework.tests.views'
def test_view_call_final(self):
response = self.client.options('/mock/final/')
self.assertEqual(response['Content-Type'].split(';')[0], "application/json")
parser = JSONParser(None)
(data, files) = parser.parse(StringIO(response.content))
self.assertEqual(data['test'], 'passed')
def test_options_method_simple_view(self):
示例14: patterns
from lizard_fewsnorm.api.views import ParameterView
from lizard_fewsnorm.api.views import RootView
from lizard_fewsnorm.api.views import TimeserieSelectionView
admin.autodiscover()
NAME_PREFIX = 'lizard_fewsnorm_api_'
urlpatterns = patterns(
'',
url(r'^$',
RootView.as_view(),
name=NAME_PREFIX + 'root'),
url(r'^source/$',
ListOrCreateModelView.as_view(resource=FewsNormSourceResource),
name=NAME_PREFIX + 'source_list'),
url(r'^source/(?P<slug>.*)/$',
InstanceModelView.as_view(resource=FewsNormSourceResource),
name=NAME_PREFIX + 'source_detail'),
url(r'^location/$',
LocationView.as_view(),
name=NAME_PREFIX + 'location'),
url(r'^identifier/$',
IdentifierView.as_view(),
name=NAME_PREFIX + 'identifier'),
url(r'^location/(?P<ident>.*)/$',
InstanceModelView.as_view(resource=LocationResource),
name=NAME_PREFIX + 'location_detail'),
url(r'^parameter/$',
ParameterView.as_view(),
示例15: patterns
from django.conf.urls import patterns, include, url
from django.views.generic.base import View
from testapp import views
from django.views import generic
from djangorestframework.views import ListOrCreateModelView
from testapp.api import PersonResource
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', generic.RedirectView.as_view(url='people'), name='home' ),
url(r'^person/add$', views.PersonCreate.as_view(), name='person_add'),
url(r'^people$', views.PersonList.as_view(), name='person_list'),
# RESTful Api
url(r'^restframework', include('djangorestframework.urls', namespace='djangorestframework')),
url(r'api/person/', ListOrCreateModelView.as_view(resource=PersonResource))
)