Commit 83976145 authored by Arthur Del Esposte's avatar Arthur Del Esposte

Display subscribed packages on user's profile through package tables

parent 1c98e84f
Pipeline #26664 passed with stage
in 6 minutes and 17 seconds
......@@ -7,6 +7,9 @@
<li class="nav-item {% if active_element == 'subscriptions' %}active{% endif %}">
<a class="nav-link" href="{% url 'dtracker-accounts-subscriptions' %}">Subscriptions</a>
</li>
<li class="nav-item {% if active_element == 'subscriptions-table' %}active{% endif %}">
<a class="nav-link" href="{% url 'dtracker-accounts-subscriptions-table' %}">Packages Table</a>
</li>
<li class="nav-item {% if active_element == 'change-profile' %}active{% endif %}">
<a class="nav-link" href="{% url 'dtracker-accounts-profile-modify' %}">Personal Information</a>
</li>
......
{% extends 'core/base.html' %}
{% load staticfiles %}
{% load distro_tracker_extras %}
{% block title %}Subscriptions Table | {{ block.super }}{% endblock %}
{% block extra-js %}
<script src="{% static 'accounts/js/profile.js' %}"></script>
<script type="text/x-dtracker-url" id="unsubscribe-url">{% url 'dtracker-api-accounts-unsubscribe' %}</script>
<script type="text/x-dtracker-url" id="unsubscribe-all-url">{% url 'dtracker-api-accounts-unsubscribe-all' %}</script>
<script type="text/x-dtracker-url" id="all-keywords-url">{% url 'dtracker-api-keywords' %}</script>
<script type="text/x-dtracker-url" id="update-keywords-url">{% url 'dtracker-api-accounts-profile-keywords' %}</script>
{% endblock %}
{% block content %}
{% include 'accounts/profile-navbar.html' with active_element='subscriptions-table' %}
<div class="package-tables m-y-1">
<div class="row">
<div class="col-md-12 team-tables" id="dtracker-package-center">
{% for table in tables %}
{% with rows_length=table.rows|length %}
{% if table.number_of_packages > rows_length %}
{% include 'core/package-table.html' with table=table show_link=1 %}
{% else %}
{% include 'core/package-table.html' with table=table %}
{% endif %}
{% endwith %}
{% endfor %}
</div>
</div>
</div>
{% endblock %}
......@@ -22,7 +22,7 @@ from distro_tracker.core.models import (
SourcePackageName,
Subscription
)
from distro_tracker.test import TestCase
from distro_tracker.test import TestCase, UserAuthMixin
class UserManagerTests(TestCase):
......@@ -271,6 +271,51 @@ class SubscriptionsViewTests(TestCase):
[sub.package.name for sub in entry['subscriptions']])
class SubscriptionsTableViewTests(UserAuthMixin, TestCase):
"""
Tests the :class:`distro_tracker.accounts.SubscriptionsTableView`.
"""
def setUp(self):
self.setup_users(login=True)
self.package_name = PackageName.objects.create(name='dummy-package')
self.user = self.current_user
def get_subscriptions_table_view(self):
return self.client.get(reverse('dtracker-accounts-subscriptions-table'))
def subscribe_email_to_package(self, email, package_name):
Subscription.objects.create_for(
email=email,
package_name=package_name.name)
def test_no_subscriptions(self):
"""
Tests the scenario where the user has no subscriptions.
"""
response = self.get_subscriptions_table_view()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'accounts/subscriptions-table.html')
table = response.context['tables'][0]
self.assertEqual(len(table.rows), 0)
self.assertEqual(table.title, "Subscribed Packages")
def test_with_subscriptions(self):
"""
Tests the scenario where the user has subscriptions.
"""
self.subscribe_email_to_package(self.user.main_email, self.package_name)
response = self.get_subscriptions_table_view()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'accounts/subscriptions-table.html')
table = response.context['tables'][0]
self.assertEqual(len(table.rows), 1)
self.assertEqual(table.title, "Subscribed Packages")
self.assertIn(self.package_name, table.packages)
class UserEmailsViewTests(TestCase):
"""
Tests for the :class:`distro_tracker.accounts.views.UserEmailsView` view.
......
......@@ -28,6 +28,7 @@ from distro_tracker.core.models import (
Subscription,
get_web_package
)
from distro_tracker.core.package_tables import create_table
from distro_tracker.core.utils import (
distro_tracker_render_to_string,
render_to_json_response
......@@ -171,6 +172,28 @@ class SubscriptionsView(LoginRequiredMixin, View):
})
class SubscriptionsTableView(LoginRequiredMixin, View):
"""
Displays a user's subscribed packages.
This only includes direct package subscriptions.
"""
template_name = 'accounts/subscriptions-table.html'
def _create_tables(self, user):
return [
create_table(
slug='general', scope=user, title='Subscribed Packages'),
create_table(slug='general', scope=user, tag='tag:bugs'),
]
def get(self, request):
user = request.user
return render(request, self.template_name, {
'tables': self._create_tables(user)
})
class UserEmailsView(LoginRequiredMixin, View):
"""
Returns a JSON encoded list of the currently logged in user's emails.
......
......@@ -37,6 +37,7 @@ from distro_tracker.accounts.views import (
ResetPasswordView,
SubscribeUserToPackageView,
SubscriptionsView,
SubscriptionsTableView,
UnsubscribeAllView,
UnsubscribeUserView,
UserEmailsView
......@@ -159,6 +160,9 @@ urlpatterns = [
url(r'^accounts/subscriptions/$',
SubscriptionsView.as_view(),
name='dtracker-accounts-subscriptions'),
url(r'^accounts/subscriptions-table/$',
SubscriptionsTableView.as_view(),
name='dtracker-accounts-subscriptions-table'),
url(r'^accounts/profile/subscriptions/choose-subscription-email/$',
ChooseSubscriptionEmailView.as_view(),
name='dtracker-accounts-choose-email'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment