Intitial teams support #147
@ -14,7 +14,7 @@
|
|||||||
{% if not field.is_hidden %}
|
{% if not field.is_hidden %}
|
||||||
<label for="{{ field.id_for_label }}" class="form-check-label">
|
<label for="{{ field.id_for_label }}" class="form-check-label">
|
||||||
{{ label|safe }}
|
{{ label|safe }}
|
||||||
{% if field.field.required %}<span class="form-required-indicator">*</span>{% endif %}
|
{% if field.field.required or required %}<span class="form-required-indicator">*</span>{% endif %}
|
||||||
</label>
|
</label>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
@ -24,7 +24,7 @@
|
|||||||
{% if not field.is_hidden %}
|
{% if not field.is_hidden %}
|
||||||
<label for="{{ field.id_for_label }}">
|
<label for="{{ field.id_for_label }}">
|
||||||
{{ label|safe }}
|
{{ label|safe }}
|
||||||
{% if field.field.required %}<span class="form-required-indicator">*</span>{% endif %}
|
{% if field.field.required or required %}<span class="form-required-indicator">*</span>{% endif %}
|
||||||
</label>
|
</label>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -163,6 +163,17 @@ class ExtensionUpdateForm(forms.ModelForm):
|
|||||||
|
|
||||||
self.add_preview_formset.error_messages['too_few_forms'] = self.msg_need_previews
|
self.add_preview_formset.error_messages['too_few_forms'] = self.msg_need_previews
|
||||||
|
|
||||||
|
user_teams = self.request.user.teams.all()
|
||||||
|
if self.request.user in self.instance.authors.all() and len(user_teams) > 0:
|
||||||
|
team_pk = None
|
||||||
|
if self.instance.team:
|
||||||
|
team_pk = self.instance.team.pk
|
||||||
|
self.fields['team'] = forms.ChoiceField(
|
||||||
|
choices=[(None, self.request.user), *[(team.pk, team.name) for team in user_teams]],
|
||||||
|
required=False,
|
||||||
|
initial=team_pk,
|
||||||
|
)
|
||||||
|
|
||||||
def is_valid(self, *args, **kwargs) -> bool:
|
def is_valid(self, *args, **kwargs) -> bool:
|
||||||
"""Validate all nested forms and form(set)s first."""
|
"""Validate all nested forms and form(set)s first."""
|
||||||
if 'submit_draft' in self.data:
|
if 'submit_draft' in self.data:
|
||||||
@ -198,6 +209,27 @@ class ExtensionUpdateForm(forms.ModelForm):
|
|||||||
|
|
||||||
return all(is_valid_flags)
|
return all(is_valid_flags)
|
||||||
|
|
||||||
|
def clean_team(self):
|
||||||
|
# don't modify instance if the field value wasn't sent
|
||||||
|
# empty value reset the team
|
||||||
|
if 'team' in self.data:
|
||||||
|
# TODO permissions check
|
||||||
|
# shouldn't happen normally: the form doesn't render the select
|
||||||
|
if self.request.user not in self.instance.authors.all():
|
||||||
|
self.add_error('team', _('Not allowed to set the team'))
|
||||||
|
return
|
||||||
|
|
||||||
|
team_pk = self.cleaned_data['team']
|
||||||
|
if team_pk:
|
||||||
|
team = self.request.user.teams.filter(pk=team_pk).first()
|
||||||
|
if not team:
|
||||||
|
self.add_error('team', _('User does not belong to the team'))
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.instance.team = team
|
||||||
|
else:
|
||||||
|
self.instance.team = None
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""Perform additional validation and status changes."""
|
"""Perform additional validation and status changes."""
|
||||||
super().clean()
|
super().clean()
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
{% if user in extension.authors.all and user.teams.count > 0 %}
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col">
|
||||||
|
{# django won't allow submitting an empty field for a required field, so using a hack with an explicit required=True #}
|
||||||
|
{% include "common/components/field.html" with field=extension_form.team label="Assign Team" required=True %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{% include "common/components/field.html" with field=extension_form.description label="Description" placeholder="Describe the extension..." %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{% include "common/components/field.html" with field=extension_form.support placeholder="https://example.com" %}
|
||||||
|
</div>
|
@ -1,5 +1,5 @@
|
|||||||
{% extends "common/base.html" %}
|
{% extends "common/base.html" %}
|
||||||
{% load i18n common pipeline %}
|
{% load common filters i18n pipeline %}
|
||||||
|
|
||||||
{% block page_title %}
|
{% block page_title %}
|
||||||
{% with extension=extension_form.instance %}
|
{% with extension=extension_form.instance %}
|
||||||
@ -40,36 +40,7 @@
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="card p-3 mb-3">
|
<section class="card p-3 mb-3">
|
||||||
{% if user.team_users %}
|
{% include "extensions/components/extension_form.html" with extension_form=extension_form %}
|
||||||
<div class="row mb-3">
|
|
||||||
<div class="col">
|
|
||||||
{# TODO: @back-end process Select Team with Django #}
|
|
||||||
<label>Select Team</label><span class="form-required-indicator">*</span>
|
|
||||||
<select class="form-control" id="team" allowempty="false" required>
|
|
||||||
{# TODO: chcek while option first is not selected #}
|
|
||||||
<option disabled>Select...</option>
|
|
||||||
|
|
||||||
{% for team_member in user.team_users.all %}
|
|
||||||
{% with team=team_member.team %}
|
|
||||||
<option>{{ team.name }}</option>
|
|
||||||
{% endwith %}
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="col"></div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% for field in extension_form %}
|
|
||||||
{% if field != 'tags' %}
|
|
||||||
{# TODO: fix handling of tags #}
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
{% include "common/components/field.html" with placeholder="Enter the text here..." %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="mt-4">
|
<section class="mt-4">
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
{% extends "common/base.html" %}
|
{% extends "common/base.html" %}
|
||||||
{% load filters %}
|
{% load common filters i18n pipeline %}
|
||||||
{% load i18n common pipeline %}
|
|
||||||
{% block page_title %}{{ extension.name }}{% endblock page_title %}
|
{% block page_title %}{{ extension.name }}{% endblock page_title %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
@ -29,33 +28,7 @@
|
|||||||
{{ form.errors }}
|
{{ form.errors }}
|
||||||
|
|
||||||
<section class="card p-3">
|
<section class="card p-3">
|
||||||
{% if user.team_users %}
|
{% include "extensions/components/extension_form.html" with extension_form=form %}
|
||||||
<div class="row mb-3">
|
|
||||||
<div class="col">
|
|
||||||
{# TODO: @back-end process Assign Team with Django #}
|
|
||||||
<label>Assign Team</label><span class="form-required-indicator">*</span>
|
|
||||||
<select class="form-control" id="team" allowempty="false" required>
|
|
||||||
{# TODO: check while option first is not selected #}
|
|
||||||
<option disabled>Select...</option>
|
|
||||||
|
|
||||||
{% for team_member in user.team_users.all %}
|
|
||||||
{% with team=team_member.team %}
|
|
||||||
<option>{{ team.name }}</option>
|
|
||||||
{% endwith %}
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="col"></div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<div>
|
|
||||||
{% include "common/components/field.html" with field=form.description label="Description" placeholder="Describe the extension..." %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
{% include "common/components/field.html" with field=form.support placeholder="https://example.com" %}
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="mt-4">
|
<section class="mt-4">
|
||||||
|
Loading…
Reference in New Issue
Block a user