Merge branch 'master' into pyup-update-django-celery-beat-2.1.0-to-2.2.0

This commit is contained in:
Bruno Alla 2021-01-24 15:22:36 +00:00
commit 24ebd22c02
10 changed files with 47 additions and 18 deletions

View File

@ -1057,5 +1057,10 @@
"name": "Yotam Tal",
"github_login": "yotamtal",
"twitter_username": ""
},
{
"name": "John",
"github_login": "thorrak",
"twitter_username": ""
}
]

View File

@ -3,6 +3,10 @@ All enhancements and patches to Cookiecutter Django will be documented in this f
<!-- GENERATOR_PLACEHOLDER -->
## [2021-01-22]
### Changed
- Use self.request.user instead of second query ([#3012](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3012))
## [2021-01-14]
### Updated
- Update tox to 3.21.1 ([#3006](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3006))

View File

@ -866,6 +866,13 @@ Listed in alphabetical order.
</td>
<td>afrowave</td>
</tr>
<tr>
<td>John</td>
<td>
<a href="https://github.com/thorrak">thorrak</a>
</td>
<td></td>
</tr>
<tr>
<td>John Cass</td>
<td>

View File

@ -11,7 +11,7 @@ flake8-isort==4.0.0
# Testing
# ------------------------------------------------------------------------------
tox==3.21.1
tox==3.21.2
pytest==5.4.3 # pyup: <6 # https://github.com/hackebrot/pytest-cookies/issues/51
pytest-cookies==0.5.1
pytest-instafail==0.4.2

View File

@ -13,7 +13,7 @@ watchgod==0.6 # https://github.com/samuelcolvin/watchgod
# Testing
# ------------------------------------------------------------------------------
mypy==0.790 # https://github.com/python/mypy
mypy==0.800 # https://github.com/python/mypy
django-stubs==1.7.0 # https://github.com/typeddjango/django-stubs
pytest==6.2.1 # https://github.com/pytest-dev/pytest
pytest-sugar==0.9.4 # https://github.com/Frozenball/pytest-sugar
@ -37,7 +37,7 @@ pre-commit==2.9.3 # https://github.com/pre-commit/pre-commit
# Django
# ------------------------------------------------------------------------------
factory-boy==3.1.0 # https://github.com/FactoryBoy/factory_boy
factory-boy==3.2.0 # https://github.com/FactoryBoy/factory_boy
django-debug-toolbar==3.2 # https://github.com/jazzband/django-debug-toolbar
django-extensions==3.1.0 # https://github.com/django-extensions/django-extensions

View File

@ -53,18 +53,6 @@ class Migration(migrations.Migration):
verbose_name="username",
),
),
(
"first_name",
models.CharField(
blank=True, max_length=30, verbose_name="first name"
),
),
(
"last_name",
models.CharField(
blank=True, max_length=150, verbose_name="last name"
),
),
(
"email",
models.EmailField(

View File

@ -9,6 +9,8 @@ class User(AbstractUser):
#: First and last name do not cover name patterns around the globe
name = CharField(_("Name of User"), blank=True, max_length=255)
first_name = None # type: ignore
last_name = None # type: ignore
def get_absolute_url(self):
"""Get url for user's detail view.

View File

@ -23,7 +23,7 @@ class UserFactory(DjangoModelFactory):
digits=True,
upper_case=True,
lower_case=True,
).generate(params={"locale": None})
).evaluate(None, None, extra={"locale": None})
)
self.set_password(password)

View File

@ -1,8 +1,12 @@
import pytest
from django.contrib import messages
from django.contrib.auth.models import AnonymousUser
from django.contrib.messages.middleware import MessageMiddleware
from django.contrib.sessions.middleware import SessionMiddleware
from django.http.response import Http404
from django.test import RequestFactory
from {{ cookiecutter.project_slug }}.users.forms import UserChangeForm
from {{ cookiecutter.project_slug }}.users.models import User
from {{ cookiecutter.project_slug }}.users.tests.factories import UserFactory
from {{ cookiecutter.project_slug }}.users.views import (
@ -41,6 +45,25 @@ class TestUserUpdateView:
assert view.get_object() == user
def test_form_valid(self, user: User, rf: RequestFactory):
view = UserUpdateView()
request = rf.get("/fake-url/")
# Add the session/message middleware to the request
SessionMiddleware().process_request(request)
MessageMiddleware().process_request(request)
request.user = user
view.request = request
# Initialize the form
form = UserChangeForm()
form.cleaned_data = []
view.form_valid(form)
messages_sent = [m.message for m in messages.get_messages(request)]
assert messages_sent == ["Information successfully updated"]
class TestUserRedirectView:
def test_get_redirect_url(self, user: User, rf: RequestFactory):

View File

@ -27,11 +27,11 @@ class UserUpdateView(LoginRequiredMixin, UpdateView):
return reverse("users:detail", kwargs={"username": self.request.user.username})
def get_object(self):
return User.objects.get(username=self.request.user.username)
return self.request.user
def form_valid(self, form):
messages.add_message(
self.request, messages.INFO, _("Infos successfully updated")
self.request, messages.INFO, _("Information successfully updated")
)
return super().form_valid(form)