예제 #1
0
파일: views.py 프로젝트: ringchhenlama/CMS
    def get_context_data(self, *args, **kwargs):
        ctx = super().get_context_data(**kwargs)
        ctx['pages_menu'] = Page.objects.exclude(is_menu=False)
        try:
            ctx['company_info'] = Appearance.objects.all().first()
        except ObjectDoesNotExist:
            ctx['company_info'] = None
        ctx['socialsite_info'] = Socialsite.objects.all()
        try:
            ctx['blog'] = BlogTitle.objects.first()
        except ObjectDoesNotExist:
            ctx['blog'] = None
        try:
            ctx['popular_posts_qs'] = BlogPost.all_post(
                check_deadline=True).order_by('-count')[:4]
        except ObjectDoesNotExist:
            ctx['popular_posts_qs'] = None

        try:
            ctx['notices'] = Notice.objects.all()[:3]
        except ObjectDoesNotExist:
            ctx['notices'] = None
        ctx['footer_links'] = Page.objects.filter(is_footer_link=True)

        return ctx
예제 #2
0
def get_posts_by_category(category, check_deadline=False):
    return BlogPost.all_post(check_deadline=check_deadline).filter(category=category)[:6]
예제 #3
0
def get_count_posts_by_month(month, year):
    return BlogPost.all_post().filter(created_at__month=month, created_at__year=year).count()
예제 #4
0
def get_recent_blogs(count=5):
    return {'blogs': BlogPost.all_post(check_deadline=True)[:count]}