Can delete Godfathers

This commit is contained in:
Antoine Bartuccio 2016-09-29 15:04:43 +02:00
parent a008f34288
commit 2c6f17063a
4 changed files with 48 additions and 17 deletions

View File

@ -55,3 +55,9 @@
</ul>
{% endif %}
{% endmacro %}
{% macro delete_godfather(user, profile, godfather, is_father) %}
{% if user == profile or user.is_root or user.is_board_member %}
<a href="{{ url("core:user_godfathers_delete", user_id=profile.id, godfather_id=godfather.id, is_father=is_father) }}">{% trans %}Delete{% endtrans %}</a>
{% endif %}
{% endmacro %}

View File

@ -1,26 +1,34 @@
{% extends "core/base.jinja" %}
{% from "core/macros.jinja" import user_link_with_pict %}
{% from "core/macros.jinja" import user_link_with_pict, delete_godfather %}
{% block title %}
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s godfathers{% endtrans %}
{% endblock %}
{% block content %}
{% if profile.godfathers.exists() %}
<h4>{% trans %}Godfathers{% endtrans %}</h4>
<ul>
{% for u in profile.godfathers.all() %}
<li> <a href="{{ url("core:user_godfathers", user_id=u.id) }}" class="mini_profile_link" >
{{ u.get_mini_item()|safe }} </a> </li>
{{ u.get_mini_item()|safe }} </a>{{ delete_godfather(user, profile, u, True) }}</li>
{% endfor %}
</ul>
{% else %}
<p>{% trans %}No godfathers{% endtrans %}
{% endif %}
{% if profile.godchildren.exists() %}
<h4>{% trans %}Godchildren{% endtrans %}</h4>
<ul>
{% for u in profile.godchildren.all() %}
<li> <a href="{{ url("core:user_godfathers", user_id=u.id) }}" class="mini_profile_link" >
{{ u.get_mini_item()|safe }} </a> </li>
{{ u.get_mini_item()|safe }} </a>{{ delete_godfather(user, profile, u, False) }}</li>
{% endfor %}
</ul>
{% if profile == user %}
{% else %}
<p>{% trans %}No godchildren{% endtrans %}
{% endif %}
{% if profile == user or user.is_root %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p() }}

View File

@ -33,6 +33,7 @@ urlpatterns = [
url(r'^user/(?P<user_id>[0-9]+)/mini$', UserMiniView.as_view(), name='user_profile_mini'),
url(r'^user/(?P<user_id>[0-9]+)/$', UserView.as_view(), name='user_profile'),
url(r'^user/(?P<user_id>[0-9]+)/godfathers$', UserGodfathersView.as_view(), name='user_godfathers'),
url(r'^user/(?P<user_id>[0-9]+)/godfathers/(?P<godfather_id>[0-9]+)/(?P<is_father>(True)|(False))/delete$', DeleteUserGodfathers, name='user_godfathers_delete'),
url(r'^user/(?P<user_id>[0-9]+)/edit$', UserUpdateProfileView.as_view(), name='user_edit'),
url(r'^user/(?P<user_id>[0-9]+)/profile_upload$', UserUploadProfilePictView.as_view(), name='user_profile_upload'),
url(r'^user/(?P<user_id>[0-9]+)/groups$', UserUpdateGroupView.as_view(), name='user_groups'),

View File

@ -6,7 +6,7 @@ from django.core.urlresolvers import reverse
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist, ValidationError
from django.http import Http404
from django.views.generic.edit import UpdateView
from django.views.generic import ListView, DetailView, TemplateView
from django.views.generic import ListView, DetailView, TemplateView, DeleteView
from django.forms.models import modelform_factory
from django.forms import CheckboxSelectMultiple
from django.template.response import TemplateResponse
@ -179,6 +179,22 @@ class UserView(UserTabsMixin, CanViewMixin, DetailView):
template_name = "core/user_detail.jinja"
current_tab = 'infos'
def DeleteUserGodfathers(request, user_id, godfather_id, is_father):
user = User.objects.get(id=user_id)
if ((user == request.user) or
request.user.is_root or
request.user.is_board_member):
ud = get_object_or_404(User, id=godfather_id)
if is_father == "True":
user.godfathers.remove(ud)
else:
user.godchildren.remove(ud)
else:
raise PermissionDenied
return redirect('core:user_godfathers', user_id=user_id)
class UserGodfathersView(UserTabsMixin, CanViewMixin, DetailView):
"""
Display a user's godfathers