From 7bed4644045927f8ad4a7b1ab0de7336d428c1f1 Mon Sep 17 00:00:00 2001
From: Mutia Rahmatun Husna <mutia.rahmatun@ui.ac.id>
Date: Sat, 31 Oct 2020 22:24:33 +0700
Subject: [PATCH] [#23] Contributor: Most Contributing Author

---
 app/services.py                               |  4 ++++
 app/templates/app/includes/sidebar.html       |  5 -----
 .../app/includes/sidebar_profile.html         |  6 ++++++
 app/templates/change-password.html            |  2 +-
 app/templates/most-contributor.html           | 20 +++++++++++++++++++
 app/templates/password_reset.html             |  2 +-
 app/templates/password_reset_done.html        |  2 +-
 app/templates/password_reset_form.html        |  2 +-
 app/templates/password_reset_sent.html        |  2 +-
 app/templates/password_success.html           |  2 +-
 app/templates/user_favorite_materi.html       |  2 +-
 app/tests.py                                  | 15 +++++++++-----
 app/urls.py                                   |  3 ++-
 app/views.py                                  | 14 +++++++++++++
 14 files changed, 63 insertions(+), 18 deletions(-)
 create mode 100644 app/templates/most-contributor.html

diff --git a/app/services.py b/app/services.py
index 4ae99b5..95cbb4a 100644
--- a/app/services.py
+++ b/app/services.py
@@ -103,6 +103,10 @@ class DafterKatalogService:
         preserved = Case(*[When(pk=pk, then=pos) for pos, pk in enumerate(ids)])
         return Materi.objects.filter(id__in=ids).order_by(preserved)
 
+    # @staticmethod
+    # def get_most_contributing(lst_materi):
+
+
     @staticmethod
     def apply_random(lst_materi):
         return random.sample(list(lst_materi), len(lst_materi))
diff --git a/app/templates/app/includes/sidebar.html b/app/templates/app/includes/sidebar.html
index 69425f3..ab41216 100644
--- a/app/templates/app/includes/sidebar.html
+++ b/app/templates/app/includes/sidebar.html
@@ -31,11 +31,6 @@
             <span>Statisik Materi</span>
         </a>
     </li>
-    <li class="nav-item">
-        <a class="nav-link" href="{% url 'favorite' %}">
-            <span>Favorite Materi</span>
-        </a>
-    </li>
     <li class="nav-item">
         <a class="nav-link" href="{% url 'posts' %}">
         <span>Materi Diunggah</span></a>
diff --git a/app/templates/app/includes/sidebar_profile.html b/app/templates/app/includes/sidebar_profile.html
index d28a4c5..3b01110 100644
--- a/app/templates/app/includes/sidebar_profile.html
+++ b/app/templates/app/includes/sidebar_profile.html
@@ -32,4 +32,10 @@
         <a class="nav-link" href="/baca-nanti">
             <span>Baca Nanti</span></a>
     </li>
+
+    <li class="nav-item">
+        <a class="nav-link" href="{% url 'favorite' %}">
+            <span>Materi Favorite</span>
+        </a>
+    </li>
 </ul>
\ No newline at end of file
diff --git a/app/templates/change-password.html b/app/templates/change-password.html
index cd9bc26..1160d5f 100644
--- a/app/templates/change-password.html
+++ b/app/templates/change-password.html
@@ -1,5 +1,5 @@
 {% extends 'app/base_profile.html' %}
-{% block title %}Change Password{% endblock%}
+{% block title %}{% endblock%}
 {% block content %}
 
 
diff --git a/app/templates/most-contributor.html b/app/templates/most-contributor.html
new file mode 100644
index 0000000..62accb0
--- /dev/null
+++ b/app/templates/most-contributor.html
@@ -0,0 +1,20 @@
+{% extends "base.html" %}
+{% block content %}
+    <div class="container">
+      {% include 'app/includes/navbar_katalog_materi.html' %}
+        <br>
+        <h1>Most Contributor Author</h1>
+        {% for cont in content %}
+            <br>
+            <div class="card" style="min-width: 641px;">
+            <div class="card-body">
+                <div class="image_container">
+                    <img class="img-responsive center-block" id="card_image" src="{{news.cover.url}}" alt="{{news.id}}">
+                </div>
+                <br><br>
+                <h5 class="card-title">{{content.Author}}</h5>
+            </div>
+            </div>
+        {% endfor %}
+    </div><br><br><br>
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/password_reset.html b/app/templates/password_reset.html
index 1489085..37cafe7 100644
--- a/app/templates/password_reset.html
+++ b/app/templates/password_reset.html
@@ -1,5 +1,5 @@
 {% extends 'app/base_reset.html' %}
-{% block title %}Reset Password{% endblock%}
+{% block title %}{% endblock%}
 {% block content %}
 
 
diff --git a/app/templates/password_reset_done.html b/app/templates/password_reset_done.html
index d021c57..e8b8393 100644
--- a/app/templates/password_reset_done.html
+++ b/app/templates/password_reset_done.html
@@ -1,6 +1,6 @@
 
 {% extends 'app/base_reset.html' %}
-{% block title %}Password reset complete{% endblock%}
+{% block title %}{% endblock%}
 {% block content %}
 
 
diff --git a/app/templates/password_reset_form.html b/app/templates/password_reset_form.html
index 73e68f5..f6ca8fa 100644
--- a/app/templates/password_reset_form.html
+++ b/app/templates/password_reset_form.html
@@ -1,5 +1,5 @@
 {% extends 'app/base_reset.html' %}
-{% block title %}Enter new password{% endblock%}
+{% block title %}{% endblock%}
 {% block content %}
 
 
diff --git a/app/templates/password_reset_sent.html b/app/templates/password_reset_sent.html
index 12542b5..dd01216 100644
--- a/app/templates/password_reset_sent.html
+++ b/app/templates/password_reset_sent.html
@@ -1,6 +1,6 @@
 
 {% extends 'app/base_reset.html' %}
-{% block title %}Password reset sent{% endblock%}
+{% block title %}{% endblock%}
 {% block content %}
 
 
diff --git a/app/templates/password_success.html b/app/templates/password_success.html
index 3c61031..d097463 100644
--- a/app/templates/password_success.html
+++ b/app/templates/password_success.html
@@ -1,5 +1,5 @@
 {% extends 'app/base_profile.html' %}
-{% block title %}Change Password{% endblock%}
+{% block title %}{% endblock%}
 {% block content %}
 
 
diff --git a/app/templates/user_favorite_materi.html b/app/templates/user_favorite_materi.html
index 7ca9ccf..78c9415 100644
--- a/app/templates/user_favorite_materi.html
+++ b/app/templates/user_favorite_materi.html
@@ -1,4 +1,4 @@
-{% extends 'app/base_dashboard.html' %}
+{% extends 'app/base_profile.html' %}
 {% load static %}
 
 {% block title %}
diff --git a/app/tests.py b/app/tests.py
index d65e62e..f428616 100644
--- a/app/tests.py
+++ b/app/tests.py
@@ -295,13 +295,18 @@ class DaftarKatalogPerKontributorTest(TestCase):
         found = resolve(self.url)
         self.assertEqual(found.func.__name__, KatalogPerKontributorView.as_view().__name__)
 
-    def test_katalog_per_kontributor_show_daftar_materi_kontributor(self):
-        response = self.client.get(self.url)
+    # def test_katalog_per_kontributor_show_daftar_materi_kontributor(self):
+    #     response = self.client.get(self.url)
 
-        list_materi = Materi.objects.filter(uploader=self.contributor)
-        data = response.context_data["materi_list"]
-        self.assertEqual(len(list_materi), len(data))
+    #     list_materi = Materi.objects.filter(uploader=self.contributor)
+    #     data = response.context_data["materi_list"]
+    #     self.assertEqual(len(list_materi), len(data))
 
+    def test_count_materi_per_contributor(self):
+        response = self.client.get(self.url)
+        list_materi = Materi.objects.filter(uploader=self.contributor)
+        jumlah = response.context_data["materi_list"]
+        self.assertEqual(len(list_materi), len(jumlah))
 
 class DetailMateriTest(TestCase):
     def _get_materi_info_html(self, info_name, info_value):
diff --git a/app/urls.py b/app/urls.py
index 9df11eb..b48be94 100644
--- a/app/urls.py
+++ b/app/urls.py
@@ -6,7 +6,7 @@ from app.views import (DashboardKontributorView, ProfilView, StatisticsView,
                        SuksesLoginAdminView, SuksesLoginKontributorView, DownloadHistoryView,
                        SuntingProfilView, UploadMateriHTML, UploadMateriView, UploadMateriExcelView, PostsView,
                        ReqMateriView, KatalogPerKontributorView, MateriFavorite, PasswordChangeViews, password_success, 
-                       SubmitVisitorView, ReadLaterView)
+                       SubmitVisitorView, ReadLaterView, MostContributor)
 
 
 urlpatterns = [
@@ -57,4 +57,5 @@ urlpatterns = [
     path("reset_password_complete/", 
         auth_views.PasswordResetCompleteView.as_view(template_name="password_reset_done.html"), 
         name="password_reset_complete"),
+    path("most-contributor/", MostContributor.as_view(), name="most-contributor")
 ]
diff --git a/app/views.py b/app/views.py
index cb0be08..cd6be9c 100644
--- a/app/views.py
+++ b/app/views.py
@@ -876,3 +876,17 @@ class StatisticsView(TemplateView):
             context['stats'] = query
 
             return self.render_to_response(context)
+
+class MostContributor(TemplateView):
+    template_name = "most-contributor.html"
+
+    def dispatch(self, request, *args, **kwargs):
+        if not request.user.is_authenticated:
+            raise PermissionDenied(request)
+        return super(MostContributor, self).dispatch(request, *args, **kwargs)
+
+    def count_contributor(self):
+        count_materi = Materi.objects.all.count()
+        content = {'count_materi':count_materi}
+        print(content)
+        return content
-- 
GitLab