diff --git a/core/templates/core/macros.jinja b/core/templates/core/macros.jinja index cba03994..21ef4151 100644 --- a/core/templates/core/macros.jinja +++ b/core/templates/core/macros.jinja @@ -55,3 +55,9 @@ {% endif %} {% endmacro %} + +{% macro delete_godfather(user, profile, godfather, is_father) %} + {% if user == profile or user.is_root or user.is_board_member %} + {% trans %}Delete{% endtrans %} + {% endif %} +{% endmacro %} \ No newline at end of file diff --git a/core/templates/core/user_godfathers.jinja b/core/templates/core/user_godfathers.jinja index a82e622d..80331c5e 100644 --- a/core/templates/core/user_godfathers.jinja +++ b/core/templates/core/user_godfathers.jinja @@ -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 %} -

{% trans %}Godfathers{% endtrans %}

- -

{% trans %}Godchildren{% endtrans %}

- - {% if profile == user %} + {% if profile.godfathers.exists() %} +

{% trans %}Godfathers{% endtrans %}

+ + {% else %} +

{% trans %}No godfathers{% endtrans %} + {% endif %} + {% if profile.godchildren.exists() %} +

{% trans %}Godchildren{% endtrans %}

+ + {% else %} +

{% trans %}No godchildren{% endtrans %} + {% endif %} + {% if profile == user or user.is_root %}

{% csrf_token %} {{ form.as_p() }} diff --git a/core/urls.py b/core/urls.py index f1435b98..db983740 100644 --- a/core/urls.py +++ b/core/urls.py @@ -33,6 +33,7 @@ urlpatterns = [ url(r'^user/(?P[0-9]+)/mini$', UserMiniView.as_view(), name='user_profile_mini'), url(r'^user/(?P[0-9]+)/$', UserView.as_view(), name='user_profile'), url(r'^user/(?P[0-9]+)/godfathers$', UserGodfathersView.as_view(), name='user_godfathers'), + url(r'^user/(?P[0-9]+)/godfathers/(?P[0-9]+)/(?P(True)|(False))/delete$', DeleteUserGodfathers, name='user_godfathers_delete'), url(r'^user/(?P[0-9]+)/edit$', UserUpdateProfileView.as_view(), name='user_edit'), url(r'^user/(?P[0-9]+)/profile_upload$', UserUploadProfilePictView.as_view(), name='user_profile_upload'), url(r'^user/(?P[0-9]+)/groups$', UserUpdateGroupView.as_view(), name='user_groups'), diff --git a/core/views/user.py b/core/views/user.py index c46bb676..00b5179c 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -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