add approve action
This commit is contained in:
parent
f5b612cf0c
commit
93fdfd5712
|
@ -290,6 +290,11 @@ urlpatterns = [
|
||||||
TeamMemberRemoveView.as_view(),
|
TeamMemberRemoveView.as_view(),
|
||||||
name='teammember_remove',
|
name='teammember_remove',
|
||||||
),
|
),
|
||||||
|
url(
|
||||||
|
r'^members/(?P<pk>[0-9]+)/approve/$',
|
||||||
|
TeamMemberApproveView.as_view(),
|
||||||
|
name='teammember_approve',
|
||||||
|
),
|
||||||
url(
|
url(
|
||||||
r'(?P<slug>[-_\w+]+)/join/$',
|
r'(?P<slug>[-_\w+]+)/join/$',
|
||||||
TeamJoinView.as_view(),
|
TeamJoinView.as_view(),
|
||||||
|
|
|
@ -87,6 +87,9 @@ Team: {{ team.name }} | {{ block.super }}
|
||||||
<td>
|
<td>
|
||||||
{% if membership.approved %}
|
{% if membership.approved %}
|
||||||
<a class="btn btn-danger" href="{% url 'teammember_remove' camp_slug=camp.slug pk=membership.id %}"><i class="fa fa-trash-o"></i> Remove</a>
|
<a class="btn btn-danger" href="{% url 'teammember_remove' camp_slug=camp.slug pk=membership.id %}"><i class="fa fa-trash-o"></i> Remove</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="btn btn-danger" href="{% url 'teammember_remove' camp_slug=camp.slug pk=membership.id %}"><i class="fa fa-trash-o"></i> Remove</a>
|
||||||
|
<a class="btn btn-success" href="{% url 'teammember_approve' camp_slug=camp.slug pk=membership.id %}"><i class="fa fa-check"></i> Approve</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
18
src/teams/templates/teammember_approve.html
Normal file
18
src/teams/templates/teammember_approve.html
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
{% load commonmark %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Approve team member {{ teammember.user.profile.name }} for the {{ teammember.team.name }} team
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h3>Approve member {{ teammember.user.profile.name }} for the {{ teammember.team.name }} team</h3>
|
||||||
|
<p class="lead">Really approve the user <b>{{ teammember.user.profile.name }}</b> for the {{ teammember.team.name }} team? The user will receive an email with a message.<p>
|
||||||
|
<form method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form }}
|
||||||
|
<button class="btn btn-success" type="submit"><i class="fa fa-check"></i> Add teammember</button>
|
||||||
|
<a href="{% url 'team_detail' camp_slug=teammember.team.camp.slug slug=teammember.team.slug %}" class="btn btn-default" type="submit"><i class="fa fa-remove"></i> Cancel</a>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -2,7 +2,7 @@
|
||||||
{% load commonmark %}
|
{% load commonmark %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
Remove member {{ teammember.user.profile.name }} from team {{ teammember.team.name }}
|
Remove member {{ teammember.user.profile.name }} from the {{ teammember.team.name }} team
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
|
@ -8,6 +8,7 @@ from django.shortcuts import redirect
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.http import Http404, HttpResponseRedirect
|
from django.http import Http404, HttpResponseRedirect
|
||||||
from django.views.generic.detail import SingleObjectMixin
|
from django.views.generic.detail import SingleObjectMixin
|
||||||
|
from django.core.urlresolvers import reverse_lazy
|
||||||
|
|
||||||
|
|
||||||
class TeamListView(CampViewMixin, ListView):
|
class TeamListView(CampViewMixin, ListView):
|
||||||
|
@ -67,7 +68,7 @@ class EnsureTeamResponsibleMixin(SingleObjectMixin):
|
||||||
model = TeamMember
|
model = TeamMember
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
if not request.user in self.get_object().team.responsible.all():
|
if request.user not in self.get_object().team.responsible.all():
|
||||||
messages.error(request, 'No thanks')
|
messages.error(request, 'No thanks')
|
||||||
return HttpResponseRedirect(reverse_lazy('team_detail', slug=self.get_object().team.slug))
|
return HttpResponseRedirect(reverse_lazy('team_detail', slug=self.get_object().team.slug))
|
||||||
|
|
||||||
|
@ -85,3 +86,15 @@ class TeamMemberRemoveView(LoginRequiredMixin, EnsureTeamResponsibleMixin, Updat
|
||||||
form.instance.delete()
|
form.instance.delete()
|
||||||
messages.success(self.request, "Team member removed")
|
messages.success(self.request, "Team member removed")
|
||||||
return redirect('team_detail', camp_slug=form.instance.team.camp.slug, slug=form.instance.team.slug)
|
return redirect('team_detail', camp_slug=form.instance.team.camp.slug, slug=form.instance.team.slug)
|
||||||
|
|
||||||
|
|
||||||
|
class TeamMemberApproveView(LoginRequiredMixin, EnsureTeamResponsibleMixin, UpdateView):
|
||||||
|
template_name = "teammember_approve.html"
|
||||||
|
model = TeamMember
|
||||||
|
fields = []
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
form.instance.approved = True
|
||||||
|
form.instance.save()
|
||||||
|
messages.success(self.request, "Team member approved")
|
||||||
|
return redirect('team_detail', camp_slug=form.instance.team.camp.slug, slug=form.instance.team.slug)
|
||||||
|
|
Loading…
Reference in a new issue