Ejemplo n.º 1
0
def _aggregate_activity(user, days=60):
	since_datetime = time_ago(days=days)

	memberships = Membership.objects.filter(created_at__gt=since_datetime, user=user).select_related('page', 'user', 'page__owner')
	follows = Follow.objects.filter(created_at__gt=since_datetime, target=user).select_related('user')

	textitems = TextItem.objects.exclude(creator=user).filter(
		Q(created_at__gt=since_datetime), 
		Q(page__owner=user) | Q(page__membership__user=user) |
		Q(page__published=True) & Q(creator__followers__user=user) & ~Q(page__owner=F('creator'))
		).select_related('page', 'page__owner', 'creator').distinct()
	
	imageitems = ImageItem.objects.exclude(creator=user).filter(
		Q(created_at__gt=since_datetime), 
		Q(page__owner=user) | Q(page__membership__user=user) |
		Q(page__published=True) & Q(creator__followers__user=user) & ~Q(page__owner=F('creator'))
		).select_related('page', 'page__owner', 'creator').distinct()

	embeditems = EmbedItem.objects.exclude(creator=user).filter(
		Q(created_at__gt=since_datetime), 
		Q(page__owner=user) | Q(page__membership__user=user) |
		Q(page__published=True) & Q(creator__followers__user=user) & ~Q(page__owner=F('creator'))
		).select_related('page', 'page__owner', 'creator').distinct()

	pages_published_by_following = Page.objects.filter(
		published_at__gt=since_datetime, owner__followers__user=user, published=True
	).select_related('owner')

	all_activity_last_n_days = sorted(
		chain(pages_published_by_following, memberships, textitems, imageitems, embeditems, follows), 
		key=lambda instance: instance.published_at if hasattr(instance, 'published_at') else instance.created_at,
		reverse=True
	)[:20]

	return all_activity_last_n_days
Ejemplo n.º 2
0
def stats(request):
    from marketing.helpers import get_top_pages
    if not request.user.is_superuser:
        raise Http404
    one_week_ago = time_ago(days=7)
    most_viewed = get_top_pages(one_week_ago)
    lines = ['Most Viewed Pages Since %s' % one_week_ago]
    for dct in most_viewed:
        page = Page.objects.get(id=dct['page'])
        if page.owner_id:
            owner_email = page.owner.email
        else:
            owner_email = None
        lines.append("%d\t%s\t%s\t%s" % (dct['pcount'], owner_email, page.get_absolute_url(), page.title))
    return HttpResponse('\n'.join(lines), content_type="text/plain")
Ejemplo n.º 3
0
 def get_start(self, args):
     if not args:
         print "Must pass number of seconds as arguments."
         sys.exit(1)
     secs_back_to_look = int(args[0])
     return time_ago(seconds=secs_back_to_look)