possibility to create participation from account
This commit is contained in:
parent
61d0372bfd
commit
92128bbe6e
|
@ -1,5 +1,8 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.forms.models import modelform_factory
|
||||
from django import forms
|
||||
|
||||
from django_select2.forms import Select2Widget
|
||||
|
||||
from .models import Participation, Profile
|
||||
|
||||
|
@ -16,3 +19,12 @@ ProfileOrgaForm = modelform_factory(Profile, fields=['biography', 'notes'])
|
|||
|
||||
ParticipationOrgaForm = modelform_factory(Participation,
|
||||
fields=['transport', 'connector', 'sound', 'constraints', 'orga'])
|
||||
|
||||
class ParticipationField(forms.ModelChoiceField):
|
||||
def label_from_instance(self, obj):
|
||||
return obj.profile.__str__()
|
||||
|
||||
|
||||
class NewParticipationForm(forms.Form):
|
||||
|
||||
participant = ParticipationField(User.objects.all(), widget=Select2Widget(), label='Add participant from existing account')
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% load bootstrap3 %}
|
||||
{% load accounts_tags %}
|
||||
|
||||
{% block admintab %} active{% endblock %}
|
||||
|
||||
|
@ -44,9 +45,20 @@
|
|||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% if request|orga %}
|
||||
{% include "_form.html" %}
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
{{ block.css }}
|
||||
{{ form.media.css }}
|
||||
{% endblock %}
|
||||
|
||||
{% block js_end %}
|
||||
{{ block.super }}
|
||||
{{ form.media.js }}
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip()
|
||||
|
|
|
@ -9,7 +9,7 @@ urlpatterns = [
|
|||
url(r'^profile/$', views.profile, name='profile'),
|
||||
url(r'^login/$', auth_views.login, {'extra_context': {'buttons': [views.RESET_PASSWORD_BUTTON]}}, name='login'),
|
||||
url(r'^logout/$', auth_views.logout, {'next_page': settings.LOGOUT_REDIRECT_URL}, name='logout'),
|
||||
url(r'^admin/participants/$', views.ParticipantList.as_view(), name='list-participant'),
|
||||
url(r'^admin/participants/$', views.participation_list, name='list-participant'),
|
||||
url(r'^admin/participant/(?P<username>[\w.@+-]+)$', views.edit, name='edit-participant'),
|
||||
url(r'', include('django.contrib.auth.urls')),
|
||||
]
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.shortcuts import get_object_or_404, render, redirect
|
||||
from django.views.generic import ListView
|
||||
from django.contrib.sites.shortcuts import get_current_site
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from registration.backends.default.views import RegistrationView
|
||||
|
||||
from .forms import ParticipationForm, ParticipationOrgaForm, ProfileForm, ProfileOrgaForm, UserForm
|
||||
from .forms import ParticipationForm, ParticipationOrgaForm, ProfileForm, ProfileOrgaForm, UserForm, NewParticipationForm
|
||||
from .mixins import StaffRequiredMixin
|
||||
from .decorators import staff_required
|
||||
from .models import Participation, Profile
|
||||
from .utils import can_edit_profile, is_orga
|
||||
from .models import User
|
||||
|
||||
RESET_PASSWORD_BUTTON = ('password_reset', 'warning', 'Reset your password')
|
||||
CHANGE_PASSWORD_BUTTON = ('password_change', 'warning', 'Change password')
|
||||
|
@ -39,9 +42,24 @@ def profile(request):
|
|||
return render(request, 'accounts/profile.html', {'forms': forms, 'buttons': [CHANGE_PASSWORD_BUTTON]})
|
||||
|
||||
|
||||
class ParticipantList(StaffRequiredMixin, ListView):
|
||||
def get_queryset(self):
|
||||
return Participation.objects.filter(site=get_current_site(self.request)).all()
|
||||
@staff_required
|
||||
def participation_list(request):
|
||||
participation_list = Participation.objects.filter(site=get_current_site(request)).all()
|
||||
form = NewParticipationForm(request.POST or None)
|
||||
|
||||
if request.method == 'POST' and form.is_valid():
|
||||
user = User.objects.get(username=form.cleaned_data['participant'])
|
||||
participation, created = Participation.objects.get_or_create(user=user, site=get_current_site(request))
|
||||
if created:
|
||||
messages.success(request, "%s added to participant" % user.profile)
|
||||
else:
|
||||
messages.info(request, "%s is already a participant" % user.profile)
|
||||
return redirect(reverse('list-participant'))
|
||||
|
||||
return render(request, 'accounts/participation_list.html', {
|
||||
'participation_list': participation_list,
|
||||
'form': form,
|
||||
})
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in New Issue