Merge branch 'sli' into 'master'

Godfathers deletion



See merge request !11
This commit is contained in:
Skia 2016-09-29 15:12:19 +02:00
commit 52184c4012
4 changed files with 49 additions and 18 deletions

View File

@ -35,7 +35,7 @@
{%- endmacro %} {%- endmacro %}
{% macro show_slots(user) %} {% macro show_slots(user) %}
{% if get_subscriber(user).slots.exists() %} {% if get_subscriber(user).slots.filter(start_date__gte=timezone.now()).exists() %}
<h5>{% trans %}Slot{% endtrans %}</h5> <h5>{% trans %}Slot{% endtrans %}</h5>
<ul> <ul>
{% for i in get_subscriber(user).slots.filter(start_date__gte=timezone.now().replace(tzinfo=None)).all() %} {% for i in get_subscriber(user).slots.filter(start_date__gte=timezone.now().replace(tzinfo=None)).all() %}
@ -55,3 +55,9 @@
</ul> </ul>
{% endif %} {% endif %}
{% endmacro %} {% 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" %} {% 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 %} {% block title %}
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s godfathers{% endtrans %} {% trans user_name=profile.get_display_name() %}{{ user_name }}'s godfathers{% endtrans %}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<h4>{% trans %}Godfathers{% endtrans %}</h4> {% if profile.godfathers.exists() %}
<ul> <h4>{% trans %}Godfathers{% endtrans %}</h4>
{% for u in profile.godfathers.all() %} <ul>
<li> <a href="{{ url("core:user_godfathers", user_id=u.id) }}" class="mini_profile_link" > {% for u in profile.godfathers.all() %}
{{ u.get_mini_item()|safe }} </a> </li> <li> <a href="{{ url("core:user_godfathers", user_id=u.id) }}" class="mini_profile_link" >
{% endfor %} {{ u.get_mini_item()|safe }} </a>{{ delete_godfather(user, profile, u, True) }}</li>
</ul> {% endfor %}
<h4>{% trans %}Godchildren{% endtrans %}</h4> </ul>
<ul> {% else %}
{% for u in profile.godchildren.all() %} <p>{% trans %}No godfathers{% endtrans %}
<li> <a href="{{ url("core:user_godfathers", user_id=u.id) }}" class="mini_profile_link" > {% endif %}
{{ u.get_mini_item()|safe }} </a> </li> {% if profile.godchildren.exists() %}
{% endfor %} <h4>{% trans %}Godchildren{% endtrans %}</h4>
</ul> <ul>
{% if profile == user %} {% 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>{{ delete_godfather(user, profile, u, False) }}</li>
{% endfor %}
</ul>
{% else %}
<p>{% trans %}No godchildren{% endtrans %}
{% endif %}
{% if profile == user or user.is_root %}
<form action="" method="post"> <form action="" method="post">
{% csrf_token %} {% csrf_token %}
{{ form.as_p() }} {{ 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]+)/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]+)/$', 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$', 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]+)/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]+)/profile_upload$', UserUploadProfilePictView.as_view(), name='user_profile_upload'),
url(r'^user/(?P<user_id>[0-9]+)/groups$', UserUpdateGroupView.as_view(), name='user_groups'), 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.core.exceptions import PermissionDenied, ObjectDoesNotExist, ValidationError
from django.http import Http404 from django.http import Http404
from django.views.generic.edit import UpdateView 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.models import modelform_factory
from django.forms import CheckboxSelectMultiple from django.forms import CheckboxSelectMultiple
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
@ -179,6 +179,22 @@ class UserView(UserTabsMixin, CanViewMixin, DetailView):
template_name = "core/user_detail.jinja" template_name = "core/user_detail.jinja"
current_tab = 'infos' 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): class UserGodfathersView(UserTabsMixin, CanViewMixin, DetailView):
""" """
Display a user's godfathers Display a user's godfathers