keep archive per year, don't call it archive
This commit is contained in:
parent
d995ea0c6f
commit
cf2efd7fb3
8 changed files with 72 additions and 17 deletions
|
|
@ -35,7 +35,8 @@ def index(request):
|
|||
now = None
|
||||
week, archive = models.Item.public(now)
|
||||
context['items'] = week
|
||||
context['archive'] = archive.exists()
|
||||
if archive.exists():
|
||||
context['archive'] = '/_%s/' % now.year
|
||||
if now:
|
||||
context['now'] = now
|
||||
context['previous_week'] = (now - timedelta(days=7)).strftime(TS_FORMAT)
|
||||
|
|
@ -43,7 +44,7 @@ def index(request):
|
|||
return render(request, 'index.html', context)
|
||||
|
||||
|
||||
def archive(request, week=None):
|
||||
def archive(request, year=None, week=None):
|
||||
context = default_context(request)
|
||||
qs = models.Item.public()
|
||||
week, archive = models.Item.public()
|
||||
|
|
@ -71,7 +72,9 @@ def item(request, id):
|
|||
comments = []
|
||||
for comment in qs:
|
||||
comments.append(comment.json())
|
||||
context['comments'] = mark_safe(json.dumps(comments))
|
||||
context['comments'] = mark_safe(json.dumps(comments, ensure_ascii=False))
|
||||
context['comments'] = json.dumps(comments, ensure_ascii=False)
|
||||
|
||||
user = {}
|
||||
if request.user.is_staff:
|
||||
user['is_moderator'] = True
|
||||
|
|
@ -80,6 +83,17 @@ def item(request, id):
|
|||
|
||||
context['user'] = mark_safe(json.dumps(user))
|
||||
request.session['item'] = id
|
||||
qs = models.Item.objects.exclude(published=None).exclude(id=item.id)
|
||||
if not request.user.is_staff:
|
||||
now = get_now()
|
||||
qs = qs.filter(published__lt=now)
|
||||
previous_item = qs.exclude(published__gt=item.published).order_by('-published').first()
|
||||
next_item = qs.exclude(published__lt=item.published).order_by('published').first()
|
||||
if next_item:
|
||||
context['next'] = next_item.get_absolute_url()
|
||||
if previous_item:
|
||||
context['previous'] = previous_item.get_absolute_url()
|
||||
|
||||
return render(request, 'item.html', context)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue