Add membership check, joining action to association detail page

- 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:
parent 7c2219b4
......@@ -61,7 +61,14 @@
{% endfor %}
{% endif %}
<input class="btn blue darken-2 center" value="join" type="submit"/>
{% if not is_member %}
<form method="POST" action="{% url 'associations:join' %}">
{% csrf_token %}
<input class="btn blue darken-2 center" value="join" type="submit"/>
{% else %}
<a class="btn disabled">Vous êtes déja membre ;)</a>
{% endif %}
<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 (
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(
{'asso': asso, 'links': links}
{'asso': asso, 'links': links, 'is_member': is_member}
# TODO: It will be necessary to check who the authenticated user is
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)
except IntegrityError:
messages.error(request, "Une erreur s'est produite!")
"Votre inscription est en attente de validation par le " +
"bureau de l'association {}".format(
return redirect(
reverse('associations:details', kwargs={'id':}))
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