Improves edit.py and its forms (#648)

* Improves edit.py and its forms

* Adds tests
This commit is contained in:
Nikita Sobolev
2021-06-16 11:25:57 +03:00
committed by GitHub
parent acfe0ce820
commit eb702384a8
5 changed files with 55 additions and 18 deletions

View File

@@ -10,6 +10,8 @@
"""Ensure that form can have type AuthenticationForm."""
form.get_user()
return HttpResponseRedirect(self.get_success_url())
- case: dispatch_http_response
main: |
from django.http import HttpResponse
@@ -19,6 +21,8 @@
def dispatch(self, request, *args, **kwargs) -> HttpResponse:
response: HttpResponse
return response
- case: dispatch_streaming_http_response
main: |
from django.http import StreamingHttpResponse
@@ -28,3 +32,32 @@
def dispatch(self, request, *args, **kwargs) -> StreamingHttpResponse:
response: StreamingHttpResponse
return response
- case: generic_form_views
main: |
from django.views.generic.edit import CreateView, UpdateView
from django import forms
from myapp.models import Article
class ArticleModelForm(forms.ModelForm[Article]):
class Meta:
model = Article
class MyCreateView(CreateView[Article, ArticleModelForm]):
def some(self) -> None:
reveal_type(self.get_form_class()) # N: Revealed type is "Type[main.ArticleModelForm*]"
class MyUpdateView(UpdateView[Article, ArticleModelForm]):
def some(self) -> None:
reveal_type(self.get_form_class()) # N: Revealed type is "Type[main.ArticleModelForm*]"
installed_apps:
- myapp
files:
- path: myapp/__init__.py
- path: myapp/models.py
content: |
from django.db import models
class Article(models.Model):
pass