Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion articles/templates/articles/author.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{% extends 'base.html' %}

{% block header %}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
{% endblock %}

{% block content %}
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1>{{ author.name }}</h1>
<h2>今まで書いた記事</h2>
<h3>今まで書いた記事</h2>
<table class="table">
<thead>
<tr>
Expand All @@ -21,6 +24,9 @@ <h2>今まで書いた記事</h2>
<td>
<a href="{{ article.url }}" target="_blank">{{ article.title }}</a>
</td>
<td>
{{ article.id }}
</td>
</tr>
{% endfor %}
</tbody>
Expand Down
69 changes: 69 additions & 0 deletions articles/templates/articles/author_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% extends 'base.html' %}

{% block content %}
<div class="container">
<div class="row">
<div class="col-xs-12">
<table class="table">
<thead>
<tr>
<th>Rank</th>
<th>Name</th>
<th>Rate</th>
</tr>
</thead>
<tbody>
{% for author in authors %}
<tr>
<td>{{ forloop.counter0|add:authors.start_index }}</td>
<td>
<a href="{% url 'author' author.id %}">{{ author.name }}</a>
</td>
<td>{{ author.rate }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<!--<div class="pagination">
<span class="step-links">
{% if authors.has_previous %}
<a href="?page={{ authors.previous_page_number }}">previous</a>
{% endif %}

<span class="current">
Page {{ authors.number }} of {{ authors.paginator.num_pages }}.
</span>

{% if authors.has_next %}
<a href="?page={{ authors.next_page_number }}">next</a>
{% endif %}
</span>
</div>
-->

<ul class="pagination">
{% if authors.has_previous %}
<li><a href="?page={{ authors.previous_page_number }}">&laquo;</a></li>
{% else %}
<li class="disabled"><a href="#">&laquo;</a></li>
{% endif %}

{% for num in authors.paginator.page_range %}
{% ifequal num authors.number %}
<li class="active"><a href="#">{{ num }}<span class="sr-only">(current)</span></a></li>
{% else %}
<li><a href="?page={{ num }}">{{ num }}</a></li>
{% endifequal %}
{% endfor %}

{% if authors.has_next %}
<li><a href="?page={{ authors.next_page_number }}">&raquo;</a></li>
{% else %}
<li class="disabled"><a href="#">&raquo;</a></li>
{% endif %}
<ul>
</div>

{% endblock %}
29 changes: 19 additions & 10 deletions articles/views.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
from django.shortcuts import render

# Create your views here.

from django.views.generic import ListView
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from .models import Authors
from .models import Articles


def index(request):
authors = Authors.objects.order_by('-rate')
context = {
'authors': authors
}
return render(request, 'articles/index.html', context)

def author(request, author_id):
author = Authors.objects.filter(id=author_id)[0]
articles = Articles.objects.filter(author__id=author_id).order_by('-pub_date')
Expand All @@ -23,3 +15,20 @@ def author(request, author_id):
return render(request, 'articles/author.html', context)


def index(request):
authors = Authors.objects.order_by('-rate')
paginator = Paginator(authors, 25)
page = request.GET.get('page')

try:
extacted_authors = paginator.page(page)
except PageNotAnInteger:
extacted_authors = paginator.page(1)
except EmptyPage:
extacted_authors = paginator.page(paginator.num_pages)
context = {
'authors': extacted_authors,
}
return render(request, 'articles/author_list.html', context)