diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-04-15 22:02:30 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-04-15 22:02:30 -0400 |
commit | 2ea4e6f4d5245dd5e43c90d54635477c6e7dd6a7 (patch) | |
tree | d0994cde414fffd3389d036f5a043327aae3af39 | |
parent | 05430050147c87818c08373e9930756da4d6b5ac (diff) | |
parent | e5fc7cd53f6082f2911bc6c8cf8ea4f4ca4addc8 (diff) |
Merge tag 'release_2014-11-08.2' into archweb-generic
Todolist pagination and sitemap, news sitemap
-rw-r--r-- | news/urls.py | 3 | ||||
-rw-r--r-- | sitemaps.py | 29 | ||||
-rw-r--r-- | sitestatic/archweb.css | 11 | ||||
-rw-r--r-- | templates/news/list.html | 3 | ||||
-rw-r--r-- | templates/sitemaps/news_sitemap.xml.jinja | 14 | ||||
-rw-r--r-- | templates/sitemaps/sitemap.xml.jinja | 9 | ||||
-rw-r--r-- | templates/todolists/list.html | 7 | ||||
-rw-r--r-- | templates/todolists/paginator.html | 22 | ||||
-rw-r--r-- | todolists/urls.py | 6 | ||||
-rw-r--r-- | todolists/views.py | 13 | ||||
-rw-r--r-- | urls.py | 10 |
11 files changed, 112 insertions, 15 deletions
diff --git a/news/urls.py b/news/urls.py index 0eec6d86..c13722d4 100644 --- a/news/urls.py +++ b/news/urls.py @@ -5,8 +5,7 @@ from .views import (NewsDetailView, NewsListView, urlpatterns = patterns('news.views', - (r'^$', - NewsListView.as_view(), {}, 'news-list'), + (r'^$', NewsListView.as_view(), {}, 'news-list'), (r'^preview/$', 'preview'), # old news URLs, permanent redirect view so we don't break all links diff --git a/sitemaps.py b/sitemaps.py index eb4e05d9..03ad9254 100644 --- a/sitemaps.py +++ b/sitemaps.py @@ -8,6 +8,7 @@ from main.models import Package from news.models import News from packages.utils import get_group_info, get_split_packages_info from releng.models import Release +from todolists.models import Todolist class PackagesSitemap(Sitemap): @@ -98,6 +99,13 @@ class NewsSitemap(Sitemap): return 'yearly' +class RecentNewsSitemap(NewsSitemap): + def items(self): + now = datetime.utcnow().replace(tzinfo=utc) + cutoff = now - timedelta(days=30) + return super(RecentNewsSitemap, self).items().filter(postdate__gte=cutoff) + + class ReleasesSitemap(Sitemap): changefreq = "monthly" @@ -105,7 +113,7 @@ class ReleasesSitemap(Sitemap): return Release.objects.all().defer('info', 'torrent_data').order_by() def lastmod(self, obj): - return obj.created + return obj.last_modified def priority(self, obj): if obj.available: @@ -113,6 +121,25 @@ class ReleasesSitemap(Sitemap): return "0.2" +class TodolistSitemap(Sitemap): + priority = "0.4" + + def __init__(self): + now = datetime.utcnow().replace(tzinfo=utc) + self.two_weeks_ago = now - timedelta(days=14) + + def items(self): + return Todolist.objects.all().defer('raw').order_by() + + def lastmod(self, obj): + return obj.last_modified + + def changefreq(self, obj): + if obj.last_modified > self.two_weeks_ago: + return 'weekly' + return 'monthly' + + class BaseSitemap(Sitemap): DEFAULT_PRIORITY = 0.7 diff --git a/sitestatic/archweb.css b/sitestatic/archweb.css index edabcfb7..cd46e4c0 100644 --- a/sitestatic/archweb.css +++ b/sitestatic/archweb.css @@ -655,6 +655,17 @@ div.news-article .article-info { width: 75%; } +/* todolists: list */ +.todolist-nav { + float: right; + margin-top: -2.2em; +} + + .todolist-nav .prev, + .todolist-nav .next { + margin: 0 1em; + } + /* donate: donor list */ #donor-list ul { width: 100%; diff --git a/templates/news/list.html b/templates/news/list.html index 3295e333..93cd20e6 100644 --- a/templates/news/list.html +++ b/templates/news/list.html @@ -10,7 +10,7 @@ {% block content %} <div id="news-article-list" class="box"> - <h2>News Archives</h2> + <h2>Arch Linux News Archives</h2> {% if perms.news.add_news %} <ul class="admin-actions"> @@ -54,6 +54,5 @@ </table> {% include "news/paginator.html" %} - </div> {% endblock %} diff --git a/templates/sitemaps/news_sitemap.xml.jinja b/templates/sitemaps/news_sitemap.xml.jinja new file mode 100644 index 00000000..97dd17b5 --- /dev/null +++ b/templates/sitemaps/news_sitemap.xml.jinja @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"> +{% for url in urlset %}<url> +<loc>{{ url.location }}</loc> +{% if url.lastmod %}<lastmod>{{ url.lastmod|date("Y-m-d") }}</lastmod>{% endif %} +{% if url.changefreq %}<changefreq>{{ url.changefreq }}</changefreq>{% endif %} +{% if url.priority %}<priority>{{ url.priority }}</priority>{% endif %} +<news:news> + <news:publication><news:name>Arch Linux News</news:name><news:language>en</news:language></news:publication> + {% if url.item.postdate %}<news:publication_date>{{ url.item.postdate|date("c") }}</news:publication_date>{% endif %} + {% if url.item.title %}<news:title>{{ url.item.title }}</news:title>{% endif %} +</news:news> +</url>{% endfor %} +</urlset> diff --git a/templates/sitemaps/sitemap.xml.jinja b/templates/sitemaps/sitemap.xml.jinja new file mode 100644 index 00000000..0808a7de --- /dev/null +++ b/templates/sitemaps/sitemap.xml.jinja @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> +{% for url in urlset %}<url> +<loc>{{ url.location }}</loc> +{% if url.lastmod %}<lastmod>{{ url.lastmod|date("Y-m-d") }}</lastmod>{% endif %} +{% if url.changefreq %}<changefreq>{{ url.changefreq }}</changefreq>{% endif %} +{% if url.priority %}<priority>{{ url.priority }}</priority>{% endif %} +</url>{% endfor %} +</urlset> diff --git a/templates/todolists/list.html b/templates/todolists/list.html index 0f1ccfd7..5cfd6a02 100644 --- a/templates/todolists/list.html +++ b/templates/todolists/list.html @@ -16,7 +16,10 @@ <p>Todo lists are used by the developers when a rebuild of a set of packages is needed. This is common when a library has a version bump, during a toolchain rebuild, or a general cleanup of packages in the - repositories. The progress can be tracked here.</p> + repositories. The progress can be tracked here, and completed todo lists + can be browsed as well.</p> + + {% include "todolists/paginator.html" %} <table id="dev-todo-lists" class="results todo-table"> <thead> @@ -46,6 +49,8 @@ {% endfor %} </tbody> </table> + + {% include "todolists/paginator.html" %} </div> {% endblock %} diff --git a/templates/todolists/paginator.html b/templates/todolists/paginator.html new file mode 100644 index 00000000..3b077419 --- /dev/null +++ b/templates/todolists/paginator.html @@ -0,0 +1,22 @@ +{% if is_paginated %} +<div class="pagination"> + <p>{{ paginator.count }} todo lists, viewing page {{ page_obj.number }} of {{ paginator.num_pages }}.</p> + <p class="todolist-nav"> + {% if page_obj.has_previous %} + <a class="prev" href="?page={{ page_obj.previous_page_number }}" + title="Go to previous page">< Prev</a> + {% endif %} + {% for num in paginator.page_range %} + {% ifequal num page_obj.number %} + <span>{{ num }}</span> + {% else %} + <a href="?page={{ num }}" title="Go to page {{ num }}">{{ num }}</a> + {% endifequal %} + {% endfor %} + {% if page_obj.has_next %} + <a class="next" href="?page={{ page_obj.next_page_number }}" + title="Go to next page">Next ></a> + {% endif %} + </p> +</div> +{% endif %} diff --git a/todolists/urls.py b/todolists/urls.py index 6617d7dd..ed065f50 100644 --- a/todolists/urls.py +++ b/todolists/urls.py @@ -1,11 +1,11 @@ from django.conf.urls import patterns from django.contrib.auth.decorators import permission_required -from .views import (view_redirect, view, todolist_list, add, edit, flag, - list_pkgbases, DeleteTodolist) +from .views import (view_redirect, view, add, edit, flag, + list_pkgbases, DeleteTodolist, TodolistListView) urlpatterns = patterns('', - (r'^$', todolist_list), + (r'^$', TodolistListView.as_view(), {}, 'todolist-list'), # old todolists URLs, permanent redirect view so we don't break all links (r'^(?P<old_id>\d+)/$', view_redirect), diff --git a/todolists/views.py b/todolists/views.py index cdbfa702..db6f20f0 100644 --- a/todolists/views.py +++ b/todolists/views.py @@ -8,7 +8,7 @@ from django.shortcuts import (get_list_or_404, get_object_or_404, redirect, render) from django.db import transaction from django.views.decorators.cache import never_cache -from django.views.generic import DeleteView +from django.views.generic import DeleteView, ListView from django.template import Context, loader from django.utils.timezone import now @@ -92,10 +92,13 @@ def list_pkgbases(request, slug, svn_root): return HttpResponse('\n'.join(pkgbases), content_type='text/plain') -def todolist_list(request): - incomplete_only = request.user.is_anonymous() - lists = get_annotated_todolists(incomplete_only) - return render(request, 'todolists/list.html', {'lists': lists}) +class TodolistListView(ListView): + context_object_name = "lists" + template_name = "todolists/list.html" + paginate_by = 50 + + def get_queryset(self): + return get_annotated_todolists() @never_cache @@ -16,8 +16,11 @@ our_sitemaps = { 'package-groups': sitemaps.PackageGroupsSitemap, 'split-packages': sitemaps.SplitPackagesSitemap, 'releases': sitemaps.ReleasesSitemap, + 'todolists': sitemaps.TodolistSitemap, } +news_sitemaps = { 'news': sitemaps.RecentNewsSitemap } + urlpatterns = [] # Public pages @@ -81,7 +84,12 @@ urlpatterns += patterns('', {'sitemaps': our_sitemaps, 'sitemap_url_name': 'sitemaps'}), (r'^sitemap-(?P<section>.+)\.xml$', cache_page(1831)(sitemap_views.sitemap), - {'sitemaps': our_sitemaps}, 'sitemaps'), + {'sitemaps': our_sitemaps, 'template_name': 'sitemaps/sitemap.xml.jinja'}, + 'sitemaps'), + (r'^news-sitemap\.xml$', + cache_page(1831)(sitemap_views.sitemap), + {'sitemaps': news_sitemaps, 'template_name': 'sitemaps/news_sitemap.xml.jinja'}, + 'news-sitemap'), ) # Authentication / Admin |