diff --git a/app/item/models.py b/app/item/models.py index 1d7baec..ef325eb 100644 --- a/app/item/models.py +++ b/app/item/models.py @@ -59,10 +59,18 @@ class Item(models.Model): return json.dumps(comments) @classmethod - def public(cls, now=None): + def all_public(cls, now=None): if now is None: now = timezone.make_aware(datetime.now(), timezone.get_default_timezone()) qs = cls.objects.exclude(published=None).filter(published__lte=now).order_by('-published') + archive = qs.annotate(year=ExtractYear('published')).annotate(week=ExtractWeek('published')) + return archive + + @classmethod + def public(cls, now=None): + if now is None: + now = timezone.make_aware(datetime.now(), timezone.get_default_timezone()) + qs = cls.all_public(now) cal = now.date().isocalendar() monday = now.date() - timedelta(days=now.date().isocalendar().weekday - 1) monday = timezone.datetime(monday.year, monday.month, monday.day, tzinfo=now.tzinfo) @@ -77,11 +85,7 @@ class Item(models.Model): else: last_monday = monday - timedelta(days=7) week = qs.filter(published__gt=last_monday) - archive = (qs - .exclude(id__in=week) - .annotate(year=ExtractYear('published')) - .annotate(week=ExtractWeek('published')) - ) + archive = qs.exclude(id__in=week) return week, archive def get_week(self): diff --git a/app/item/views.py b/app/item/views.py index d31247d..d9800d5 100644 --- a/app/item/views.py +++ b/app/item/views.py @@ -77,7 +77,7 @@ def index(request): def archive(request, year=None, month=None, day=None, week=None): context = default_context(request) - _, archive = models.Item.public() + archive = models.Item.all_public() if year and month and day: date = datetime.strptime('%s-%s-%s' % (year, month, day), '%Y-%m-%d') week = int(date.strftime('%W'))