profile: add user full name template definition popup (#74507)
This commit is contained in:
parent
92f827d9f6
commit
5956ce4036
|
@ -0,0 +1,26 @@
|
||||||
|
# hobo - portal to configure and deploy applications
|
||||||
|
# Copyright (C) 2015-2023 Entr'ouvert
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU Affero General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from django import forms
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
class EditFullNameTemplateForm(forms.Form):
|
||||||
|
user_full_name_template = forms.CharField(
|
||||||
|
label=_('User full name template (Django)'),
|
||||||
|
widget=forms.Textarea,
|
||||||
|
required=False,
|
||||||
|
)
|
|
@ -9,6 +9,7 @@
|
||||||
{% block appbar %}
|
{% block appbar %}
|
||||||
<h2>{% trans 'User Profile' %}</h2>
|
<h2>{% trans 'User Profile' %}</h2>
|
||||||
<span class="actions">
|
<span class="actions">
|
||||||
|
<a rel="popup" href="{% url 'profile-edit-user-full-name-template' %}">{% trans 'User full name template' %}</a>
|
||||||
<a rel="popup" href="{% url 'profile-add-attribute' %}">{% trans 'New attribute' %}</a>
|
<a rel="popup" href="{% url 'profile-add-attribute' %}">{% trans 'New attribute' %}</a>
|
||||||
</span>
|
</span>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
{% extends "hobo/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
<div id="profile-full-name-template-form">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
</div>
|
||||||
|
{% block buttons %}
|
||||||
|
<div class="buttons">
|
||||||
|
<button class="submit-button">{% trans 'Save' %}</button>
|
||||||
|
<a class="cancel" href="{% url 'profile-home' %}">{% trans 'Cancel' %}</a>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -23,4 +23,9 @@ urlpatterns = [
|
||||||
re_path(r'(?P<name>[\w-]+)/options', views.options, name='profile-attribute-options'),
|
re_path(r'(?P<name>[\w-]+)/options', views.options, name='profile-attribute-options'),
|
||||||
path('reorder', views.reorder, name='profile-reorder'),
|
path('reorder', views.reorder, name='profile-reorder'),
|
||||||
path('add-attribute', views.add_attribute, name='profile-add-attribute'),
|
path('add-attribute', views.add_attribute, name='profile-add-attribute'),
|
||||||
|
path(
|
||||||
|
'edit-user-full-name-template',
|
||||||
|
views.edit_user_full_name_template,
|
||||||
|
name='profile-edit-user-full-name-template',
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -16,10 +16,13 @@
|
||||||
|
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.urls import reverse, reverse_lazy
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.views.generic import CreateView, ListView, RedirectView, UpdateView
|
from django.utils.translation import ugettext as _
|
||||||
|
from django.views.generic import CreateView, ListView, RedirectView, TemplateView, UpdateView
|
||||||
|
|
||||||
from hobo.deploy.signals import notify_agents
|
from hobo.deploy.signals import notify_agents
|
||||||
|
from hobo.environment.forms import VariablesFormMixin
|
||||||
|
|
||||||
|
from .forms import EditFullNameTemplateForm
|
||||||
from .models import AttributeDefinition
|
from .models import AttributeDefinition
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,6 +75,16 @@ class OptionsView(UpdateView):
|
||||||
options = OptionsView.as_view()
|
options = OptionsView.as_view()
|
||||||
|
|
||||||
|
|
||||||
|
class EditFullNameTemplateView(VariablesFormMixin, TemplateView):
|
||||||
|
template_name = 'profile/edit_full_name_template.html'
|
||||||
|
form_class = EditFullNameTemplateForm
|
||||||
|
variables = ['user_full_name_template']
|
||||||
|
success_message = _('User full name template has been updated.')
|
||||||
|
|
||||||
|
|
||||||
|
edit_user_full_name_template = EditFullNameTemplateView.as_view()
|
||||||
|
|
||||||
|
|
||||||
def reorder(request):
|
def reorder(request):
|
||||||
new_order_list = [int(x) for x in request.GET['new-order'].split(',')]
|
new_order_list = [int(x) for x in request.GET['new-order'].split(',')]
|
||||||
for attribute in AttributeDefinition.objects.all():
|
for attribute in AttributeDefinition.objects.all():
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from hobo.environment.models import Authentic
|
from hobo.environment.models import Authentic, Variable
|
||||||
from hobo.environment.utils import get_variable
|
from hobo.environment.utils import get_variable
|
||||||
from hobo.profile import models
|
from hobo.profile import models
|
||||||
from hobo.profile.models import AttributeDefinition
|
from hobo.profile.models import AttributeDefinition
|
||||||
|
@ -79,13 +79,39 @@ def test_add_attribute(logged_app, admin_user, kind):
|
||||||
assert models.AttributeDefinition.objects.filter(kind=kind).filter(name='test').count() == 1
|
assert models.AttributeDefinition.objects.filter(kind=kind).filter(name='test').count() == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_edit_user_full_name_template(logged_app, admin_user, settings):
|
||||||
|
app = logged_app
|
||||||
|
value = '{{ user.first_name }}'
|
||||||
|
assert not Variable.objects.filter(name='user_full_name_template')
|
||||||
|
page = app.get('/profile/edit-user-full-name-template', status=200)
|
||||||
|
page.form['user_full_name_template'] = value
|
||||||
|
page.form.submit()
|
||||||
|
assert Variable.objects.get(name='user_full_name_template').value == value
|
||||||
|
|
||||||
|
value = '{{ user.last_name }} etc.'
|
||||||
|
page = app.get('/profile/edit-user-full-name-template', status=200)
|
||||||
|
page.form['user_full_name_template'] = value
|
||||||
|
page.form.submit()
|
||||||
|
assert Variable.objects.get(name='user_full_name_template').value == value
|
||||||
|
|
||||||
|
page = app.get('/profile/edit-user-full-name-template', status=200)
|
||||||
|
page.form['user_full_name_template'] = 'whatever'
|
||||||
|
page.click('Cancel')
|
||||||
|
assert Variable.objects.get(name='user_full_name_template').value == value
|
||||||
|
|
||||||
|
page = app.get('/profile/edit-user-full-name-template', status=200)
|
||||||
|
page.form['user_full_name_template'] = ''
|
||||||
|
page.form.submit()
|
||||||
|
assert Variable.objects.get(name='user_full_name_template').value == ''
|
||||||
|
|
||||||
|
|
||||||
def test_attribute_kind_not_restricted_at_model_level(db):
|
def test_attribute_kind_not_restricted_at_model_level(db):
|
||||||
assert models.AttributeDefinition.objects.create(label='test', kind='somestring')
|
assert models.AttributeDefinition.objects.create(label='test', kind='somestring')
|
||||||
|
|
||||||
|
|
||||||
def test_profile_home_view(logged_app):
|
def test_profile_home_view(logged_app):
|
||||||
resp = logged_app.get('/profile/', status=200)
|
resp = logged_app.get('/profile/', status=200)
|
||||||
assert [x['href'] for x in resp.html.findAll('a', {'rel': 'popup'})][1:4] == [
|
assert [x['href'] for x in resp.html.findAll('a', {'rel': 'popup'})][2:5] == [
|
||||||
'/profile/title/options',
|
'/profile/title/options',
|
||||||
'/profile/first_name/options',
|
'/profile/first_name/options',
|
||||||
'/profile/last_name/options',
|
'/profile/last_name/options',
|
||||||
|
@ -99,7 +125,7 @@ def test_reorder_view(logged_app):
|
||||||
assert resp.location == '/profile/'
|
assert resp.location == '/profile/'
|
||||||
assert AttributeDefinition.objects.filter(name='last_name')[0].order == 1
|
assert AttributeDefinition.objects.filter(name='last_name')[0].order == 1
|
||||||
resp = resp.follow()
|
resp = resp.follow()
|
||||||
assert [x['href'] for x in resp.html.findAll('a', {'rel': 'popup'})][1:4] == [
|
assert [x['href'] for x in resp.html.findAll('a', {'rel': 'popup'})][2:5] == [
|
||||||
'/profile/last_name/options',
|
'/profile/last_name/options',
|
||||||
'/profile/first_name/options',
|
'/profile/first_name/options',
|
||||||
'/profile/title/options',
|
'/profile/title/options',
|
||||||
|
|
Loading…
Reference in New Issue