From 33e3657120118e88e6c9ba7043ec8720a07c70fa Mon Sep 17 00:00:00 2001
From: Pierre-antoine Comby <comby@crans.org>
Date: Wed, 25 Mar 2020 18:00:40 +0100
Subject: [PATCH] add aliases view to clubs

---
 apps/member/urls.py                          |  3 ++-
 apps/member/views.py                         | 17 +++++++++++++----
 templates/member/alias_update.html           | 15 +++++++++++++++
 templates/member/club_alias.html             |  6 ++++++
 templates/member/club_info.html              |  2 +-
 templates/member/club_picture_update.html    |  4 ----
 templates/member/profile_alias.html          | 15 +--------------
 templates/member/profile_picture_update.html |  6 +-----
 8 files changed, 39 insertions(+), 29 deletions(-)
 create mode 100644 templates/member/alias_update.html
 create mode 100644 templates/member/club_alias.html

diff --git a/apps/member/urls.py b/apps/member/urls.py
index bc536f60..1b296771 100644
--- a/apps/member/urls.py
+++ b/apps/member/urls.py
@@ -14,11 +14,12 @@ urlpatterns = [
     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_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/<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_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('manage-auth-token/', views.ManageAuthTokens.as_view(), name='auth_token'),
     # API for the user autocompleter
diff --git a/apps/member/views.py b/apps/member/views.py
index 14322dcf..1ea2212c 100644
--- a/apps/member/views.py
+++ b/apps/member/views.py
@@ -168,15 +168,14 @@ class UserListView(LoginRequiredMixin, SingleTableView):
         return context
 
 
+
+    
 class AliasView(LoginRequiredMixin, FormMixin, DetailView):
-    model = User
-    template_name = 'member/profile_alias.html'
-    context_object_name = 'user_object'
     form_class = AliasForm
 
     def get_context_data(self, **kwargs):
         context = super().get_context_data(**kwargs)
-        note = context['user_object'].note
+        note = context['object'].note
         context["aliases"] = AliasTable(note.alias_set.all())
         return context
 
@@ -197,6 +196,11 @@ class AliasView(LoginRequiredMixin, FormMixin, DetailView):
         alias.save()
         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):
     model = Alias
@@ -364,6 +368,11 @@ class ClubDetailView(LoginRequiredMixin, DetailView):
         context['member_list'] = club_member
         return context
 
+class ClubAliasView(AliasView):
+    model = Club
+    template_name = 'member/club_alias.html'
+    context_object_name = 'club'
+
 
 class ClubUpdateView(LoginRequiredMixin, UpdateView):
     model = Club
diff --git a/templates/member/alias_update.html b/templates/member/alias_update.html
new file mode 100644
index 00000000..1555a09d
--- /dev/null
+++ b/templates/member/alias_update.html
@@ -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>
diff --git a/templates/member/club_alias.html b/templates/member/club_alias.html
new file mode 100644
index 00000000..394b1c95
--- /dev/null
+++ b/templates/member/club_alias.html
@@ -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 %}
diff --git a/templates/member/club_info.html b/templates/member/club_info.html
index d81bd870..b63c1e85 100644
--- a/templates/member/club_info.html
+++ b/templates/member/club_info.html
@@ -25,7 +25,7 @@
             <dt class="col-xl-6">{% trans 'membership fee'|capfirst %}</dt>
             <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>
 
             <dt class="col-xl-3">{% trans 'email'|capfirst %}</dt>
diff --git a/templates/member/club_picture_update.html b/templates/member/club_picture_update.html
index 70f5cf4a..4f72efec 100644
--- a/templates/member/club_picture_update.html
+++ b/templates/member/club_picture_update.html
@@ -1,10 +1,6 @@
 {% extends "member/club_detail.html" %}
 {% load i18n static pretty_money django_tables2 crispy_forms_tags %}
 
-{% block profile_info %}
-{% include "member/club_info.html" %}
-{% endblock%}
-
 {% block profile_content%}
 {% include "member/picture_update.html" %}
 {% endblock%}
diff --git a/templates/member/profile_alias.html b/templates/member/profile_alias.html
index a83d7c3e..dafc8e5a 100644
--- a/templates/member/profile_alias.html
+++ b/templates/member/profile_alias.html
@@ -2,18 +2,5 @@
 {% load i18n static pretty_money django_tables2 crispy_forms_tags %}
 
 {% block profile_content %}
-        <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>
+{% include "member/alias_update.html"%}
 {% endblock %}
diff --git a/templates/member/profile_picture_update.html b/templates/member/profile_picture_update.html
index db7c5767..4be78dc8 100644
--- a/templates/member/profile_picture_update.html
+++ b/templates/member/profile_picture_update.html
@@ -1,10 +1,6 @@
-{% extends "member/noteowner_detail.html" %}
+{% extends "member/profile_detail.html" %}
 {% load i18n static pretty_money django_tables2 crispy_forms_tags %}
 
-{% block profile_info %}
-{% include "member/profile_info.html" %}
-{% endblock%}
-
 {% block profile_content%}
 {% include "member/picture_update.html" %}
 {% endblock%}
-- 
GitLab