Reimplement proposition list
This commit is contained in:
parent
dc2cd07d93
commit
022583f0a9
4 changed files with 26 additions and 13 deletions
|
@ -5,13 +5,10 @@
|
|||
|
||||
{% block content %}
|
||||
<h1>Liste des propositions</h1>
|
||||
{% if error %}
|
||||
<p>{{ error }}</p>
|
||||
{% endif %}
|
||||
|
||||
<p><a href="{% url "propositions:create" %}">Proposer un morceau</a></p>
|
||||
|
||||
{% if n > 0 %}
|
||||
{% if propositions.exists %}
|
||||
<table>
|
||||
<tr>
|
||||
<th></th>
|
||||
|
@ -21,7 +18,7 @@
|
|||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
{% for p in props %}
|
||||
{% for p in propositions %}
|
||||
<tr class="prop">
|
||||
<td>
|
||||
{% if p.lien %}<a href={{ p.lien }}>{% endif %}<b>{{ p.nom }}</b>{% if p.artiste %} - {{ p.artiste }}{% endif %}{% if p.lien %}</a>{% endif %}</td>
|
||||
|
|
|
@ -46,3 +46,19 @@ class PropositionCreateTest(TestCase):
|
|||
self.assertEqual(proposition.user, user.profile)
|
||||
self.assertEqual(proposition.nboui, 0)
|
||||
self.assertEqual(proposition.nbnon, 0)
|
||||
|
||||
|
||||
class PropositionListTest(TestCase):
|
||||
url = reverse_lazy("propositions:list")
|
||||
|
||||
def test_anonymous_get(self):
|
||||
response = Client().get(self.url)
|
||||
self.assertRedirects(response, "/login?next={}".format(self.url))
|
||||
|
||||
def test_get(self):
|
||||
user = new_user("toto")
|
||||
client = Client()
|
||||
client.force_login(user)
|
||||
|
||||
response = client.get(self.url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
|
|
@ -5,7 +5,7 @@ from propositions import views
|
|||
|
||||
app_name = "propositions"
|
||||
urlpatterns = [
|
||||
path("", views.liste, name="list"),
|
||||
path("", views.PropositionList.as_view(), name="list"),
|
||||
path("new", views.PropositionCreate.as_view(), name="create"),
|
||||
path("<int:id>/oui", views.repoui, name="oui"),
|
||||
path("<int:id>/non", views.repnon, name="non"),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.shortcuts import redirect, get_object_or_404
|
||||
from django.urls import reverse_lazy
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic import CreateView, DeleteView
|
||||
from django.views.generic import CreateView, DeleteView, ListView
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.http import HttpResponseRedirect
|
||||
|
||||
|
@ -23,11 +23,11 @@ class PropositionCreate(LoginRequiredMixin, CreateView):
|
|||
return HttpResponseRedirect(self.success_url)
|
||||
|
||||
|
||||
@login_required
|
||||
def liste(request):
|
||||
props = Prop.objects.all().order_by('-nboui', 'nbnon', 'nom')
|
||||
n = len(props)
|
||||
return render(request, 'propositions/liste.html', locals())
|
||||
class PropositionList(LoginRequiredMixin, ListView):
|
||||
template_name = "propositions/liste.html"
|
||||
context_object_name = "propositions"
|
||||
model = Prop
|
||||
ordering = ["-nboui", "nbnon", "nom"]
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in a new issue