How to use the djangorestframework.compat.View 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 haiwen / seahub / api / views.py View on Github external
return api_error(request, '400')

        names =  file_names.split(':')
        names = map(lambda x: unquote(x).decode('utf-8'), names)

        for file_name in names:
            try:
                seafserv_threaded_rpc.del_file(repo_id, parent_dir,
                                               file_name, request.user.username)
            except SearpcError,e:
                return api_error(request, '418', 'SearpcError:' + e.msg)

        return reloaddir_if_neccessary (request, repo_id, parent_dir)


class OpMkdirView(ResponseMixin, View):

    @api_login_required
    def get(self, request, repo_id):
        return api_error(request, '407')

    @api_login_required
    def post(self, request, repo_id):
        resp = check_repo_access_permission(request, get_repo(repo_id))
        if resp:
            return resp

        path = request.GET.get('p')
        if not path or path[0] != '/':
            return api_error(request, '400')

        parent_dir = os.path.dirname(path)
github haiwen / seahub / api / views.py View on Github external
'dir' : f.is_dir,
                 'size' : f.size
                 }
        array.append(sfile)



def api_starred_files(request):
    starred_files = []
    personal_files = get_starred_files(request.user.username, -1)
    append_starred_files (starred_files, personal_files)
    return HttpResponse(json.dumps(starred_files), status=200,
                        content_type=json_content_type)


class StarredFileView(ResponseMixin, View):

    @api_login_required
    def get(self, request):
        return api_starred_files(request)
github haiwen / seahub / api / views.py View on Github external
return HttpResponse(json.dumps('success'), status='200',
                            content_type=json_content_type)

    current_commit = get_commits(repo_id, 0, 1)[0]
    try:
        dir_id = seafserv_threaded_rpc.get_dirid_by_path(current_commit.id,
                                                         parent_dir.encode('utf-8'))
    except SearpcError, e:
        return api_error(request, "411", "SearpcError:" + e.msg)

    if not dir_id:
        return api_error(request, '410')
    return get_dir_entrys_by_id(request, dir_id)


class OpDeleteView(ResponseMixin, View):

    @api_login_required
    def get(self, request, repo_id):
        return api_error(request, '407')

    @api_login_required
    def post(self, request, repo_id):
        resp = check_repo_access_permission(request, get_repo(repo_id))
        if resp:
            return resp

        parent_dir = request.GET.get('p', '/')
        file_names = request.POST.get("file_names")

        if not parent_dir or not file_names:
            return api_error(request, '400')
github encode / django-rest-framework / examples / mixin / urls.py View on Github external
from djangorestframework.compat import View  # Use Django 1.3's django.views.generic.View, or fall back to a clone of that if Django < 1.3
from djangorestframework.mixins import ResponseMixin
from djangorestframework.renderers import DEFAULT_RENDERERS
from djangorestframework.response import Response
from djangorestframework.reverse import reverse

from django.conf.urls.defaults import patterns, url


class ExampleView(ResponseMixin, View):
    """An example view using Django 1.3's class based views.
    Uses djangorestframework's RendererMixin to provide support for multiple output formats."""
    renderers = DEFAULT_RENDERERS

    def get(self, request):
        url = reverse('mixin-view', request)
        response = Response({'description': 'Some example content',
                                  'url': url}, status=200)
        self.response = self.prepare_response(response)
        return self.response


urlpatterns = patterns('',
    url(r'^$', ExampleView.as_view(), name='mixin-view'),
)
github haiwen / seahub / api / views.py View on Github external
return HttpResponse(json.dumps([info]), status=200, content_type=json_content_type)
    else:
        return api_error(request, '408')


class Ping(ResponseMixin, View):

    def get(self, request):
        response = HttpResponse(json.dumps("pong"), status=200, content_type=json_content_type)
        if request.user.is_authenticated():
            response["logined"] = True
        else:
            response["logined"] = False
        return response

class Account(ResponseMixin, View):
    renderers = (JSONRenderer,)

    @api_login_required
    def get(self, request):
        info = {}
        email = request.user.username
        info['email'] = email
        info['usage'] = seafserv_threaded_rpc.get_user_quota_usage(email)
        info['total'] = seafserv_threaded_rpc.get_user_quota(email)
        info['feedback'] = settings.DEFAULT_FROM_EMAIL
        response = Response(200, [info])
        return self.render(response)


class ReposView(ResponseMixin, View):
    renderers = (JSONRenderer,)