2015-05-07 14:37:00 +02:00
|
|
|
# hobo - portal to configure and deploy applications
|
|
|
|
# Copyright (C) 2015 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.shortcuts import redirect
|
2020-05-07 20:01:20 +02:00
|
|
|
from django.urls import reverse, reverse_lazy
|
2023-03-29 12:10:39 +02:00
|
|
|
from django.utils.translation import gettext as _
|
2023-02-16 16:58:45 +01:00
|
|
|
from django.views.generic import CreateView, ListView, RedirectView, TemplateView, UpdateView
|
2015-05-07 14:37:00 +02:00
|
|
|
|
|
|
|
from hobo.deploy.signals import notify_agents
|
2023-02-16 16:58:45 +01:00
|
|
|
from hobo.environment.forms import VariablesFormMixin
|
2015-05-07 14:37:00 +02:00
|
|
|
|
2023-02-16 16:58:45 +01:00
|
|
|
from .forms import EditFullNameTemplateForm
|
2015-05-07 14:37:00 +02:00
|
|
|
from .models import AttributeDefinition
|
|
|
|
|
|
|
|
|
|
|
|
class HomeView(ListView):
|
|
|
|
model = AttributeDefinition
|
|
|
|
|
2021-05-14 18:39:27 +02:00
|
|
|
|
2015-05-07 14:37:00 +02:00
|
|
|
home = HomeView.as_view()
|
|
|
|
|
|
|
|
|
2016-09-20 08:58:07 +02:00
|
|
|
class AddAttributeView(CreateView):
|
|
|
|
model = AttributeDefinition
|
|
|
|
fields = [
|
|
|
|
'label',
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
'required',
|
2021-07-27 16:37:16 +02:00
|
|
|
'required_on_login',
|
2016-09-20 08:58:07 +02:00
|
|
|
'asked_on_registration',
|
2019-01-01 13:22:54 +01:00
|
|
|
'user_editable',
|
|
|
|
'user_visible',
|
|
|
|
'searchable',
|
|
|
|
'disabled',
|
|
|
|
'kind',
|
|
|
|
]
|
2016-09-20 08:58:07 +02:00
|
|
|
success_url = reverse_lazy('profile-home')
|
|
|
|
|
2021-05-14 18:39:27 +02:00
|
|
|
|
2016-09-20 08:58:07 +02:00
|
|
|
add_attribute = AddAttributeView.as_view()
|
|
|
|
|
|
|
|
|
2016-07-04 09:59:43 +02:00
|
|
|
class OptionsView(UpdateView):
|
|
|
|
model = AttributeDefinition
|
|
|
|
slug_url_kwarg = 'name'
|
|
|
|
slug_field = 'name'
|
|
|
|
fields = [
|
|
|
|
'label',
|
|
|
|
'description',
|
|
|
|
'required',
|
2021-07-27 16:37:16 +02:00
|
|
|
'required_on_login',
|
2016-07-04 09:59:43 +02:00
|
|
|
'asked_on_registration',
|
2019-01-01 13:22:54 +01:00
|
|
|
'user_editable',
|
|
|
|
'user_visible',
|
|
|
|
'searchable',
|
|
|
|
'disabled',
|
|
|
|
]
|
2016-07-04 09:59:43 +02:00
|
|
|
success_url = reverse_lazy('profile-home')
|
2015-05-07 14:37:00 +02:00
|
|
|
|
2021-05-14 18:39:27 +02:00
|
|
|
|
2016-07-04 09:59:43 +02:00
|
|
|
options = OptionsView.as_view()
|
2015-05-07 14:37:00 +02:00
|
|
|
|
2021-05-14 18:39:27 +02:00
|
|
|
|
2023-02-16 16:58:45 +01:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
2015-05-07 14:37:00 +02:00
|
|
|
def reorder(request):
|
|
|
|
new_order_list = [int(x) for x in request.GET['new-order'].split(',')]
|
|
|
|
for attribute in AttributeDefinition.objects.all():
|
|
|
|
old_order = attribute.order
|
|
|
|
new_order = new_order_list.index(attribute.id) + 1
|
|
|
|
if old_order != new_order:
|
|
|
|
attribute.order = new_order_list.index(attribute.id) + 1
|
|
|
|
attribute.save()
|
|
|
|
return redirect(reverse('profile-home'))
|