Esempio n. 1
0
	def _restrictable(self, optlist):
		if 'atomfeed-virt-only-in' not in self.context or \
		   not self.page.virtual() or \
		   not pageranges.is_restriction(self.context) or \
		   pageranges.restriction(self.context) in optlist:
			return False
		return True
Esempio n. 2
0
 def _restrictable(self, optlist):
     if 'atomfeed-virt-only-in' not in self.context or \
        not self.page.virtual() or \
        not pageranges.is_restriction(self.context) or \
        pageranges.restriction(self.context) in optlist:
         return False
     return True
Esempio n. 3
0
def directory(ctx):
	"""List the contents of the current directory, with links to each
	page and subdirectory. Supports VirtualDirectory restrictions, but
	always shows subdirectories."""
	res = []
	if ctx.page.type != "dir" or not ctx.page.displayable():
		return ''

	# Just in case:
	ctx.newtime(ctx.page.timestamp)
	dl = ctx.page.children()
	if not dl:
		return ''
	# Restrict the results if we've been asked to. This is complicated
	# by our need to preserve directories *always*, because we don't
	# know if they have any files within the restriction inside them.
	if pageranges.is_restriction(ctx):
		dirl = [z for z in dl if z.type == 'dir']
		tl = pageranges.filter_files(ctx, [(z.timestamp, z.path)
						   for z in dl
						   if z.type != 'dir'])
		if not tl and not dirl:
			return ''
		dl = [ctx.model.get_page(z[1]) for z in tl]
		dl.extend(dirl)
		dl.sort(key=lambda x: x.name)

	res.append("<ul>")
	for de in dl:
		res.append("\n<li> ")
		res.append(htmlrends.makelink(de.name, ctx.url(de)))
	res.append("\n</ul>\n")
	return ''.join(res)
Esempio n. 4
0
def directory(ctx):
    """List the contents of the current directory, with links to each
	page and subdirectory. Supports VirtualDirectory restrictions, but
	always shows subdirectories."""
    res = []
    if ctx.page.type != "dir" or not ctx.page.displayable():
        return ''

    # Just in case:
    ctx.newtime(ctx.page.timestamp)
    dl = ctx.page.children()
    if not dl:
        return ''
    # Restrict the results if we've been asked to. This is complicated
    # by our need to preserve directories *always*, because we don't
    # know if they have any files within the restriction inside them.
    if pageranges.is_restriction(ctx):
        dirl = [z for z in dl if z.type == 'dir']
        tl = pageranges.filter_files(ctx, [(z.timestamp, z.path)
                                           for z in dl if z.type != 'dir'])
        if not tl and not dirl:
            return ''
        dl = [ctx.model.get_page(z[1]) for z in tl]
        dl.extend(dirl)
        dl.sort(key=lambda x: x.name)

    res.append("<ul>")
    for de in dl:
        res.append("\n<li> ")
        res.append(htmlrends.makelink(de.name, ctx.url(de)))
    res.append("\n</ul>\n")
    return ''.join(res)
Esempio n. 5
0
def isblogyearmonth(context):
    """Suceeds (by generating a space) if we are a directory, in a
	blog view, and we are in a month or year VirtualDirectory.
	Fails otherwise."""
    if context.view != "blog" or \
       not pageranges.is_restriction(context) or \
       pageranges.restriction(context) not in ('year', 'month'):
        return ''
    else:
        return ' '
Esempio n. 6
0
def _fillcomments(context):
    r = context.getcache(atom_comkey)
    if r is not None:
        return r
    cutpoint = get_cutpoint(context)

    #dl = context.model.comments_children(context.page.me())
    dl = comments.cached_comments_children(context, context.page.me())
    # Force the generator to be expanded to a full list, so we can
    # sort it.
    dl = list(dl)
    utils.sort_timelist(dl)
    if not dl:
        context.setcache(atom_comkey, [])
        return []

    # Virtualization of comments means that we restrict the pages
    # that the comments are on to be within the virtualization
    # range. We cannot simply use pageranges.filter_files() on
    # the comments list itself, because the timestamps in that
    # are the *comment* timestamps, not the *page* timestamps.
    filterComments = False
    filterD = {}
    if pageranges.is_restriction(context):
        filterComments = True
        for ts, p in context.page.descendants(context):
            filterD[p] = True

    res = []
    count = 0
    for ts, path, cname in dl:
        if count > cutpoint:
            break
        if filterComments and path not in filterD:
            continue
        np = context.model.get_page(path)
        # We drop entirely pages that can't be accessed with
        # the current (lack of) permissions, rather than
        # insert a message about denied content; this seems
        # better.
        if not np.displayable() or np.is_redirect() or \
           not np.access_ok(context):
            continue
        c = context.model.get_comment(np, cname)
        if not c:
            continue
        count += 1
        res.append((ts, path, cname, c))
    context.setcache(atom_comkey, res)
    return res
Esempio n. 7
0
def _fillcomments(context):
	r = context.getcache(atom_comkey)
	if r is not None:
		return r
	cutpoint = get_cutpoint(context)

	#dl = context.model.comments_children(context.page.me())
	dl = comments.cached_comments_children(context, context.page.me())
	# Force the generator to be expanded to a full list, so we can
	# sort it.
	dl = list(dl)
	utils.sort_timelist(dl)
	if not dl:
		context.setcache(atom_comkey, [])
		return []

	# Virtualization of comments means that we restrict the pages
	# that the comments are on to be within the virtualization
	# range. We cannot simply use pageranges.filter_files() on
	# the comments list itself, because the timestamps in that
	# are the *comment* timestamps, not the *page* timestamps.
	filterComments = False
	filterD = {}
	if pageranges.is_restriction(context):
		filterComments = True
		for ts, p in context.page.descendants(context):
			filterD[p] = True

	res = []
	count = 0
	for ts, path, cname in dl:
		if count > cutpoint:
			break
		if filterComments and path not in filterD:
			continue
		np = context.model.get_page(path)
		# We drop entirely pages that can't be accessed with
		# the current (lack of) permissions, rather than
		# insert a message about denied content; this seems
		# better.
		if not np.displayable() or np.is_redirect() or \
		   not np.access_ok(context):
			continue
		c = context.model.get_comment(np, cname)
		if not c:
			continue
		count += 1
		res.append((ts, path, cname, c))
	context.setcache(atom_comkey, res)
	return res
Esempio n. 8
0
def blogdir(context):
	"""Generate a BlogDir rendering of the current directory:
	display all real pages in the current directory from most
	recent to oldest, rendering each with the template
	_blog/blogdirpage.tmpl_. Supports VirtualDirectory restrictions."""
	if context.page.type != "dir":
		return ''
	if not context.page.displayable():
		raise derrors.IntErr("undisplayable directory page")
	dl = context.page.children("file")
	if not dl:
		return ''
	# Boil it down to just files, in modtime order.
	# (Technically this is real files: displayable, non-redirect.)
	dl = [z for z in dl if z.realpage() and not z.is_util()]
	# This directory might have nothing.
	if not dl:
		return ''

	# Apply restrictions, backwardly.
	# Because restrictions are designed to be hugely scalable, they
	# want the output we'd get from page.descendants().
	if pageranges.is_restriction(context):
		tl = pageranges.filter_files(context, [(z.timestamp, z.path)
						       for z in dl])
		if not tl:
			return ''
		dl = [context.model.get_page(z[1]) for z in tl]
	else:
		dl.sort(key=lambda x: x.timestamp, reverse=True)

	# For each file, clone the context, set the current page to
	# it (!), and render it with the blogentry template.
	to = context.model.get_template("blog/blogdirpage.tmpl")
	context.setvar(rollvar, {})
	res = []
	for page in dl:
		# Note: we do not reset the view type, because we do
		# not render through the interface that cares; we go
		# straight to template.
		nc = context.clone_to_page(page)
		res.append(template.Template(to).render(nc))
		context.newtime(nc.modtime)
	return ''.join(res)
Esempio n. 9
0
def blogdir(context):
    """Generate a BlogDir rendering of the current directory:
	display all real pages in the current directory from most
	recent to oldest, rendering each with the template
	_blog/blogdirpage.tmpl_. Supports VirtualDirectory restrictions."""
    if context.page.type != "dir":
        return ''
    if not context.page.displayable():
        raise derrors.IntErr("undisplayable directory page")
    dl = context.page.children("file")
    if not dl:
        return ''
    # Boil it down to just files, in modtime order.
    # (Technically this is real files: displayable, non-redirect.)
    dl = [z for z in dl if z.realpage() and not z.is_util()]
    # This directory might have nothing.
    if not dl:
        return ''

    # Apply restrictions, backwardly.
    # Because restrictions are designed to be hugely scalable, they
    # want the output we'd get from page.descendants().
    if pageranges.is_restriction(context):
        tl = pageranges.filter_files(context,
                                     [(z.timestamp, z.path) for z in dl])
        if not tl:
            return ''
        dl = [context.model.get_page(z[1]) for z in tl]
    else:
        dl.sort(key=lambda x: x.timestamp, reverse=True)

    # For each file, clone the context, set the current page to
    # it (!), and render it with the blogentry template.
    to = context.model.get_template("blog/blogdirpage.tmpl")
    context.setvar(rollvar, {})
    res = []
    for page in dl:
        # Note: we do not reset the view type, because we do
        # not render through the interface that cares; we go
        # straight to template.
        nc = context.clone_to_page(page)
        res.append(template.Template(to).render(nc))
        context.newtime(nc.modtime)
    return ''.join(res)
Esempio n. 10
0
def clipDown(context, dl):
	if 'blog-display-howmany' in context:
		cutpoint = context['blog-display-howmany']
	else:
		cutpoint = TOPN_NUMBER
	if len(dl) > cutpoint and \
	   (not pageranges.is_restriction(context) or \
	    pageranges.restriction(context) in ('year', 'month')):
		t1 = time.localtime(dl[cutpoint-1][0])
		i = cutpoint
		while i < len(dl):
			t2 = time.localtime(dl[i][0])
			if t1.tm_mday != t2.tm_mday:
				break
			i += 1
		if i < len(dl):
			context.setvar(":blog:clippedrange", dl[i])
			context.setvar(":blog:clipsize", i)
			dl = dl[:i]
	return dl
Esempio n. 11
0
def clipDown(context, dl):
    if 'blog-display-howmany' in context:
        cutpoint = context['blog-display-howmany']
    else:
        cutpoint = TOPN_NUMBER
    if len(dl) > cutpoint and \
       (not pageranges.is_restriction(context) or \
        pageranges.restriction(context) in ('year', 'month')):
        t1 = time.localtime(dl[cutpoint - 1][0])
        i = cutpoint
        while i < len(dl):
            t2 = time.localtime(dl[i][0])
            if t1.tm_mday != t2.tm_mday:
                break
            i += 1
        if i < len(dl):
            context.setvar(":blog:clippedrange", dl[i])
            context.setvar(":blog:clipsize", i)
            dl = dl[:i]
    return dl
Esempio n. 12
0
def true_atom_page(context, only_in=False):
    if not context.page.virtual() or \
       not pageranges.is_restriction(context) or \
       not ('atomfeed-virt-only-in' in context or \
     'atomfeed-virt-only-adv' in context):
        # We must use .curdir() here because hasatomfeed() is
        # true for the root page as well as directories.
        return context.page.curdir()
    # tricky: .curdir() is not necessary now since virtual pages are
    # always directories.
    rt = pageranges.restriction(context)
    # If we are called with only_in True, a-v-only-in is known to exist.
    if only_in:
        atypes = context['atomfeed-virt-only-in']
    else:
        atypes = context.get('atomfeed-virt-only-adv',
                             context.get('atomfeed-virt-only-in', None))
    if rt in atypes or \
       (rt in ('year', 'month', 'day') and 'calendar' in atypes):
        return context.page
    return context.page.me()
Esempio n. 13
0
def true_atom_page(context, only_in = False):
	if not context.page.virtual() or \
	   not pageranges.is_restriction(context) or \
	   not ('atomfeed-virt-only-in' in context or \
		'atomfeed-virt-only-adv' in context):
		# We must use .curdir() here because hasatomfeed() is
		# true for the root page as well as directories.
		return context.page.curdir()
	# tricky: .curdir() is not necessary now since virtual pages are
	# always directories.
	rt = pageranges.restriction(context)
	# If we are called with only_in True, a-v-only-in is known to exist.
	if only_in:
		atypes = context['atomfeed-virt-only-in']
	else:
		atypes = context.get('atomfeed-virt-only-adv',
				     context.get('atomfeed-virt-only-in', None))
	if rt in atypes or \
	   (rt in ('year', 'month', 'day') and 'calendar' in atypes):
		return context.page
	return context.page.me()