How to use the djangorestframework.views.InstanceModelView function in djangorestframework

To help you get started, we’ve selected a few djangorestframework examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github boosh / pwlocker / pwlocker / apps / api / views.py View on Github external
"""
        Clear the current user singleton to make sure it doesn't leak
        """
        CurrentUserSingleton.set_user(None)
        return super(ModelMixin, self).final(request, response, *args, **kargs)


class PasswordListView(RestrictPasswordToUserMixin, ListOrCreateModelView):
    """
    List view for Password objects.
    """
    resource = PasswordResource
    permissions = (IsAuthenticated, )


class PasswordInstanceView(RestrictPasswordToUserMixin, InstanceModelView):
    """
    View for individual Password instances
    """
    resource = PasswordResource
    permissions = (IsAuthenticated, )

    def put(self, request, *args, **kwargs):
        """
        Only allow the creating user to modify an instance.
        """
        model = self.resource.model
        query_kwargs = self.get_query_kwargs(request, *args, **kwargs)

        try:
            self.model_instance = self.get_instance(**query_kwargs)
github devilry / devilry-django / src / devilry_nodeadmin / devilry_nodeadmin / rest / nodedetails.py View on Github external
def _serialize_node(self, node):
        return {
            'id': node.id,
            'short_name': node.short_name,
            'long_name': node.long_name
        }

    def childnodes(self, instance):
        return [self._serialize_node(node) for node in instance.child_nodes.all()]




class NodeDetails( InstanceModelView ):
    resource = NodeDetailsResource
    permissions = (IsAuthenticated, IsNodeAdmin,)
    allowed_methods = ('get',)

    def get_instance_data(self, instance):
        return instance
github paulmillr / chieftain / api1 / urls.py View on Github external
(r"^post/$",
        PostListOrCreateView.as_view(resource=PostResource)),
    (r"^post/(?P\w+)/$",
        PostListOrCreateView.as_view(resource=PostResource)),
    (r"^post/(?P\w+)/first/$",
        PostListOrCreateView.as_view(resource=PostResource),
        {"is_op_post": True}),
    (r"^post/(?P\d+)$",
        PostInstanceView.as_view(resource=PostResource)),
    (r"^post/(?P\w+)/(?P\d+)$",
        PostInstanceView.as_view(resource=PostResource)),

    (r"^section/$",
        ListOrCreateModelView.as_view(resource=SectionResource)),
    (r"^section/(?P\d+)$",
        InstanceModelView.as_view(resource=SectionResource)),
    (r"^section/(?P\w+)",
        InstanceModelView.as_view(resource=SectionResource)),

    (r"^sectiongroup/",
        ListOrCreateModelView.as_view(resource=SectionGroupResource)),
    (r"^sectiongroup/(?P\d+)",
        InstanceModelView.as_view(resource=SectionGroupResource)),

    (r"^file/$",
        ListOrCreateModelView.as_view(resource=FileResource)),
    (r"^file/(?P\d+)$",
        FileInstanceView.as_view(resource=FileResource)),
    (r"^file/random_image/(?P\d{1,2})",
        RandomImageView.as_view(resource=FileResource)),

    (r"^filetype/(?P\d+)$",
github devilry / devilry-django / src / devilry_nodeadmin / devilry_nodeadmin / rest / views.py View on Github external
path.append( candidate )
            candidate = candidate.parentnode
            counter += 1

        path.reverse()

        serializer = PathElementResource()

        return serializer.serialize_iter( path )


class PathElementResource( ModelResource ):
    model = Node
    fields = ( 'id', 'short_name', )

class Path( InstanceModelView ):
    resource = PathResource
    permissions = ( IsAuthenticated, )
    allowed_methods = ('get' ,)
github devilry / devilry-django / src / devilry_nodeadmin / devilry_nodeadmin / rest / views.py View on Github external
path.reverse()

        serializer = PathElementResource()

        return serializer.serialize_iter( path )


class IsNodeAdmin( BaseIsAdmin ):
    ID_KWARG = 'pk'

    def check_permission( self, user ):
        nodeid = self.get_id()
        nodeadmin_required( user, nodeid )


class RelatedNodeDetails( InstanceModelView ):
    resource = NodeDetailsResource
    permissions = ( IsAuthenticated, IsNodeAdmin, )
    allowed_methods = ('get' ,)


    def get_instance_data( self, instance ):
        return instance




class PathResource( ModelResource ):
    model = Node
    fields = ( 'id', 'path', )

    def path( self, instance ):
github encode / django-rest-framework / examples / blogpost / urls.py View on Github external
class CommentResource(ModelResource):
    """
    A Comment is associated with a given Blog Post and has a *username* and *comment*, and optionally a *rating*. 
    """
    model = Comment
    fields = ('username', 'comment', 'created', 'rating', 'url', 'blogpost')
    ordering = ('-created',)


urlpatterns = patterns('',
    url(r'^$', ListOrCreateModelView.as_view(resource=BlogPostResource), name='blog-posts-root'),
    url(r'^(?P[^/]+)/$', InstanceModelView.as_view(resource=BlogPostResource)),
    url(r'^(?P[^/]+)/comments/$', ListOrCreateModelView.as_view(resource=CommentResource), name='comments'),
    url(r'^(?P[^/]+)/comments/(?P[^/]+)/$', InstanceModelView.as_view(resource=CommentResource)),
)