#101 Team enhancements
* visual enhancement for team index rendering * adds validity check for admin-membership of a team
This commit is contained in:
@@ -233,10 +233,27 @@ class EditTeamModalForm(NewTeamModalForm):
|
||||
empty_label=None,
|
||||
)
|
||||
|
||||
def __is_admin_valid(self):
|
||||
admin = self.cleaned_data.get("admin", None)
|
||||
members = self.cleaned_data.get("members", None)
|
||||
_is_valid = admin in members
|
||||
|
||||
if not _is_valid:
|
||||
self.add_error(
|
||||
"members",
|
||||
_("Selected admin ({}) needs to be a member of this team.").format(admin.username)
|
||||
)
|
||||
|
||||
return _is_valid
|
||||
|
||||
def is_valid(self):
|
||||
super_valid = super().is_valid()
|
||||
admin_valid = self.__is_admin_valid()
|
||||
return super_valid and admin_valid
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("Edit team")
|
||||
self.form_caption = None
|
||||
self.action_url = reverse("user:team-edit", args=(self.instance.id,))
|
||||
self.cancel_redirect = reverse("user:team-index")
|
||||
|
||||
@@ -255,6 +272,7 @@ class EditTeamModalForm(NewTeamModalForm):
|
||||
with transaction.atomic():
|
||||
self.instance.name = self.cleaned_data.get("name", None)
|
||||
self.instance.description = self.cleaned_data.get("description", None)
|
||||
self.instance.admin = self.cleaned_data.get("admin", None)
|
||||
self.instance.save()
|
||||
self.instance.users.set(self.cleaned_data.get("members", []))
|
||||
return self.instance
|
||||
|
||||
@@ -13,51 +13,53 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h4>{% trans 'Teams' %}</h4>
|
||||
<div class="col-md">
|
||||
<button class="btn rlp-r btn-modal" data-form-url="{% url 'user:team-new' %}" title="{% trans 'Add new team' %}">
|
||||
{% fa5_icon 'plus' %}
|
||||
{% trans 'New' %}
|
||||
</button>
|
||||
</div>
|
||||
<div class="table-container">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" class="align-middle">{% trans 'Name' %}</th>
|
||||
<th scope="col" class="align-middle w-20">{% trans 'Description' %}</th>
|
||||
<th scope="col" class="align-middle">{% trans 'Members' %}</th>
|
||||
<th scope="col" class="align-middle">{% trans 'Actions' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for team in teams %}
|
||||
<div class="container">
|
||||
<h4>{% trans 'Teams' %}</h4>
|
||||
<div class="col-md">
|
||||
<button class="btn rlp-r btn-modal" data-form-url="{% url 'user:team-new' %}" title="{% trans 'Add new team' %}">
|
||||
{% fa5_icon 'plus' %}
|
||||
{% trans 'New' %}
|
||||
</button>
|
||||
</div>
|
||||
<div class="table-container">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{{team.name}}</td>
|
||||
<td>
|
||||
<div class="scroll-150">
|
||||
{{team.description}}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
{% for member in team.users.all %}
|
||||
<span class="badge badge-pill rlp-r">{{member.username}}</span>
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td>
|
||||
{% if team.admin == user %}
|
||||
<button class="btn rlp-r btn-modal" data-form-url="{% url 'user:team-edit' team.id %}" title="{% trans 'Edit team' %}">
|
||||
{% fa5_icon 'edit' %}
|
||||
</button>
|
||||
<button class="btn rlp-r btn-modal" data-form-url="{% url 'user:team-remove' team.id %}" title="{% trans 'Remove team' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
<th scope="col" class="align-middle">{% trans 'Name' %}</th>
|
||||
<th scope="col" class="align-middle w-20">{% trans 'Description' %}</th>
|
||||
<th scope="col" class="align-middle">{% trans 'Members' %}</th>
|
||||
<th scope="col" class="align-middle">{% trans 'Action' %}</th>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for team in teams %}
|
||||
<tr>
|
||||
<td>{{team.name}}</td>
|
||||
<td>
|
||||
<div class="scroll-150">
|
||||
{{team.description}}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
{% for member in team.users.all %}
|
||||
<span class="badge badge-pill rlp-r">{{member.username}}</span>
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td>
|
||||
{% if team.admin == user %}
|
||||
<button class="btn rlp-r btn-modal" data-form-url="{% url 'user:team-edit' team.id %}" title="{% trans 'Edit team' %}">
|
||||
{% fa5_icon 'edit' %}
|
||||
</button>
|
||||
<button class="btn rlp-r btn-modal" data-form-url="{% url 'user:team-remove' team.id %}" title="{% trans 'Remove team' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% with 'btn-modal' as btn_class %}
|
||||
|
||||
Reference in New Issue
Block a user