示例#1
0
    def get_sections(self):

        visited = set()

        sections_to_combine = []
        page = self
        while page is not None and page.id not in visited:
            visited.add(page.id)
            sections_to_combine.append(page.content_data.get('sections'))
            if not page.inherit:
                break
            page = page.parent

        sections_to_combine = sections_to_combine[::-1]

        if self.base is not None:
            sections_to_combine.append(self.base.content_data.get('sections'))

        sections = combine_sections( *sections_to_combine )

        return sections
示例#2
0
    def get_sections(self):

        visited = set()

        sections_to_combine = []
        page = self
        while page is not None and page.id not in visited:
            visited.add(page.id)
            sections_to_combine.append(page.content_data.get('sections'))
            if not page.inherit:
                break
            page = page.parent

        sections_to_combine = sections_to_combine[::-1]

        if self.base is not None:
            sections_to_combine.append(self.base.content_data.get('sections'))

        sections = combine_sections(*sections_to_combine)

        return sections
示例#3
0
def tag(request, blog_slug, tag_slug, page_no=1, blog_root=None):

    page_no = int(page_no)
    if page_no < 1:
        raise Http404

    blog = get_channel_or_blog(blog_slug)
    blog_root = blog_root or blog.get_absolute_url()

    try:
        tag = blog.get_tag(tag_slug)
    except models.Tag.DoesNotExist:
        raise Http404

    title = blog.title
    posts = tag.posts()

    paginator = Paginator(posts, 10)

    if page_no > paginator.num_pages:
        raise Http404

    page = paginator.page(page_no)
    posts = page.object_list

    def get_page_url(page_no):
        if page_no < 1 or page_no > paginator.num_pages:
            return ""
        if page_no == 1:
            return "%stag/%s/" % (blog_root, tag_slug)
        else:
            return "%stag/%s/page/%i/" % (blog_root, tag_slug, page_no)

    newer_page_url = get_page_url(page_no - 1)
    older_page_url = get_page_url(page_no + 1)

    sections = extendedmarkup.combine_sections(
        blog.description_data.get("sections", None), tag.description_data.get("sections", None)
    )

    feeds = [tag.get_feed()]

    td = dict(
        blog_root=blog_root,
        blog=blog,
        tag=tag,
        title=title,
        page_title=title,
        tagline=blog.tagline,
        # archives = archives,
        page=page,
        page_no=page_no,
        posts=posts,
        sections=sections,
        older_page_url=older_page_url,
        newer_page_url=newer_page_url,
        feeds=feeds,
    )

    sections = extendedmarkup.process(sections, td)

    return render_to_response(blog.get_template_names("tag.html"), td, context_instance=RequestContext(request))
示例#4
0
def blog_post(request, blog_slug, year, month, day, slug, blog_root=None):

    blog = get_channel_or_blog(slug=blog_slug)
    blog_root = blog_root or blog.get_absolute_url()

    year = int(year)
    month = int(month)
    day = int(day)

    post_day_start = datetime(year, month, day)
    post_day_end = post_day_start + timedelta(days=1)

    if post_day_start > datetime.now():
        raise Http404

    if request.user.is_anonymous():
        post = get_object_or_404(
            models.Post,
            display_time__gte=post_day_start,
            display_time__lt=post_day_end,
            slug=slug,
            version="live",
            published=True,
        )
    else:
        post = get_object_or_404(
            models.Post,
            display_time__gte=post_day_start,
            display_time__lt=post_day_end,
            slug=slug,
            version="live",
            version_id=None,
        )

    is_preview = False
    if "version" in request.GET and not request.user.is_anonymous():
        version = request.GET.get("version")
        if not post.version_exists(version):
            raise Http404
        post = post.get_version(version)
        is_preview = True

    if not request.user.is_anonymous() and request.GET.has_key("clearcache"):
        invalidate_cache(post)

    sections = extendedmarkup.combine_sections(
        blog.description_data.get("sections", None), post.content_data.get("sections", None)
    )

    prev_post = None
    next_post = None
    try:
        prev_post = blog.posts().filter(published=True, display_time__lt=post.display_time).order_by("-display_time")[0]
    except IndexError:
        pass

    try:
        next_post = blog.posts().filter(published=True, display_time__gt=post.display_time).order_by("display_time")[0]
    except IndexError:
        pass

    tags = list(post.tags.all().order_by("slug"))
    # tags.sort(key = lambda t:t.name.lower())

    td = dict(
        blog_root=blog_root,
        blog=blog,
        year=year,
        month=month,
        day=day,
        post=post,
        prev_post=prev_post,
        next_post=next_post,
        page_title=post.title,
        tagline=post.blog.title,
        tags=tags,
        sections=sections,
        user=request.user,
        is_preview=is_preview,
    )

    sections = extendedmarkup.process(sections, td)

    return render_to_response(
        blog.get_template_names("entry.html", [post.template_path]), td, context_instance=RequestContext(request)
    )
示例#5
0
def tag(request, blog_slug, tag_slug, page_no=1, blog_root=None):

    page_no = int(page_no)
    if page_no < 1:
        raise Http404

    blog = get_channel_or_blog(blog_slug)
    blog_root = blog_root or blog.get_absolute_url()

    try:
        tag = blog.get_tag(tag_slug)
    except models.Tag.DoesNotExist:
        raise Http404

    title = blog.title
    posts = tag.posts()


    paginator = Paginator(posts, 10)

    if page_no > paginator.num_pages:
        raise Http404

    page = paginator.page(page_no)
    posts = page.object_list

    def get_page_url(page_no):
        if page_no < 1 or page_no > paginator.num_pages:
            return ""
        if page_no == 1:
            return "%stag/%s/"%(blog_root, tag_slug)
        else:
            return "%stag/%s/page/%i/" % (blog_root, tag_slug, page_no)


    newer_page_url = get_page_url(page_no - 1)
    older_page_url = get_page_url(page_no + 1)

    sections = extendedmarkup.combine_sections( blog.description_data.get('sections', None),
                                 tag.description_data.get('sections', None) )


    feeds = [tag.get_feed()]

    td = dict(blog_root = blog_root,
              blog = blog,
              tag = tag,
              title = title,
              page_title = title,
              tagline = blog.tagline,
              #archives = archives,
              page = page,
              page_no = page_no,
              posts = posts,
              sections = sections,
              older_page_url = older_page_url,
              newer_page_url = newer_page_url,
              feeds = feeds)


    sections = extendedmarkup.process(sections, td)

    return render_to_response(blog.get_template_names("tag.html"),
                              td,
                              context_instance=RequestContext(request))
示例#6
0
def blog_post(request, blog_slug, year, month, day, slug, blog_root=None):

    blog = get_channel_or_blog(slug=blog_slug)
    blog_root = blog_root or blog.get_absolute_url()

    year = int(year)
    month = int(month)
    day = int(day)

    post_day_start = datetime(year, month, day)
    post_day_end = post_day_start + timedelta(days=1)

    if post_day_start > datetime.now():
        raise Http404

    if request.user.is_anonymous():
        post = get_object_or_404(models.Post,
                                 display_time__gte=post_day_start,
                                 display_time__lt=post_day_end,
                                 slug=slug,
                                 version='live',
                                 published=True)
    else:
        post = get_object_or_404(models.Post,
                                 display_time__gte=post_day_start,
                                 display_time__lt=post_day_end,
                                 slug=slug,
                                 version='live',
                                 version_id=None)


    is_preview = False
    if 'version' in request.GET and not request.user.is_anonymous():
        version = request.GET.get('version')
        if not post.version_exists(version):
            raise Http404
        post = post.get_version(version)
        is_preview = True

    if not request.user.is_anonymous() and request.GET.has_key('clearcache'):
        invalidate_cache(post)


    sections = extendedmarkup.combine_sections( blog.description_data.get('sections', None),
                                 post.content_data.get('sections', None) )


    prev_post = None
    next_post = None
    try:
        prev_post = blog.posts().filter(published=True, display_time__lt=post.display_time).order_by('-display_time')[0]
    except IndexError:
        pass

    try:
        next_post = blog.posts().filter(published=True, display_time__gt=post.display_time).order_by('display_time')[0]
    except IndexError:
        pass

    tags = list(post.tags.all().order_by('slug'))
    #tags.sort(key = lambda t:t.name.lower())


    td = dict(  blog_root = blog_root,
                blog=blog,
                year=year,
                month=month,
                day=day,
                post=post,
                prev_post=prev_post,
                next_post=next_post,
                page_title = post.title,
                tagline = post.blog.title,
                tags = tags,
                sections = sections,
                user = request.user,
                is_preview = is_preview )

    sections = extendedmarkup.process(sections, td)

    return render_to_response(blog.get_template_names("entry.html", [post.template_path]),
                              td,
                              context_instance=RequestContext(request))