def search(request): query = request.GET.get("q") if not query: return redirect("index") # fetch query results results = SearchIndex\ .search(query)\ .select_related("post", "user", "comment") # filter them by type content_type = request.GET.get("type") if content_type in ALLOWED_TYPES: results = results.filter(type=content_type) else: content_type = None # ordering ordering = request.GET.get("ordering") if ordering not in ALLOWED_ORDERING: ordering = "-rank" results = results.order_by(ordering) return render( request, "search.html", { "type": content_type, "ordering": ordering, "query": query, "results": paginate(request, results, page_size=settings.SEARCH_PAGE_SIZE), })
def index(request): qs = Post.active_objects.all().select_related('feed') page = paginate(qs, request, settings.FEEDZILLA_PAGE_SIZE) return {'page': page, }
def index(request): qs = Post.active_objects.all().select_related('feed') page = paginate(qs, request, settings.FEEDZILLA_PAGE_SIZE) context = { 'page': page, } return render(request, 'feedzilla/index.html', context)
def profile(request, user_slug): user = get_object_or_404(User, slug=user_slug) if user.id == request.me.id: goto = request.GET.get("goto") if goto: return redirect(goto) tags = Tag.objects.filter(is_visible=True).all() intro = Post.get_user_intro(user) projects = Post.objects.filter(author=user, type=Post.TYPE_PROJECT).all() active_tags = {t.tag_id for t in UserTag.objects.filter(user=user).all()} achievements = UserBadge.objects.filter(user=user)[:8] expertises = UserExpertise.objects.filter(user=user).all() posts = Post.objects_for_user(request.me)\ .filter(author=user, is_visible=True)\ .exclude(type__in=[Post.TYPE_INTRO, Post.TYPE_PROJECT]) return render( request, "users/profile.html", { "user": user, "intro": intro, "projects": projects, "tags": tags, "active_tags": active_tags, "achievements": achievements, "expertise_form": ExpertiseForm(), "expertises": expertises, "posts": paginate(request, posts), })
def tag(request, tag_value): tag = get_object_or_404(Tag, name=tag_value) qs = TaggedItem.objects.get_by_model(Post, tag).filter(active=True).order_by('-created') page = paginate(qs, request, settings.FEEDZILLA_PAGE_SIZE) return {'tag': tag, 'page': page, }
def user_details_topics(request, username): user = get_object_or_404(User, username=username) topics = Topic.objects.filter(user=user).order_by('-created') page = paginate(topics, request, settings.PYBB_TOPIC_PAGE_SIZE) return {'profile': user, 'page': page, }
def forum_details(request, forum_id): forum = get_object_or_404(Forum, pk=forum_id) topics = forum.topics.order_by('-sticky', '-updated').select_related() page = paginate(topics, request, settings.PYBB_FORUM_PAGE_SIZE) load_last_post(page.object_list) return {'forum': forum, 'page': page, }
def bookmarks(request): user = request.me posts = Post.objects.filter( bookmarks__user=user).order_by('-bookmarks__created_at').all() return render(request, "bookmarks.html", { "posts": paginate(request, posts), })
def tag(request, tag_value): tag = get_object_or_404(Tag, name=tag_value) qs = TaggedItem.objects.get_by_model(FeedEntry, tag).filter(active=True).order_by('-created') page = paginate(qs, request, FEED_PAGE_SIZE) return ('feedz/feedz_tag.html', { 'tag': tag, 'page': page, } )
def user_list(request): users = User.objects.order_by('username') form = UserSearchForm(request.GET) users = form.filter(users) page = paginate(users, request, settings.PYBB_USERS_PAGE_SIZE) return {'page': page, 'form': form, }
def bookmarks(request): user = request.me posts = Post.objects_for_user(user)\ .filter(bookmarks__user=user, deleted_at__isnull=True)\ .order_by('-bookmarks__created_at')\ .all() return render(request, "bookmarks.html", { "posts": paginate(request, posts), })
def search(request): query = request.GET.get("q") if not query: return redirect("index") results = SearchIndex.search(query).select_related("post", "profile", "comment") return render(request, "posts/search.html", { "query": query, "results": paginate(request, results, page_size=settings.SEARCH_PAGE_SIZE), })
def feed(request, post_type=None, topic_slug=None, ordering="activity"): if request.me: request.me.update_last_activity() posts = Post.objects_for_user(request.me) else: posts = Post.visible_objects() # filter posts by type if post_type: posts = posts.filter(type=post_type) # filter by topic topic = None if topic_slug: topic = get_object_or_404(Topic, slug=topic_slug) posts = posts.filter(topic=topic) # hide non-public posts and intros from unauthorized users if not request.me: posts = posts.exclude(is_public=False).exclude(type=Post.TYPE_INTRO) # exclude shadow banned posts if request.me: posts = posts.exclude( Q(is_shadow_banned=True) & ~Q(author_id=request.me.id)) # no type and topic? probably it's the main page, let's apply some more filters if not topic and not post_type: posts = posts.filter(is_visible_on_main_page=True) # order posts by some metric if ordering: if ordering == "activity": posts = posts.order_by("-last_activity_at") elif ordering == "new": posts = posts.order_by("-published_at") elif ordering == "top": posts = posts.filter(published_at__gte=datetime.utcnow() - timedelta(days=60)).order_by("upvotes") else: raise Http404() # split results into pinned and unpinned posts pinned_posts = posts.filter(is_pinned_until__gte=datetime.utcnow()) posts = posts.exclude(id__in=[p.id for p in pinned_posts]) return render( request, "posts/feed.html", { "posts": paginate(request, posts), "pinned_posts": pinned_posts, "post_type": post_type, "ordering": ordering, "topic": topic, })
def friends(request, user_slug): if request.me.slug != user_slug: return HttpResponseForbidden() user = get_object_or_404(User, slug=user_slug) user_friends = Friend.user_friends(user_from=user) return render(request, "users/friends/index.html", { "user": user, "friends_paginated": paginate(request, user_friends, page_size=settings.FRIENDS_PAGE_SIZE) })
def tag(request, tag_value): try: tag = FeedzillaTag.objects.get(slug=tag_value) except FeedzillaTag.DoesNotExist: tag = get_object_or_404(FeedzillaTag, name=tag_value) return redirect('feedzilla_tag', tag.slug, permanent=True) qs = Post.objects.filter(tags=tag, active=True).order_by('-created') page = paginate(qs, request, settings.FEEDZILLA_PAGE_SIZE) context = {'tag': tag.name, 'page': page} return render(request, 'feedzilla/tag.html', context)
def index(request): #qs = Post.active_objects.all().select_related('feed') qs = Post.objects.all().select_related('feed') # TODO: Remove it! host = request.GET.get('host') if host: qs = qs.filter(feed__site_url__icontains=host) page, paginator = paginate(qs, request, app_settings.PAGE_SIZE) return {'page': page, 'paginator': paginator, }
def profile_badges(request, user_slug): if user_slug == "me": return redirect("profile_badges", request.me.slug, permanent=False) user = get_object_or_404(User, slug=user_slug) badges = UserBadge.user_badges(user) return render( request, "users/profile/badges.html", { "user": user, "badges": paginate(request, badges, settings.PROFILE_BADGES_PAGE_SIZE), })
def search(request): query = request.GET.get('query', '') min_limit = 2 if len(query) < min_limit: posts = [] message = _('Your query is shorter than %d characters') % min_limit else: posts = Post.active_objects.filter(content__icontains=query) message = '' page = paginate(posts, request, settings.FEEDZILLA_PAGE_SIZE) context = {'page': page, 'message': message, 'query': query, } return render(request, 'feedzilla/search.html', context)
def profile_comments(request, user_slug): if user_slug == "me": return redirect("profile_comments", request.me.slug, permanent=False) user = get_object_or_404(User, slug=user_slug) comments = Comment.visible_objects()\ .filter(author=user, post__is_visible=True)\ .order_by("-created_at")\ .select_related("post") return render(request, "users/profile/comments.html", { "user": user, "comments": paginate(request, comments, settings.PROFILE_COMMENTS_PAGE_SIZE), })
def profile_posts(request, user_slug): if user_slug == "me": return redirect("profile_posts", request.me.slug, permanent=False) user = get_object_or_404(User, slug=user_slug) posts = Post.objects_for_user(request.me) \ .filter(author=user, is_visible=True) \ .exclude(type__in=[Post.TYPE_INTRO, Post.TYPE_PROJECT, Post.TYPE_WEEKLY_DIGEST]) \ .order_by("-published_at") return render(request, "users/profile/posts.html", { "user": user, "posts": paginate(request, posts, settings.PROFILE_POSTS_PAGE_SIZE), })
def tag(request, tag_value): try: tag = FeedzillaTag.objects.get(slug=tag_value) except FeedzillaTag.DoesNotExist: tag = get_object_or_404(FeedzillaTag, name=tag_value) return redirect('feedzilla_tag', tag.slug, permanent=True) qs = Post.objects.filter(tags=tag, active=True).order_by('-created') page = paginate(qs, request, settings.FEEDZILLA_PAGE_SIZE) context = { 'tag': tag.name, 'page': page } return render(request, 'feedzilla/tag.html', context)
def topic_details(request, topic_id): try: topic = Topic.objects.select_related().get(pk=topic_id) except Topic.DoesNotExist: raise Http404() topic.views += 1 topic.save() if request.user.is_authenticated(): update_read_tracking(topic, request.user) if settings.PYBB_FREEZE_FIRST_POST: first_post = topic.head else: first_post = None form = AddPostForm(topic=topic) moderator = (request.user.is_superuser or request.user in topic.forum.moderators.all()) subscribed = (request.user.is_authenticated() and request.user in topic.subscribers.all()) posts = topic.posts.all() page = paginate(posts, request, settings.PYBB_TOPIC_PAGE_SIZE) users = User.objects.filter(pk__in= set(x.user_id for x in page.object_list)).select_related("pybb_profile") users = dict((user.pk, user) for user in users) for post in page.object_list: post.user = users.get(post.user_id) load_related(page.object_list, Attachment.objects.all(), 'post') return {'topic': topic, 'last_post': topic.last_post, 'first_post': first_post, 'form': form, 'moderator': moderator, 'subscribed': subscribed, 'posts': page.object_list, 'page': page, }
def search(request): query = request.GET.get('query', '') min_limit = 2 if len(query) < min_limit: posts = [] message = _('Your query is shorter than %d characters') % min_limit else: posts = Post.active_objects.filter(content__icontains=query) message = '' page, paginator = paginate(posts, request, app_settings.PAGE_SIZE) return {'page': page, 'paginator': paginator, 'message': message, 'query': query, }
def profile(request, user_slug): if user_slug == "me": return redirect("profile", request.me.slug, permanent=False) user = get_object_or_404(User, slug=user_slug) if not request.me.is_moderator: # hide unverified and deleted users if user.moderation_status != User.MODERATION_STATUS_APPROVED or user.deleted_at: raise Http404() # handle auth redirect if user.id == request.me.id: goto = request.GET.get("goto") if goto and goto.startswith(settings.APP_HOST): return redirect(goto) tags = Tag.objects.filter(is_visible=True).all() intro = Post.get_user_intro(user) projects = Post.objects.filter(author=user, type=Post.TYPE_PROJECT, is_visible=True).all() active_tags = {t.tag_id for t in UserTag.objects.filter(user=user).all()} similarity = {} if user.id != request.me.id: my_tags = {t.tag_id for t in UserTag.objects.filter(user=request.me).all()} similarity = calculate_similarity(my_tags, active_tags, tags) achievements = UserAchievement.objects.filter(user=user).select_related("achievement") expertises = UserExpertise.objects.filter(user=user).all() comments = Comment.visible_objects().filter(author=user, post__is_visible=True).order_by("-created_at")[:3] posts = Post.objects_for_user(request.me)\ .filter(author=user, is_visible=True)\ .exclude(type__in=[Post.TYPE_INTRO, Post.TYPE_PROJECT]) return render(request, "users/profile.html", { "user": user, "intro": intro, "projects": projects, "tags": tags, "active_tags": active_tags, "achievements": [ua.achievement for ua in achievements], "expertises": expertises, "comments": comments, "posts": paginate(request, posts), "similarity": similarity, })
def search(request): query = request.GET.get('query', '') min_limit = 2 if len(query) < min_limit: posts = [] message = _('Your query is shorter than %d characters') % min_limit else: posts = Post.active_objects.filter(content__icontains=query) message = '' page = paginate(posts, request, settings.FEEDZILLA_PAGE_SIZE) context = { 'page': page, 'message': message, 'query': query, } return render(request, 'feedzilla/search.html', context)
def profile(request, user_slug): if user_slug == "me": return redirect("profile", request.me.slug, permanent=False) user = get_object_or_404(User, slug=user_slug) if not request.me.is_moderator: # hide unverified users if not user.is_profile_complete or not user.is_profile_complete or user.is_profile_rejected: raise Http404() if user.id == request.me.id: goto = request.GET.get("goto") if goto: return redirect(goto) tags = Tag.objects.filter(is_visible=True).all() intro = Post.get_user_intro(user) projects = Post.objects.filter(author=user, type=Post.TYPE_PROJECT).all() active_tags = {t.tag_id for t in UserTag.objects.filter(user=user).all()} achievements = UserAchievement.objects.filter(user=user).select_related("achievement") expertises = UserExpertise.objects.filter(user=user).all() comments = Comment.visible_objects().filter(author=user).order_by("-created_at")[:3] posts = Post.objects_for_user(request.me)\ .filter(author=user, is_visible=True)\ .exclude(type__in=[Post.TYPE_INTRO, Post.TYPE_PROJECT]) return render(request, "users/profile.html", { "user": user, "intro": intro, "projects": projects, "tags": tags, "active_tags": active_tags, "achievements": [ua.achievement for ua in achievements], "expertises": expertises, "comments": comments, "posts": paginate(request, posts), })
def forum_details(forum, request): """ Return data which usually used on Forum Details page. This function is useful if you want to display topics from some forum outside the forum. For example, news section on the website could be powered by content from some subforum. In this case each News item will be a ``Topic`` instance and all comments will be ``Post`` items. Args: forum: the ``pybb.models.Forum`` instance request: ``Request`` object """ topics = forum.topics.order_by('-sticky', '-updated').select_related() page = paginate(topics, request, settings.PYBB_FORUM_PAGE_SIZE) load_last_post(page.object_list) return {'forum': forum, 'page': page, }
def forum_details(forum, request): """ Return data which usually used on Forum Details page. This function is useful if you want to display topics from some forum outside the forum. For example, news section on the website could be powered by content from some subforum. In this case each News item will be a ``Topic`` instance and all comments will be ``Post`` items. Args: forum: the ``pybb.models.Forum`` instance request: ``Request`` object """ topics = forum.topics.order_by('-sticky', '-updated').select_related() page = paginate(topics, request, settings.PYBB_FORUM_PAGE_SIZE) load_last_post(page.object_list) return { 'forum': forum, 'page': page, }
def people(request): users = User.registered_members().order_by("-created_at").select_related( "geo") query = request.GET.get("query") if query: users = users.filter(index__index=SearchQuery(query, config="russian")) tags = request.GET.getlist("tags") if tags: users = users.filter(index__tags__contains=tags) country = request.GET.get("country") if country: users = users.filter(country=country) filters = request.GET.getlist("filters") if filters: if "faang" in filters: users = users.filter(company__in=[ "Facebook", "Apple", "Google", "Amazon", "Netflix", "Microsoft", "Фейсбук", "Гугл", "Амазон", "Нетфликс", "Майкрософт", "Микрософт" ]) if "same_city" in filters: users = users.filter(city=request.me.city) if "activity" in filters: users = users.filter(last_activity_at__gte=datetime.utcnow() - timedelta(days=30)) tags_with_stats = Tag.tags_with_stats() tag_stat_groups = group_by(tags_with_stats, "group", todict=True) tag_stat_groups.update({ "travel": [ tag for tag in tag_stat_groups[Tag.GROUP_CLUB] if tag.code in { "can_coffee", "can_city", "can_beer", "can_office", "can_sleep", } ], "grow": [ tag for tag in tag_stat_groups[Tag.GROUP_CLUB] if tag.code in { "can_advice", "can_project", "can_teach", "search_idea", "can_idea", "can_invest", "search_mentor", "can_mentor", "can_hobby" } ], "work": [ tag for tag in tag_stat_groups[Tag.GROUP_CLUB] if tag.code in { "can_refer", "search_employees", "search_job", "search_remote", "search_relocate" } ], }) active_countries = User.registered_members().filter(country__isnull=False)\ .values("country")\ .annotate(country_count=Count("country"))\ .order_by("-country_count") map_stat_groups = { "💼 Топ компаний": top(users, "company")[:5], "🏰 Города": top(users, "city")[:5], "🎬 Экспертиза": top(UserExpertise.objects.filter(user_id__in=[u.id for u in users]), "name")[:5], } return render( request, "users/people.html", { "people_query": { "query": query, "country": country, "tags": tags, "filters": filters, }, "users": users, "users_paginated": paginate(request, users, page_size=settings.PEOPLE_PAGE_SIZE), "tag_stat_groups": tag_stat_groups, "max_tag_user_count": max(tag.user_count for tag in tags_with_stats), "active_countries": active_countries, "map_stat_groups": map_stat_groups, })
def events_list_items(request): if "listid" in request.POST: sublist = get_object_or_404(SubscriptionList, user=request.user, id=request.POST["listid"]) feedlist = sublist.trackers.all() show_empty = False elif "feed" in request.POST: sublist = None try: feedlist = [Feed.from_name(request.POST["feed"])] show_empty = True except Feed.DoesNotExist: feedlist = [] show_empty = False else: raise Http404() if len(feedlist) > 0 or show_empty: qs = Feed.get_events_for(feedlist if len(feedlist) > 0 else None, int(request.POST.get( 'count', '100'))) # get all events else: qs = [] page = paginate(qs, request, per_page=50) # Based on the last 100 events, how often do we expect to get email updates? # Compute this using the median time between events, which should give us an # idea of how often the events occur in a way that is robust to a few long # periods of no events, e.g. which Congress is out of session. expected_frequency = None if len(qs) > 15: # Get the time between consecutive events, in days. seps = [] for i in xrange(1, len(qs)): s = (qs[i - 1]["when"] - qs[i]["when"]).total_seconds() if s == 0: continue # skip things that happen at exactly the same time, # since they probably don't help us understand frequency seps.append(s / float(60 * 60 * 24)) # Find the median. if len(seps) == 0: # everything occurred at the same moment days_between_events = 1000 else: seps.sort() days_between_events = seps[len(seps) / 2] if not sublist or sublist.email == 0: if days_between_events < 1: expected_frequency = "Turn on daily email updates if you would like to get these events sent to you each day." elif days_between_events < 7: expected_frequency = "Turn on daily or weekly email updates if you would like to get these events mailed to you each day or week." elif sublist.email == 1: if days_between_events < 1: expected_frequency = "You can expect an email update roughly every day Congress is in session." elif days_between_events < 4: expected_frequency = "You can expect an email update every couple of days." elif days_between_events < 6: expected_frequency = "You can expect an email update every week." else: expected_frequency = "You will get email updates when more events in Congress occur matching the items you are tracking." elif sublist.email == 2: if days_between_events < 6: expected_frequency = "You can expect an email update every week." elif days_between_events < 20: expected_frequency = "You can expect an email update every couple of weeks." else: expected_frequency = "You will get email updates when more events in Congress occur matching the items you are tracking." return { 'page': page, 'list': sublist, 'feeds': feedlist, 'expected_frequency': expected_frequency, 'simple_mode': len(feedlist) == 1 and feedlist[0].single_event_type, }
def feed(request, post_type=POST_TYPE_ALL, topic_slug=None, label_code=None, ordering=ORDERING_ACTIVITY): post_type = post_type or Post if request.me: request.me.update_last_activity() posts = Post.objects_for_user(request.me) else: posts = Post.visible_objects() # filter posts by type if post_type != POST_TYPE_ALL: posts = posts.filter(type=post_type) # filter by topic topic = None if topic_slug: topic = get_object_or_404(Topic, slug=topic_slug) posts = posts.filter(topic=topic) # filter by label if label_code: posts = posts.filter(label_code=label_code) # hide muted users if request.me: muted = Muted.objects.filter(user_from=request.me).values_list("user_to_id").all() if muted: posts = posts.exclude(author_id__in=muted) # hide non-public posts and intros from unauthorized users if not request.me: posts = posts.exclude(is_public=False).exclude(type=Post.TYPE_INTRO) # exclude shadow banned posts, but show them in "new" tab if ordering != ORDERING_NEW: if request.me: posts = posts.exclude(Q(is_shadow_banned=True) & ~Q(author_id=request.me.id)) else: posts = posts.exclude(is_shadow_banned=True) # hide no-feed posts (show only inside rooms and topics) if not topic and not label_code: posts = posts.filter(is_visible_in_feeds=True) # order posts by some metric if ordering: if ordering == ORDERING_ACTIVITY: posts = posts.order_by("-last_activity_at") elif ordering == ORDERING_NEW: posts = posts.order_by("-published_at", "-created_at") elif ordering == ORDERING_TOP: posts = posts.order_by("-upvotes") elif ordering == ORDERING_HOT: posts = posts.order_by("-hotness") elif ordering == ORDERING_TOP_WEEK: posts = posts.filter( published_at__gte=datetime.utcnow() - timedelta(days=7) ).order_by("-upvotes") elif ordering == ORDERING_TOP_MONTH: posts = posts.filter( published_at__gte=datetime.utcnow() - timedelta(days=31) ).order_by("-upvotes") elif ordering == ORDERING_TOP_YEAR: posts = posts.filter( published_at__gte=datetime.utcnow() - timedelta(days=365) ).order_by("-upvotes") else: raise Http404() # split results into pinned and unpinned posts on main page pinned_posts = [] if ordering == ORDERING_ACTIVITY: pinned_posts = posts.filter(is_pinned_until__gte=datetime.utcnow()) posts = posts.exclude(id__in=[p.id for p in pinned_posts]) return render(request, "feed.html", { "post_type": post_type or POST_TYPE_ALL, "ordering": ordering, "topic": topic, "label_code": label_code, "posts": paginate(request, posts), "pinned_posts": pinned_posts, "date_month_ago": datetime.utcnow() - timedelta(days=30), })
def feed(request, post_type=POST_TYPE_ALL, topic_slug=None, ordering=ORDERING_ACTIVITY): post_type = post_type or Post if request.me: request.me.update_last_activity() posts = Post.objects_for_user(request.me) else: posts = Post.visible_objects() # filter posts by type if post_type != POST_TYPE_ALL: posts = posts.filter(type=post_type) # filter by topic topic = None if topic_slug: topic = get_object_or_404(Topic, slug=topic_slug) posts = posts.filter(topic=topic) # hide non-public posts and intros from unauthorized users if not request.me: posts = posts.exclude(is_public=False).exclude(type=Post.TYPE_INTRO) # exclude shadow banned posts, but show them in "new" tab if ordering != ORDERING_NEW: if request.me: posts = posts.exclude( Q(is_shadow_banned=True) & ~Q(author_id=request.me.id)) else: posts = posts.exclude(is_shadow_banned=True) # no type and topic? probably it's the main page, let's apply some more filters if not topic and post_type == POST_TYPE_ALL: posts = posts.filter(is_visible_on_main_page=True) # order posts by some metric if ordering: if ordering == ORDERING_ACTIVITY: posts = posts.order_by("-last_activity_at") elif ordering == ORDERING_NEW: posts = posts.order_by("-published_at", "-created_at") elif ordering == ORDERING_TOP: posts = posts.order_by("-upvotes") elif ordering == ORDERING_TOP_WEEK: posts = posts.filter(published_at__gte=datetime.utcnow() - timedelta(days=7)).order_by("-upvotes") elif ordering == ORDERING_TOP_MONTH: posts = posts.filter(published_at__gte=datetime.utcnow() - timedelta(days=31)).order_by("-upvotes") else: raise Http404() # split results into pinned and unpinned posts on main page pinned_posts = [] if ordering == ORDERING_ACTIVITY: pinned_posts = posts.filter(is_pinned_until__gte=datetime.utcnow()) posts = posts.exclude(id__in=[p.id for p in pinned_posts]) return render( request, "feed.html", { "post_type": post_type or POST_TYPE_ALL, "ordering": ordering, "topic": topic, "posts": paginate(request, posts), "pinned_posts": pinned_posts, })
def events_list_items(request): if "listid" in request.POST: sublist = get_object_or_404(SubscriptionList, user=request.user, id=request.POST["listid"]) feedlist = sublist.trackers.all() show_empty = False elif "feed" in request.POST: sublist = None try: feedlist = [Feed.from_name(request.POST["feed"])] show_empty = True except Feed.DoesNotExist: feedlist = [] show_empty = False else: raise Http404() if len(feedlist) > 0 or show_empty: qs = Feed.get_events_for(feedlist if len(feedlist) > 0 else None, int(request.POST.get('count', '100'))) # get all events else: qs = [] page = paginate(qs, request, per_page=50) # Based on the last 100 events, how often do we expect to get email updates? # Compute this using the median time between events, which should give us an # idea of how often the events occur in a way that is robust to a few long # periods of no events, e.g. which Congress is out of session. expected_frequency = None if len(qs) > 15: # Get the time between consecutive events, in days. seps = [] for i in xrange(1, len(qs)): s = (qs[i-1]["when"]-qs[i]["when"]).total_seconds() if s == 0: continue # skip things that happen at exactly the same time, # since they probably don't help us understand frequency seps.append( s/float(60*60*24) ) # Find the median. if len(seps) == 0: # everything occurred at the same moment days_between_events = 1000 else: seps.sort() days_between_events = seps[len(seps)/2] if not sublist or sublist.email == 0: if days_between_events < 1: expected_frequency = "Turn on daily email updates if you would like to get these events sent to you each day." elif days_between_events < 7: expected_frequency = "Turn on daily or weekly email updates if you would like to get these events mailed to you each day or week." elif sublist.email == 1: if days_between_events < 1: expected_frequency = "You can expect an email update roughly every day Congress is in session." elif days_between_events < 4: expected_frequency = "You can expect an email update every couple of days." elif days_between_events < 6: expected_frequency = "You can expect an email update every week." else: expected_frequency = "You will get email updates when more events in Congress occur matching the items you are tracking." elif sublist.email == 2: if days_between_events < 6: expected_frequency = "You can expect an email update every week." elif days_between_events < 20: expected_frequency = "You can expect an email update every couple of weeks." else: expected_frequency = "You will get email updates when more events in Congress occur matching the items you are tracking." return { 'page': page, 'list': sublist, 'feeds': feedlist, 'expected_frequency': expected_frequency, 'simple_mode': len(feedlist) == 1 and feedlist[0].single_event_type, }
def index(request): qs = FeedEntry.active_objects.all().select_related('feed') page = paginate(qs, request, settings.FEEDZILLA_PAGE_SIZE) return ('feedz/feedz_index.html', { 'page': page, } )
def index(request): qs = Post.active_objects.all().select_related('feed') page = paginate(qs, request, settings.FEEDZILLA_PAGE_SIZE) context = {'page': page, } return render(request, 'feedzilla/index.html', context)