move empty pub handling to view

main
eric 2023-05-09 17:52:41 -04:00
parent 4ae248e242
commit 151f659da6
2 changed files with 10 additions and 6 deletions

View File

@ -13,10 +13,10 @@ DOAB Link Checking Problems by Publisher
<th>Publisher</th>
<th>Number</th>
</tr>
{% for pub, numbad in pubs %}
{% for pub in pubs %}
<tr style="color:red">
<td> <a href="{% url 'publisher' pub | default: '*** no publisher name ***' %}">{{ pub | default: '*** no publisher name ***' }}</a> </td>
<td> {{ numbad }} </td>
<td> <a href="{% url 'publisher' pub.0 %}">{{ pub.0 }}</a> </td>
<td> {{ pub.1 }} </td>
</tr>
{% endfor %}
</table>

View File

@ -9,7 +9,7 @@ from django.views import generic
from .models import Item, Link
NOPUBNAME = '*** no publisher name ***'
class HomepageView(generic.TemplateView):
template_name = 'index.html'
@ -92,7 +92,11 @@ class ProblemPublishersView(generic.TemplateView):
for link in problinks:
pub = link.items.filter(status=1).first().publisher_name
probpubs[pub] = probpubs.get(pub, 0) + 1
return {'pubs': sorted(probpubs.items(), key=lambda x: x[0]) }
pubs = sorted(probpubs.items(), key=lambda x: x[0])
def fixempty(publist):
for k, v in publist:
yield (NOPUBNAME if not k else k), v
return {'pubs': fixempty(pubs)}
class PublisherView(generic.TemplateView):
@ -101,7 +105,7 @@ class PublisherView(generic.TemplateView):
def get_context_data(self, **kwargs):
pub = kwargs['publisher']
publisher = {'publisher': pub}
if pub == '*** no publisher name ***':
if pub == NOPUBNAME:
pub = ''
publisher_items = Item.objects.filter(
publisher_name=pub, status=1,