Skip to content
Snippets Groups Projects
Unverified Commit a79e01cf authored by Todd Dembrey's avatar Todd Dembrey Committed by GitHub
Browse files

Merge pull request #457 from OpenTechFund/feature/247-add-duration-fields

Make the users sortable in the become form
parents 4204fe03 e03e4734
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ from django.utils.translation import gettext_lazy as _ ...@@ -4,6 +4,7 @@ from django.utils.translation import gettext_lazy as _
from wagtail.users.forms import UserEditForm, UserCreationForm from wagtail.users.forms import UserEditForm, UserCreationForm
from django_select2.forms import Select2Widget
User = get_user_model() User = get_user_model()
...@@ -53,3 +54,13 @@ class ProfileForm(forms.ModelForm): ...@@ -53,3 +54,13 @@ class ProfileForm(forms.ModelForm):
slack = '@' + slack slack = '@' + slack
return slack return slack
class BecomeUserForm(forms.Form):
user = forms.ModelChoiceField(
widget=Select2Widget,
help_text="Only includes active, non-superusers",
queryset=User.objects.filter(is_active=True, is_superuser=False),
label='',
required=False,
)
...@@ -30,25 +30,15 @@ ...@@ -30,25 +30,15 @@
{% endif %} {% endif %}
<div class="profile__column"> <div class="profile__column">
{% if swappable %} {% if swappable_form %}
<h3>Become:</h3>
<form action="{% url 'users:become' %}" method="post" class="form"> <form action="{% url 'users:become' %}" method="post" class="form">
{{ swappable_form.media }}
{% csrf_token %} {% csrf_token %}
{% for user in swappable %} {% for field in swappable_form %}
{% if forloop.first %} {% include "funds/includes/field.html" %}
<h3>Become:</h3>
<p class="form__help">Only includes active, non-superusers</p>
<div class="form__item">
<div class="form__select">
<select name="user" id="user">
{% endif %}
<option value="{{ user.id }}">{{ user }}</option>
{% if forloop.last %}
</select>
</div>
</div>
{% endif %}
{% endfor %} {% endfor %}
<button class="button button--primary button--top-space" type="submit">Become</button> <button class="button button--primary" type="submit">Become</button>
</form> </form>
{% endif %} {% endif %}
......
...@@ -17,7 +17,7 @@ from hijack.views import login_with_id ...@@ -17,7 +17,7 @@ from hijack.views import login_with_id
from wagtail.admin.views.account import password_management_enabled from wagtail.admin.views.account import password_management_enabled
from .decorators import require_oauth_whitelist from .decorators import require_oauth_whitelist
from .forms import ProfileForm from .forms import BecomeUserForm, ProfileForm
User = get_user_model() User = get_user_model()
...@@ -36,14 +36,14 @@ class AccountView(UpdateView): ...@@ -36,14 +36,14 @@ class AccountView(UpdateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
if self.request.user.is_superuser: if self.request.user.is_superuser:
swappable = User.objects.filter(is_active=True, is_superuser=False) swappable_form = BecomeUserForm()
else: else:
swappable = [] swappable_form = None
show_change_password = password_management_enabled() and self.request.user.has_usable_password(), show_change_password = password_management_enabled() and self.request.user.has_usable_password(),
return super().get_context_data( return super().get_context_data(
swappable=swappable, swappable_form=swappable_form,
show_change_password=show_change_password, show_change_password=show_change_password,
**kwargs, **kwargs,
) )
...@@ -51,8 +51,8 @@ class AccountView(UpdateView): ...@@ -51,8 +51,8 @@ class AccountView(UpdateView):
@login_required() @login_required()
def become(request): def become(request):
if request.POST: id = request.POST['user']
id = request.POST['user'] if request.POST and id:
return login_with_id(request, id) return login_with_id(request, id)
return redirect('users:account') return redirect('users:account')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment