From 8cb7d5f00a879b329f4578ecd3558715e5216904 Mon Sep 17 00:00:00 2001 From: Paul Schilling Date: Tue, 28 Nov 2023 16:47:18 +0100 Subject: [PATCH] [#1898] Design profile page for businesses --- .../migrations/0069_auto_20231204_1159.py | 20 ++++ src/open_inwoner/accounts/models.py | 15 +-- src/open_inwoner/accounts/tests/factories.py | 8 ++ .../accounts/tests/test_profile_views.py | 38 ++++++- .../templates/pages/profile/me.html | 99 +++++++++++-------- 5 files changed, 134 insertions(+), 46 deletions(-) create mode 100644 src/open_inwoner/accounts/migrations/0069_auto_20231204_1159.py diff --git a/src/open_inwoner/accounts/migrations/0069_auto_20231204_1159.py b/src/open_inwoner/accounts/migrations/0069_auto_20231204_1159.py new file mode 100644 index 0000000000..1ec16cfd5a --- /dev/null +++ b/src/open_inwoner/accounts/migrations/0069_auto_20231204_1159.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.20 on 2023-12-04 10:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("accounts", "0068_relax_email_constraint_for_eherkenning"), + ] + + operations = [ + migrations.AlterField( + model_name="user", + name="company_name", + field=models.CharField( + blank=True, default="", max_length=250, verbose_name="Company name" + ), + ), + ] diff --git a/src/open_inwoner/accounts/models.py b/src/open_inwoner/accounts/models.py index 2ea5d54f28..f3ccc5184a 100644 --- a/src/open_inwoner/accounts/models.py +++ b/src/open_inwoner/accounts/models.py @@ -131,7 +131,10 @@ class User(AbstractBaseUser, PermissionsMixin): validators=[validate_kvk], ) company_name = models.CharField( - verbose_name=_("Company name"), max_length=250, null=True, blank=True + verbose_name=_("Company name"), + blank=True, + default="", + max_length=250, ) login_type = models.CharField( verbose_name=_("Login type"), @@ -269,12 +272,12 @@ def __init__(self, *args, **kwargs): self._old_bsn = self.bsn def __str__(self): - name = self.get_full_name() + identifier = self.company_name if self.kvk else self.get_full_name() email = self.get_contact_email() - if name and email: - return f"{name} ({email})" + if identifier and email: + return f"{identifier} ({email})" else: - return name or email or str(self.uuid)[:8] + return identifier or email or str(self.uuid)[:8] def clean(self, *args, **kwargs): """Reject non-unique emails, except for users with login_type DigiD""" @@ -350,7 +353,7 @@ def get_age(self): def get_address(self): if self.street: - return f"{self.street} {self.housenumber}, {self.city}" + return f"{self.street} {self.housenumber}, {self.postcode} {self.city}" return "" def get_new_messages_total(self) -> int: diff --git a/src/open_inwoner/accounts/tests/factories.py b/src/open_inwoner/accounts/tests/factories.py index 087d1fa946..e53f5e7332 100644 --- a/src/open_inwoner/accounts/tests/factories.py +++ b/src/open_inwoner/accounts/tests/factories.py @@ -40,6 +40,14 @@ class eHerkenningUserFactory(UserFactory): is_prepopulated = True +class KvKUserFactory(UserFactory): + first_name = "" + infix = "" + last_name = "" + login_type = LoginTypeChoices.eherkenning + kvk = "12345678" + + class TokenFactory(factory.django.DjangoModelFactory): class Meta: model = "authtoken.Token" diff --git a/src/open_inwoner/accounts/tests/test_profile_views.py b/src/open_inwoner/accounts/tests/test_profile_views.py index 5d6c4d09ae..a2e28f2e6a 100644 --- a/src/open_inwoner/accounts/tests/test_profile_views.py +++ b/src/open_inwoner/accounts/tests/test_profile_views.py @@ -9,6 +9,7 @@ import requests_mock from cms import api from django_webtest import WebTest +from pyquery import PyQuery as PQ from timeline_logger.models import TimelineLog from webtest import Upload @@ -28,7 +29,13 @@ from ..choices import ContactTypeChoices, LoginTypeChoices from ..forms import BrpUserForm, UserForm from ..models import User -from .factories import ActionFactory, DigidUserFactory, DocumentFactory, UserFactory +from .factories import ( + ActionFactory, + DigidUserFactory, + DocumentFactory, + KvKUserFactory, + UserFactory, +) @override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls") @@ -69,6 +76,9 @@ def test_user_information_profile_page(self): self.assertContains(response, self.user.housenumber) self.assertContains(response, self.user.city) + # check business profile section not displayed + self.assertNotContains(response, "Bedrijfsgegevens") + def test_get_empty_profile_page(self): response = self.app.get(self.url, user=self.user) @@ -109,6 +119,9 @@ def test_mydata_shown_with_digid_and_brp(self): response = self.app.get(self.url, user=user) self.assertContains(response, _("My details")) + # check business profile section not displayed + self.assertNotContains(response, "Bedrijfsgegevens") + def test_mydata_not_shown_with_digid_and_no_brp(self): user = UserFactory( bsn="999993847", @@ -124,6 +137,29 @@ def test_mydata_not_shown_without_digid(self): response = self.app.get(self.url, user=self.user) self.assertNotContains(response, _("My details")) + def test_info_kvk_user(self): + user = KvKUserFactory( + company_name="Makers and Shakers", + street="Fantasiestraat", + housenumber="42", + postcode="1234 XY", + city="The good place", + ) + response = self.app.get(self.url, user=user) + + self.assertContains(response, "Makers and Shakers") + self.assertContains(response, "Fantasiestraat 42") + self.assertContains(response, "1234 XY The good place") + + doc = PQ(response.content) + + business_section = doc.find("#business-overview")[0] + self.assertEqual(business_section.text, "Bedrijfsgegevens") + + # check personal overview section not displayed + personal_section = doc.find("#personal-overview") + self.assertEqual(personal_section, []) + def test_active_user_notifications_are_shown(self): user = UserFactory( bsn="999993847", diff --git a/src/open_inwoner/templates/pages/profile/me.html b/src/open_inwoner/templates/pages/profile/me.html index 71d791117d..0283a16e76 100644 --- a/src/open_inwoner/templates/pages/profile/me.html +++ b/src/open_inwoner/templates/pages/profile/me.html @@ -10,49 +10,70 @@ {% with user=request.user %}
-

{% trans "Welkom" %}, {{ user.first_name }}

- {%trans "voor het laatst ingelogd op" %}: {{ user.last_login|date:"d-m-Y" }} om {{ user.last_login|date:"H:i" }} uur +

{% trans "Welkom" %}{% if not user.is_digid_user %}, {{ user.first_name }}{% endif %}

+ {%trans "voor het laatst ingelogd op" %}: {{ user.last_login|date:"d F Y" }} om {{ user.last_login|date:"H:i" }} uur
-{# Personal information #} -
-
-

{% trans "Persoonlijke gegevens" %} -
- {% button href="profile:edit" text=_("Bewerken") icon="edit" transparent=True %} - {% if user.is_digid_user_with_brp and view.config.my_data %} - {% button href="profile:data" text=_("My details") icon="info" transparent=True icon_outlined=True %} - {% elif not user.is_digid_user %} - {% button href="password_change" text=_("Password") icon="key" transparent=True %} - {% endif %} -
-

-
-
-
{% trans "Voornaam" %}
-
{{ user.infix}} {{ user.first_name }}
-
-
-
{% trans "Achternaam" %}
-
{{ user.last_name }}
-
-
-
{% trans "Geboortedatum" %}
-
{{ user.birthday|date:"d.m.Y" }}
-
-
-
{% trans "Adres" %}
-
{{ user.street }} {{ user.housenumber }}
{{user.postcode}} {{ user.city }}
-
-
-
{% trans "E-mail adres" %}
-
{{ user.get_contact_email }}
+{% if user.kvk %} + {# Business information #} +
+
+

{% trans "Bedrijfsgegevens" %}

+
+
+
{% trans "Handelsnaam" %}
+
{{ user.company_name }}
+
+
+
{% trans "KvK nummer" %}
+
{{ user.kvk }}
+
+
+
{% trans "Zakelijk adres" %}
+
{{ user.street }} {{ user.housenumber }}
{{user.postcode}} {{ user.city }}
+
-
-
{% trans "Telefoonnummer" %}
-
{{ user.phonenumber }}
+{% else %} + {# Personal information #} +
+
+

{% trans "Persoonlijke gegevens" %} +
+ {% button href="profile:edit" text=_("Bewerken") icon="edit" transparent=True %} + {% if user.is_digid_user_with_brp and view.config.my_data %} + {% button href="profile:data" text=_("My details") icon="info" transparent=True icon_outlined=True %} + {% elif not user.is_digid_user %} + {% button href="password_change" text=_("Password") icon="key" transparent=True %} + {% endif %} +
+

+
+
+
{% trans "Voornaam" %}
+
{{ user.infix}} {{ user.first_name }}
+
+
+
{% trans "Achternaam" %}
+
{{ user.last_name }}
+
+
+
{% trans "Geboortedatum" %}
+
{{ user.birthday|date:"d F Y" }}
+
+
+
{% trans "Adres" %}
+
{{ user.street }} {{ user.housenumber }}
{{user.postcode}} {{ user.city }}
+
+
+
{% trans "E-mail adres" %}
+
{{ user.get_contact_email }}
+
+
+
{% trans "Telefoonnummer" %}
+
{{ user.phonenumber }}
+
-
+{% endif %} {# Notifications #}