add aliases view to clubs

This commit is contained in:
Pierre-antoine Comby 2020-03-25 18:00:40 +01:00
parent a41e51e23a
commit 33e3657120
8 changed files with 39 additions and 29 deletions

View File

@ -14,11 +14,12 @@ urlpatterns = [
path('club/create/', views.ClubCreateView.as_view(), name="club_create"), path('club/create/', views.ClubCreateView.as_view(), name="club_create"),
path('club/<int:pk>/update', views.ClubUpdateView.as_view(), name="club_update"), path('club/<int:pk>/update', views.ClubUpdateView.as_view(), name="club_update"),
path('club/<int:pk>/update_pic', views.ClubPictureUpdateView.as_view(), name="club_update_pic"), path('club/<int:pk>/update_pic', views.ClubPictureUpdateView.as_view(), name="club_update_pic"),
path('club/<int:pk>/aliases', views.ClubAliasView.as_view(), name="club_alias"),
path('user/', views.UserListView.as_view(), name="user_list"), path('user/', views.UserListView.as_view(), name="user_list"),
path('user/<int:pk>', views.UserDetailView.as_view(), name="user_detail"), path('user/<int:pk>', views.UserDetailView.as_view(), name="user_detail"),
path('user/<int:pk>/update', views.UserUpdateView.as_view(), name="user_update_profile"), path('user/<int:pk>/update', views.UserUpdateView.as_view(), name="user_update_profile"),
path('user/<int:pk>/update_pic', views.ProfilePictureUpdateView.as_view(), name="user_update_pic"), path('user/<int:pk>/update_pic', views.ProfilePictureUpdateView.as_view(), name="user_update_pic"),
path('user/<int:pk>/aliases', views.AliasView.as_view(), name="user_alias"), path('user/<int:pk>/aliases', views.ProfileAliasView.as_view(), name="user_alias"),
path('user/aliases/delete/<int:pk>', views.DeleteAliasView.as_view(), name="user_alias_delete"), path('user/aliases/delete/<int:pk>', views.DeleteAliasView.as_view(), name="user_alias_delete"),
path('manage-auth-token/', views.ManageAuthTokens.as_view(), name='auth_token'), path('manage-auth-token/', views.ManageAuthTokens.as_view(), name='auth_token'),
# API for the user autocompleter # API for the user autocompleter

View File

@ -168,15 +168,14 @@ class UserListView(LoginRequiredMixin, SingleTableView):
return context return context
class AliasView(LoginRequiredMixin, FormMixin, DetailView): class AliasView(LoginRequiredMixin, FormMixin, DetailView):
model = User
template_name = 'member/profile_alias.html'
context_object_name = 'user_object'
form_class = AliasForm form_class = AliasForm
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
note = context['user_object'].note note = context['object'].note
context["aliases"] = AliasTable(note.alias_set.all()) context["aliases"] = AliasTable(note.alias_set.all())
return context return context
@ -197,6 +196,11 @@ class AliasView(LoginRequiredMixin, FormMixin, DetailView):
alias.save() alias.save()
return super().form_valid(form) return super().form_valid(form)
class ProfileAliasView(AliasView):
model = User
template_name = 'member/profile_alias.html'
context_object_name = 'user_object'
class DeleteAliasView(LoginRequiredMixin, DeleteView): class DeleteAliasView(LoginRequiredMixin, DeleteView):
model = Alias model = Alias
@ -364,6 +368,11 @@ class ClubDetailView(LoginRequiredMixin, DetailView):
context['member_list'] = club_member context['member_list'] = club_member
return context return context
class ClubAliasView(AliasView):
model = Club
template_name = 'member/club_alias.html'
context_object_name = 'club'
class ClubUpdateView(LoginRequiredMixin, UpdateView): class ClubUpdateView(LoginRequiredMixin, UpdateView):
model = Club model = Club

View File

@ -0,0 +1,15 @@
{% load django_tables2 crispy_forms_tags i18n %}
<div class="d-flex justify-content-center">
<form class=" text-center form my-2" action="" method="post">
{% csrf_token %}
{{ form |crispy }}
<button class="btn btn-primary mx-2" type="submit">
{% trans "Add alias" %}
</button>
</form>
</div>
<div class="card bg-light shadow">
<div class="card-body">
{% render_table aliases %}
</div>
</div>

View File

@ -0,0 +1,6 @@
{% extends "member/club_detail.html" %}
{% load i18n static pretty_money django_tables2 crispy_forms_tags %}
{% block profile_content %}
{% include "member/alias_update.html" %}
{% endblock %}

View File

@ -25,7 +25,7 @@
<dt class="col-xl-6">{% trans 'membership fee'|capfirst %}</dt> <dt class="col-xl-6">{% trans 'membership fee'|capfirst %}</dt>
<dd class="col-xl-6">{{ club.membership_fee|pretty_money }}</dd> <dd class="col-xl-6">{{ club.membership_fee|pretty_money }}</dd>
<dt class="col-xl-6"><a href="{% url 'member:user_alias' club.pk %}">{% trans 'aliases'|capfirst %}</a></dt> <dt class="col-xl-6"><a href="{% url 'member:club_alias' club.pk %}">{% trans 'aliases'|capfirst %}</a></dt>
<dd class="col-xl-6 text-truncate">{{ object.note.alias_set.all|join:", " }}</dd> <dd class="col-xl-6 text-truncate">{{ object.note.alias_set.all|join:", " }}</dd>
<dt class="col-xl-3">{% trans 'email'|capfirst %}</dt> <dt class="col-xl-3">{% trans 'email'|capfirst %}</dt>

View File

@ -1,10 +1,6 @@
{% extends "member/club_detail.html" %} {% extends "member/club_detail.html" %}
{% load i18n static pretty_money django_tables2 crispy_forms_tags %} {% load i18n static pretty_money django_tables2 crispy_forms_tags %}
{% block profile_info %}
{% include "member/club_info.html" %}
{% endblock%}
{% block profile_content%} {% block profile_content%}
{% include "member/picture_update.html" %} {% include "member/picture_update.html" %}
{% endblock%} {% endblock%}

View File

@ -2,18 +2,5 @@
{% load i18n static pretty_money django_tables2 crispy_forms_tags %} {% load i18n static pretty_money django_tables2 crispy_forms_tags %}
{% block profile_content %} {% block profile_content %}
<div class="d-flex justify-content-center"> {% include "member/alias_update.html"%}
<form class=" text-center form my-2" action="" method="post">
{% csrf_token %}
{{ form |crispy }}
<button class="btn btn-primary mx-2" type="submit">
{% trans "Add alias" %}
</button>
</form>
</div>
<div class="card bg-light shadow">
<div class="card-body">
{% render_table aliases %}
</div>
</div>
{% endblock %} {% endblock %}

View File

@ -1,10 +1,6 @@
{% extends "member/noteowner_detail.html" %} {% extends "member/profile_detail.html" %}
{% load i18n static pretty_money django_tables2 crispy_forms_tags %} {% load i18n static pretty_money django_tables2 crispy_forms_tags %}
{% block profile_info %}
{% include "member/profile_info.html" %}
{% endblock%}
{% block profile_content%} {% block profile_content%}
{% include "member/picture_update.html" %} {% include "member/picture_update.html" %}
{% endblock%} {% endblock%}