Add membership check, joining action to association detail page

Summary:
- Add an endpoint to allow joining an association
- Replace the "Join" button with a deactivated one if the user is already a member

Test Plan:
- Not connected, click a join button, check that you've joined after logging in
- Already logged in, click a join button, and check that it's deactivated afterwards

Reviewers: corbeaumax, Armteck

Reviewed By: corbeaumax

Maniphest Tasks: T65

Differential Revision: https://phabricator.atilla.org/D34
parent 7c2219b4
......@@ -61,7 +61,14 @@
{% endfor %}
</div>
{% endif %}
<input class="btn blue darken-2 center" value="join" type="submit"/>
{% if not is_member %}
<form method="POST" action="{% url 'associations:join' id=asso.pk %}">
{% csrf_token %}
<input class="btn blue darken-2 center" value="join" type="submit"/>
</form>
{% else %}
<a class="btn disabled">Vous êtes déja membre ;)</a>
{% endif %}
</div>
</div>
<div id="desc-column">
......
......@@ -6,5 +6,6 @@ from . import views
urlpatterns = [
url(r'^$', views.list, name='list'),
url(r'^(?P<id>\d+)$', views.details, name='details'),
url(r'^(?P<id>\d+)/edit$', views.edit, name='edit')
url(r'^(?P<id>\d+)/edit$', views.edit, name='edit'),
url(r'^join/(?P<id>\d+)$', views.join, name='join'),
]
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.db.utils import IntegrityError
from django.shortcuts import (
get_object_or_404,
HttpResponseRedirect,
redirect,
render)
from .models import Association
from common.models import SchoolYear
from .models import Account, Association, Membership
from .forms import AssociationForm
......@@ -30,13 +34,39 @@ def list(request):
def details(request, id):
asso = get_object_or_404(Association, pk=id)
links = sorted(asso.sociallink_set.all(), key=orderKey)
is_member = asso.is_member(request.user)
return render(
request,
'associations/details.html',
{'asso': asso, 'links': links}
{'asso': asso, 'links': links, 'is_member': is_member}
)
# TODO: It will be necessary to check who the authenticated user is
@login_required
def join(request, id):
asso = get_object_or_404(Association, pk=id)
# No need to check if the account exists
account = Account.objects.get(user=request.user)
try:
Membership.objects.create(
account=account,
role='OT',
year=SchoolYear.objects.last(),
association=asso
)
except IntegrityError:
messages.error(request, "Une erreur s'est produite!")
messages.success(request,
"Votre inscription est en attente de validation par le " +
"bureau de l'association {}".format(asso.name))
return redirect(
reverse('associations:details', kwargs={'id': asso.pk}))
def edit(request, id):
asso = get_object_or_404(Association, pk=id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment