Set article to be displayed in reverse creation_date order
Fix a bug in navigation bar Rework on archive (there is still a bug)
This commit is contained in:
parent
8bb10fc1e1
commit
4277d28c9d
|
@ -22,6 +22,7 @@ class Archive(Index):
|
|||
filename = self.filename + '.html'
|
||||
self.nb_pages = 0
|
||||
self.cur_page = 0
|
||||
self.cur_article = 0
|
||||
if len(articles) > self.articles_per_page:
|
||||
self.nb_pages = len(articles) / self.articles_per_page
|
||||
|
||||
|
@ -37,15 +38,15 @@ class Archive(Index):
|
|||
filename = self.filename + str(self.cur_page) + '.html'
|
||||
dom = parse(src + '/_archive.html')
|
||||
|
||||
while os.path.exists(filename):
|
||||
while os.path.exists(filename):
|
||||
self.addReport('Removing unused ' + filename)
|
||||
os.unlink(filename)
|
||||
filename = filename + '.gz'
|
||||
if os.path.exists(filename):
|
||||
self.addReport('Removing unused ' + filename)
|
||||
os.unlink(filename)
|
||||
filename = filename + '.gz'
|
||||
if os.path.exists(filename):
|
||||
self.addReport('Removing unused ' + filename)
|
||||
os.unlink(filename)
|
||||
self.cur_page = self.cur_page + 1
|
||||
filename = output + '/archive/' + str(self.cur_year) + '/' + self.filename + str(self.cur_page) + '.html'
|
||||
self.cur_page = self.cur_page + 1
|
||||
filename = output + '/archive/' + str(self.cur_year) + '/' + self.filename + str(self.cur_page) + '.html'
|
||||
|
||||
def generate(self, blog, src, output):
|
||||
from dynastie.models import Article, Blog
|
||||
|
@ -76,26 +77,32 @@ class Archive(Index):
|
|||
else:
|
||||
self.addError('No tag dyn:articles found')
|
||||
|
||||
articles = Article.objects.all()
|
||||
articles = Article.objects.all().order_by('creation_date')
|
||||
|
||||
if articles.count() != 0:
|
||||
self.cur_year = articles[0].creation_date.year
|
||||
self.cur_year = int(articles[0].creation_date.year)
|
||||
|
||||
my_articles = []
|
||||
now = datetime.now()
|
||||
for article in articles:
|
||||
nb_articles = len(articles)
|
||||
for i in range(0, nb_articles):
|
||||
if self.cur_year == now.year:
|
||||
break
|
||||
|
||||
if article.creation_date.year != self.cur_year:
|
||||
self.createArchives(src, output, dom, hooks, my_articles)
|
||||
self.cur_year = article.creation_date.year
|
||||
#print 'New year ' + str(self.cur_year)
|
||||
if self.cur_year == now.year:
|
||||
continue
|
||||
my_articles = []
|
||||
if i < nb_articles-1:
|
||||
if articles[i].creation_date.year != articles[i+1].creation_date.year:
|
||||
self.createArchives(src, output, dom, hooks, my_articles)
|
||||
self.cur_year = int(articles[i+1].creation_date.year)
|
||||
#print 'New year ' + str(self.cur_year)
|
||||
my_articles = []
|
||||
if self.cur_year == int(now.year):
|
||||
break
|
||||
else:
|
||||
my_articles.append(articles[i])
|
||||
else:
|
||||
my_articles.append(article)
|
||||
if nb_articles != 1 and articles[i].creation_date.year != articles[i-1].creation_date.year:
|
||||
self.cur_year = int(articles[i].creation_date.year)
|
||||
|
||||
if len(my_articles) != 0:
|
||||
self.createArchives(src, output, dom, hooks, my_articles)
|
||||
|
|
|
@ -54,7 +54,7 @@ class Category(Index):
|
|||
self.cur_category = category
|
||||
self.filename = category.name_slug
|
||||
filename = self.filename + '.html'
|
||||
articles = Article.objects.filter(category__exact=category)
|
||||
articles = Article.objects.filter(category__exact=category).order_by('-creation_date')
|
||||
|
||||
self.nb_pages = 0
|
||||
self.cur_page = 0
|
||||
|
|
|
@ -30,6 +30,11 @@ class Index(DynastieGenerator):
|
|||
if end > self.nb_pages+1:
|
||||
end = self.nb_pages+1
|
||||
|
||||
if (end-start) < 10:
|
||||
start = end - 10
|
||||
if start < 0:
|
||||
start = 0
|
||||
|
||||
for i in range(start, end):
|
||||
if i == self.cur_page:
|
||||
nav = nav + str(i+1) + ' '
|
||||
|
@ -120,7 +125,7 @@ class Index(DynastieGenerator):
|
|||
|
||||
now = datetime.datetime.now()
|
||||
cur_year = now.year
|
||||
articles = Article.objects.filter(creation_date__year=cur_year)
|
||||
articles = Article.objects.filter(creation_date__year=cur_year).order_by('-creation_date')
|
||||
|
||||
if articles.count() < self.articles_per_page:
|
||||
articles = Article.objects.all()[:self.articles_per_page]
|
||||
|
|
6
views.py
6
views.py
|
@ -206,7 +206,7 @@ def view_blog(request, blog_id):
|
|||
if b is None:
|
||||
raise Http404
|
||||
|
||||
articles = Article.objects.filter(blog=b)
|
||||
articles = Article.objects.filter(blog=b).order_by('-creation_date')
|
||||
b = Blog.objects.get(pk=blog_id)
|
||||
form = BlogForm(instance=b)
|
||||
|
||||
|
@ -237,7 +237,7 @@ def edit_blog(request, blog_id):
|
|||
else:
|
||||
form = BlogForm(instance=b) # An unbound form
|
||||
|
||||
articles = Article.objects.filter(blog=b)
|
||||
articles = Article.objects.filter(blog=b).order_by('-creation_date')
|
||||
|
||||
c = {'blog' : b, 'articles' : articles, 'form' : form}
|
||||
|
||||
|
@ -351,7 +351,7 @@ def generate(request, blog_id):
|
|||
b.create_paths()
|
||||
report = b.generate()
|
||||
|
||||
articles = Article.objects.filter(blog=b)
|
||||
articles = Article.objects.filter(blog=b).order_by('-creation_date')
|
||||
b = Blog.objects.get(pk=blog_id)
|
||||
form = BlogForm(instance=b)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user