File: func_noerror_classviews.py

package info (click to toggle)
pylint-django 2.0.13-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 660 kB
  • sloc: python: 1,807; sh: 13; makefile: 5
file content (50 lines) | stat: -rw-r--r-- 1,327 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Checks that Pylint does not complain about attributes and methods
when using Class-based Views
"""
#  pylint: disable=missing-docstring

from django.db import models
from django.http import JsonResponse
from django.views.generic import DetailView
from django.views.generic import TemplateView
from django.views.generic import View
from django.views.generic.edit import CreateView


class BoringView(TemplateView):
    # ensure that args, kwargs and request are not thrown up as errors
    def get_context_data(self, **kwargs):
        return {
            'request': self.request,
            'args': self.args,
            'kwargs': self.kwargs
        }


class JsonView(View):
    def post(self, request):
        # do something with objects but don't use
        # self or request
        return JsonResponse({'rc': 0, 'response': 'ok'})


class Book(models.Model):
    name = models.CharField(max_length=100)
    good = models.BooleanField(default=False)


class GetBook(DetailView):
    model = Book
    template_name = 'books/get.html'
    http_method_names = ['get']


class CreateBook(CreateView):
    model = Book
    template_name = 'books/new.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['page_title'] = 'New book'
        return context