Example #1
0
def page_context(request, site, tag=None, subscription_id=None, group_id=None, newer=None, asc=None, sfeeds=None):
    """ Returns the context dictionary for a page view.
    """
    sfeeds_obj, sfeeds_ids = sfeeds
    try:
        page = int(request.GET.get('page', 0))
    except ValueError:
        page = 0
    paginator, object_list = get_paginator(site, sfeeds_ids, \
      page=page, tag=tag, subscription=subscription_id, newer=newer, asc=asc, group=group_id)
    if object_list:
        # This will hit the DB once per page instead of once for every post in
        # a page. To take advantage of this the template designer must call
        # the qtags property in every item, instead of the default tags
        # property.
        subscription_obj, tag_obj = get_posts_tags(object_list, sfeeds_obj, \
          subscription_id, tag)
    else:
        subscription_obj, tag_obj = None, None
    last_checked = sfeeds_obj.aggregate(last_checked=Min("feed__last_checked"))['last_checked']
    ctx = {
        'object_list': object_list,
        'is_paginated': paginator.pages > 1,
        'results_per_page': site.posts_per_page,
        'has_next': paginator.has_next_page(page),
        'has_previous': paginator.has_previous_page(page),
        'page': page + 1,
        'next': page + 1,
        'previous': page - 1,
        'pages': paginator.pages,
        'hits' : paginator.hits,
        'request': request,
        'now': last_checked.strftime("%Y-%m-%d %H:%M") if last_checked else None,
    }
    get_extra_content(site, sfeeds_ids, ctx)
    from feedjack import fjcloud
    ctx['tagcloud'] = fjcloud.getcloud(site, subscription_id)
    ctx['subscription_id'] = subscription_id 
    ctx['subscription'] = subscription_obj
    ctx['tag'] = tag_obj
    #ctx['subscribers'] = sfeeds_obj.filter(group__isnull=True)
    groups=set()
    for feed in sfeeds_obj:
        groups.add(feed.group)
    ctx['subscriber_groups'] = list(groups)
    ctx['subscriber_groups'] += [{'name': 'ungrouped', 'subscriber_set': sfeeds_obj.filter(group__isnull=True), 'id': 0}]
    return ctx
Example #2
0
def page_context(request, site, tag=None, user_id=None, sfeeds=None):
    """ Returns the context dictionary for a page view.
    """
    sfeeds_obj, sfeeds_ids = sfeeds
    try:
        page = int(request.GET.get('page', 0))
    except ValueError:
        page = 0
    paginator, object_list = get_paginator(site, sfeeds_ids, \
      page=page, tag=tag, user=user_id)
    if object_list:
        # This will hit the DB once per page instead of once for every post in
        # a page. To take advantage of this the template designer must call
        # the qtags property in every item, instead of the default tags
        # property.
        user_obj, tag_obj = get_posts_tags(object_list, sfeeds_obj, \
          user_id, tag)
    else:
        user_obj, tag_obj = None, None
    ctx = RequestContext(request, {
        'object_list': object_list,
        'is_paginated': paginator.pages > 1,
        'results_per_page': site.posts_per_page,
        'has_next': paginator.has_next_page(page),
        'has_previous': paginator.has_previous_page(page),
        'page': page + 1,
        'next': page + 1,
        'previous': page - 1,
        'pages': paginator.pages,
        'hits' : paginator.hits,
    })
    get_extra_content(site, sfeeds_ids, ctx)
    from feedjack import fjcloud
    ctx['tagcloud'] = fjcloud.getcloud(site, user_id)
    ctx['user_id'] = user_id
    ctx['user'] = user_obj
    ctx['tag'] = tag_obj
    ctx['subscribers'] = sfeeds_obj
    return ctx
Example #3
0
def page_context(request, site, tag=None, user_id=None, sfeeds=None):
    """ Returns the context dictionary for a page view.
    """
    sfeeds_obj, sfeeds_ids = sfeeds
    try:
        page = int(request.GET.get('page', 0))
    except ValueError:
        page = 0
    paginator, object_list = get_paginator(site, sfeeds_ids, \
      page=page, tag=tag, user=user_id)
    if object_list:
        # This will hit the DB once per page instead of once for every post in
        # a page. To take advantage of this the template designer must call
        # the qtags property in every item, instead of the default tags
        # property.
        user_obj, tag_obj = get_posts_tags(object_list, sfeeds_obj, \
          user_id, tag)
    else:
        user_obj, tag_obj = None, None
    ctx = {
        'object_list': object_list,
        'is_paginated': paginator.pages > 1,
        'results_per_page': site.posts_per_page,
        'has_next': paginator.has_next_page(page),
        'has_previous': paginator.has_previous_page(page),
        'page': page + 1,
        'next': page + 1,
        'previous': page - 1,
        'pages': paginator.pages,
        'hits': paginator.hits,
    }
    get_extra_content(site, sfeeds_ids, ctx)
    from feedjack import fjcloud
    ctx['tagcloud'] = fjcloud.getcloud(site, user_id)
    ctx['user_id'] = user_id
    ctx['user'] = user_obj
    ctx['tag'] = tag_obj
    ctx['subscribers'] = sfeeds_obj
    return ctx
Example #4
0
def page_context(request, site, **criterias):
	'Returns the context dictionary for a page view.'
	try: page = int(request.GET.get('page', 1))
	except ValueError: page = 1

	feed, tag = criterias.get('feed'), criterias.get('tag')
	if feed:
		try: feed = models.Feed.objects.get(id=feed)
		except ObjectDoesNotExist: raise Http404

	page = get_page(site, page=page, **criterias)
	subscribers = site.active_subscribers

	if site.show_tagcloud and page.object_list:
		from feedjack import fjcloud
		# This will hit the DB once per page instead of once for every post in
		# a page. To take advantage of this the template designer must call
		# the qtags property in every item, instead of the default tags
		# property.
		user_obj, tag_obj = get_posts_tags(
			subscribers, page.object_list, feed, tag )
		tag_cloud = fjcloud.getcloud(site, feed and feed.id)
	else:
		tag_obj, tag_cloud = None, tuple()
		try:
			user_obj = models.Subscriber.objects\
				.get(site=site, feed=feed) if feed else None
		except ObjectDoesNotExist: raise Http404

	ctx = dict(
		last_modified = max(it.imap(
				op.attrgetter('date_updated'), page.object_list ))\
			if len(page.object_list) else datetime(1970, 1, 1, 0, 0, 0, 0, timezone.utc),

		object_list = page.object_list,
		subscribers = subscribers,
		tag = tag_obj,
		tagcloud = tag_cloud,

		feed = feed,
		url_suffix = ''.join((
			'/feed/{0}'.format(feed.id) if feed else '',
			'/tag/{0}'.format(escape(tag)) if tag else '' )),

		p = page, # "page" is taken by legacy number
		p_10neighbors = OrderedDict(
			# OrderedDict of "num: exists" values
			# Use as "{% for p_num, p_exists in p_10neighbors.items|slice:"7:-7" %}"
			(p, p >= 1 and p <= page.paginator.num_pages)
			for p in ((page.number + n) for n in xrange(-10, 11)) ),

		## DEPRECATED:

		# Totally misnamed and inconsistent b/w user/user_obj,
		#  use "feed" and "subscribers" instead.
		user_id = feed and feed.id,
		user = user_obj,

		# Legacy flat pagination context, use "p" instead.
		is_paginated = page.paginator.num_pages > 1,
		results_per_page = site.posts_per_page,
		has_next = page.has_next(),
		has_previous = page.has_previous(),
		page = page.number,
		next = page.number + 1,
		previous = page.number - 1,
		pages = page.paginator.num_pages,
		hits = page.paginator.count )

	get_extra_content(site, ctx)

	return ctx
Example #5
0
 def get_cloud(self):
     from feedjack import fjcloud
     return fjcloud.getcloud(self.site, self.feed.id)
Example #6
0
def page_context(request, site, **criterias):
    'Returns the context dictionary for a page view.'
    try:
        page = int(request.GET.get('page', 1))
    except ValueError:
        page = 1

    feed, tag = criterias.get('feed'), criterias.get('tag')
    if feed:
        try:
            feed = models.Feed.objects.get(pk=feed)
        except ObjectDoesNotExist:
            raise Http404

    page = get_page(site, page=page, **criterias)
    subscribers = site.active_subscribers

    if site.show_tagcloud and page.object_list:
        from feedjack import fjcloud
        # This will hit the DB once per page instead of once for every post in
        #  a page. To take advantage of this the template designer must call
        #  the qtags property in every item, instead of the default tags property.
        user_obj, tag_obj = get_posts_tags(subscribers, page.object_list, feed,
                                           tag)
        tag_cloud = fjcloud.getcloud(site, feed and feed.id)
    else:
        tag_obj, tag_cloud = None, tuple()
        try:
            user_obj = models.Subscriber.objects\
             .get(site=site, feed=feed) if feed else None
        except ObjectDoesNotExist:
            raise Http404

    site_proc_tags = site.processing_tags.strip()
    if site_proc_tags != 'none':
        site_proc_tags = filter(
            None, map(op.methodcaller('strip'),
                      site.processing_tags.split(',')))
        # XXX: database hit that can be cached
        for site_feed, posts in it.groupby(page.object_list,
                                           key=op.attrgetter('feed')):
            proc = site_feed.processor_for_tags(site_proc_tags)
            if proc: proc.apply_overlay_to_posts(posts)

    ctx = dict(
     last_modified = max(it.imap(
       op.attrgetter('date_updated'), page.object_list ))\
      if len(page.object_list) else datetime(1970, 1, 1, 0, 0, 0, 0, timezone.utc),

     object_list = page.object_list,
     subscribers = subscribers.select_related('feed'),
     tag = tag_obj,
     tagcloud = tag_cloud,

     feed = feed,
     url_suffix = ''.join((
      '/feed/{0}'.format(feed.id) if feed else '',
      '/tag/{0}'.format(escape(tag)) if tag else '' )),

     p = page, # "page" is taken by legacy number
     p_10neighbors = OrderedDict(
      # OrderedDict of "num: exists" values
      # Use as "{% for p_num, p_exists in p_10neighbors.items|slice:"7:-7" %}"
      (p, p >= 1 and p <= page.paginator.num_pages)
      for p in ((page.number + n) for n in xrange(-10, 11)) ),

     ## DEPRECATED:

     # Totally misnamed and inconsistent b/w user/user_obj,
     #  use "feed" and "subscribers" instead.
     user_id = feed and feed.id,
     user = user_obj,

     # Legacy flat pagination context, use "p" instead.
     is_paginated = page.paginator.num_pages > 1,
     results_per_page = site.posts_per_page,
     has_next = page.has_next(),
     has_previous = page.has_previous(),
     page = page.number,
     next = page.number + 1,
     previous = page.number - 1,
     pages = page.paginator.num_pages,
     hits = page.paginator.count )

    get_extra_context(site, ctx)

    return ctx
Example #7
0
def page_context(request, site, **criterias):
    "Returns the context dictionary for a page view."
    try:
        page = int(request.GET.get("page", 1))
    except ValueError:
        page = 1

    feed, tag = criterias.get("feed"), criterias.get("tag")
    if feed:
        try:
            feed = models.Feed.objects.get(id=feed)
        except ObjectDoesNotExist:
            raise Http404

    page = get_page(site, page=page, **criterias)
    subscribers = site.active_subscribers

    if site.show_tagcloud and page.object_list:
        from feedjack import fjcloud

        # This will hit the DB once per page instead of once for every post in
        # a page. To take advantage of this the template designer must call
        # the qtags property in every item, instead of the default tags
        # property.
        user_obj, tag_obj = get_posts_tags(subscribers, page.object_list, feed, tag)
        tag_cloud = fjcloud.getcloud(site, feed.id)
    else:
        tag_obj, tag_cloud = None, tuple()
        try:
            user_obj = models.Subscriber.objects.get(site=site, feed=feed) if feed else None
        except ObjectDoesNotExist:
            raise Http404

    ctx = dict(
        object_list=page.object_list,
        is_paginated=page.paginator.num_pages > 1,
        results_per_page=site.posts_per_page,
        has_next=page.has_next(),
        has_previous=page.has_previous(),
        page=page.number,
        next=page.number + 1,
        previous=page.number - 1,
        pages=page.paginator.num_pages,
        hits=page.paginator.count,
        last_modified=max(it.imap(op.attrgetter("date_updated"), page.object_list))
        if len(page.object_list)
        else datetime(1970, 1, 1),
    )

    get_extra_content(site, ctx)
    ctx["tagcloud"] = tag_cloud
    ctx["tag"] = tag_obj
    ctx["subscribers"] = subscribers

    # New
    ctx["feed"] = feed
    ctx["url_suffix"] = "".join(
        ("/feed/{0}".format(feed.id) if feed else "", "/tag/{0}".format(quote(tag)) if tag else "")
    )

    # Deprecated
    ctx["user_id"] = feed and feed.id  # totally misnamed and inconsistent with user_obj
    ctx["user"] = user_obj

    return ctx