예제 #1
0
	def title(self, obj):
		site = Site.objects.get_current()
		parts = title_parts(**obj)
		parts.append(site.name)
		parts.reverse()
		
		return ': '.join(parts)
예제 #2
0
파일: feeds.py 프로젝트: iselu/bambu-tools
    def title(self, obj):
        site = Site.objects.get_current()
        parts = title_parts(**obj)
        parts.append(site.name)
        parts.reverse()

        return ': '.join(parts)
예제 #3
0
def posts(request, **kwargs):
	posts = Post.objects.live()
	templates = ['blog/posts.html']
	context = _context(request)
	breadcrumb_trail = []
	
	if 'year' in kwargs:
		if 'month' in kwargs:
			if 'day' in kwargs:
				date = datetime(
					int(kwargs['year']),
					int(kwargs['month']),
					int(kwargs['day'])
				).replace(tzinfo = utc)
				
				context['day'] = date.strftime('%B %d, %Y')
				
				breadcrumb_trail = (
					('../../../', u'Blog'),
					('../../', date.strftime('%Y')),
					('../', date.strftime('%B')),
					('', date.strftime('%d'))
				)
				
				templates.insert(0, 'blog/posts-day.html')
			else:
				date = datetime(
					int(kwargs['year']),
					int(kwargs['month']),
					1
				).replace(tzinfo = utc)
				
				context['month'] = date.strftime('%B %Y')
				
				breadcrumb_trail = (
					('../../', u'Blog'),
					('../', date.strftime('%Y')),
					('', date.strftime('%B'))
				)
				
				templates.insert(0, 'blog/posts-month.html')
		else:
			context['year'] = kwargs['year']
			templates.insert(0, 'blog/posts-year.html')
			
			breadcrumb_trail = (
				('../', u'Blog'),
				('', int(kwargs['year'])),
			)
	else:
		breadcrumb_trail = (
			('', u'Blog'),
		)
	
	if 'category' in kwargs:
		category = get_object_or_404(Category, slug = kwargs['category'])
		context['category'] = category
		templates.insert(0, 'blog/posts-category.html')
		breadcrumb_trail = (
			('../', u'Blog'),
			('', category.name)
		)
	elif 'tag' in kwargs:
		tag = get_object_or_404(Tag, slug = kwargs['tag'])
		context['tag'] = tag
		templates.insert(0, 'blog/posts-tag.html')
		breadcrumb_trail = (
			('../', u'Blog'),
			('', tag.name)
		)
	elif 'username' in kwargs:
		author = get_object_or_404(User, username = kwargs['username'])
		context['author'] = author
		templates.insert(0, 'blog/posts-author.html')
		breadcrumb_trail = (
			('../', u'Blog'),
			('', author.get_full_name() or author.username)
		)
	
	context['posts'] = view_filter(**kwargs)
	context['breadcrumb_trail'] = breadcrumb_trail
	context['title_parts'] = title_parts(**kwargs)
	
	return TemplateResponse(
		request,
		templates,
		context
	)
예제 #4
0
def posts(request, **kwargs):
	templates = ['blog/posts.html']
	context = _context(request)
	breadcrumb_trail = []

	if 'year' in kwargs:
		if 'month' in kwargs:
			if 'day' in kwargs:
				date = datetime(
					int(kwargs['year']),
					int(kwargs['month']),
					int(kwargs['day'])
				).replace(
					tzinfo = get_current_timezone()
				)

				context['day'] = date.strftime('%B %d, %Y')

				breadcrumb_trail = (
					('../../../', u'Blog'),
					('../../', date.strftime('%Y')),
					('../', date.strftime('%B')),
					('', date.strftime('%d'))
				)

				templates.insert(0, 'blog/posts-day.html')
			else:
				date = datetime(
					int(kwargs['year']),
					int(kwargs['month']),
					1
				).replace(
					tzinfo = get_current_timezone()
				)

				context['month'] = date.strftime('%B %Y')

				breadcrumb_trail = (
					('../../', u'Blog'),
					('../', date.strftime('%Y')),
					('', date.strftime('%B'))
				)

				templates.insert(0, 'blog/posts-month.html')
		else:
			context['year'] = kwargs['year']
			templates.insert(0, 'blog/posts-year.html')

			breadcrumb_trail = (
				('../', u'Blog'),
				('', int(kwargs['year'])),
			)
	else:
		breadcrumb_trail = (
			('', u'Blog'),
		)

	if 'category' in kwargs:
		category = get_object_or_404(Category, slug = kwargs['category'])
		context['category'] = category
		templates.insert(0, 'blog/posts-category.html')
		breadcrumb_trail = (
			('../', u'Blog'),
			('', category.name)
		)
	elif 'tag' in kwargs:
		tag = get_object_or_404(Tag, slug = kwargs['tag'])
		context['tag'] = tag
		templates.insert(0, 'blog/posts-tag.html')
		breadcrumb_trail = (
			('../', u'Blog'),
			('', tag.name)
		)
	elif 'username' in kwargs:
		author = get_object_or_404(User, username = kwargs['username'])
		context['author'] = author
		templates.insert(0, 'blog/posts-author.html')
		breadcrumb_trail = (
			('../', u'Blog'),
			('', author.get_full_name() or author.username)
		)

	posts = view_filter(**kwargs)
	paginator = Paginator(posts, POSTS_PER_PAGE)
	page = request.GET.get('page')

	try:
		posts = paginator.page(page)
	except PageNotAnInteger:
		posts = paginator.page(1)
	except EmptyPage:
		posts = paginator.page(paginator.num_pages)

	context['page'] = posts
	context['breadcrumb_trail'] = breadcrumb_trail
	context['title_parts'] = title_parts(**kwargs)
	context['body_classes'] = ['page-%d' % posts.number]

	if any(posts.object_list) and posts.object_list[0].attachments.filter(featured = True).exists():
		context['body_classes'].append('first-post-has-featured-attachment')

	context['enqueued_styles'] = [
		enqueue_css_block(request, posts.object_list.css(True))
	]

	return TemplateResponse(
		request,
		templates,
		context
	)
예제 #5
0
def posts(request, **kwargs):
    templates = ['blog/posts.html']
    context = _context(request)
    breadcrumb_trail = []

    if 'year' in kwargs:
        if 'month' in kwargs:
            if 'day' in kwargs:
                date = datetime(
                    int(kwargs['year']), int(kwargs['month']),
                    int(kwargs['day'])).replace(tzinfo=get_current_timezone())

                context['day'] = date.strftime('%B %d, %Y')

                breadcrumb_trail = (('../../../',
                                     u'Blog'), ('../../', date.strftime('%Y')),
                                    ('../', date.strftime('%B')),
                                    ('', date.strftime('%d')))

                templates.insert(0, 'blog/posts-day.html')
            else:
                date = datetime(int(kwargs['year']), int(kwargs['month']),
                                1).replace(tzinfo=get_current_timezone())

                context['month'] = date.strftime('%B %Y')

                breadcrumb_trail = (('../../', u'Blog'), ('../',
                                                          date.strftime('%Y')),
                                    ('', date.strftime('%B')))

                templates.insert(0, 'blog/posts-month.html')
        else:
            context['year'] = kwargs['year']
            templates.insert(0, 'blog/posts-year.html')

            breadcrumb_trail = (
                ('../', u'Blog'),
                ('', int(kwargs['year'])),
            )
    else:
        breadcrumb_trail = (('', u'Blog'), )

    if 'category' in kwargs:
        category = get_object_or_404(Category, slug=kwargs['category'])
        context['category'] = category
        templates.insert(0, 'blog/posts-category.html')
        breadcrumb_trail = (('../', u'Blog'), ('', category.name))
    elif 'tag' in kwargs:
        tag = get_object_or_404(Tag, slug=kwargs['tag'])
        context['tag'] = tag
        templates.insert(0, 'blog/posts-tag.html')
        breadcrumb_trail = (('../', u'Blog'), ('', tag.name))
    elif 'username' in kwargs:
        author = get_object_or_404(User, username=kwargs['username'])
        context['author'] = author
        templates.insert(0, 'blog/posts-author.html')
        breadcrumb_trail = (('../', u'Blog'), ('', author.get_full_name()
                                               or author.username))

    posts = view_filter(**kwargs)
    paginator = Paginator(posts, POSTS_PER_PAGE)
    page = request.GET.get('page')

    try:
        posts = paginator.page(page)
    except PageNotAnInteger:
        posts = paginator.page(1)
    except EmptyPage:
        posts = paginator.page(paginator.num_pages)

    context['page'] = posts
    context['breadcrumb_trail'] = breadcrumb_trail
    context['title_parts'] = title_parts(**kwargs)
    context['body_classes'] = ['page-%d' % posts.number]

    if any(posts.object_list) and posts.object_list[0].attachments.filter(
            featured=True).exists():
        context['body_classes'].append('first-post-has-featured-attachment')

    context['enqueued_styles'] = [
        enqueue_css_block(request, posts.object_list.css(True))
    ]

    return TemplateResponse(request, templates, context)