當前位置: 首頁>>代碼示例>>Python>>正文


Python views.ListOrCreateModelView類代碼示例

本文整理匯總了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)])
開發者ID:vitormazzi,項目名稱:django-rest-framework,代碼行數:14,代碼來源:tests.py

示例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
開發者ID:aliounedia,項目名稱:django-live,代碼行數:15,代碼來源:utils.py

示例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)
開發者ID:adieu,項目名稱:django-rest-framework,代碼行數:8,代碼來源:tests.py

示例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)
開發者ID:sfpiano,項目名稱:rbclone,代碼行數:11,代碼來源:urls.py

示例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
開發者ID:biggers,項目名稱:django-narcissus,代碼行數:23,代碼來源:urls.py

示例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)),
)
開發者ID:AgarFu,項目名稱:arritranco,代碼行數:30,代碼來源:urls.py

示例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'),
)
開發者ID:vsirisanthana,項目名稱:adios-agile,代碼行數:8,代碼來源:urls.py

示例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)),
)
開發者ID:vitormazzi,項目名稱:django-rest-framework,代碼行數:16,代碼來源:urls.py

示例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)),
)
開發者ID:Audish,項目名稱:django-rest-framework,代碼行數:8,代碼來源:urls.py

示例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'),
)
開發者ID:marmida,項目名稱:Bounty-Board,代碼行數:30,代碼來源:urls.py

示例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' ),

    
 )
開發者ID:jmbarbier,項目名稱:eskollz.archive,代碼行數:29,代碼來源:urls.py

示例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]+)/$', \
開發者ID:DigitalResearchCentre,項目名稱:shenpan-server,代碼行數:31,代碼來源:urls.py

示例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):
開發者ID:Audish,項目名稱:django-rest-framework,代碼行數:31,代碼來源:views.py

示例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(),
開發者ID:lizardsystem,項目名稱:lizard-fewsnorm,代碼行數:31,代碼來源:urls.py

示例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))
    
)
開發者ID:steven-king,項目名稱:django-bootstrap-starter,代碼行數:22,代碼來源:urls.py


注:本文中的djangorestframework.views.ListOrCreateModelView類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。