Пример #1
0
def home(request):
    """Render a home page - a page of text for visitors and a sort of 'dashboard' view for authenticated members."""
    log_page_view(request, 'Home')
    if request.user.is_anonymous():
        template = 'index.html'
        context = {}  # main index doesn't require any context
    else:
        template = 'index_bros_only.html'
        user = request.user
        profile = user.get_profile()
        threads = profile.subscriptions.order_by('-updated')
        if len(threads) > 5:
            threads = threads[:5]
        announcements = Announcement.most_recent(False)
        two_months_ago = datetime.now() - timedelta(days=60)
        info_cards = InformationCard.objects.filter(
            created__gte=two_months_ago).order_by('-created')
        if len(info_cards) > 5:
            info_cards = info_cards[:5]
        accounts = UserProfile.objects.filter(
            user__date_joined__gte=two_months_ago).order_by('badge')
        context = {
            'subscriptions': threads,
            'announcements': announcements,
            'info_cards': info_cards,
            'accounts': accounts
        }
    return render(request,
                  template,
                  context,
                  context_instance=RequestContext(request))
Пример #2
0
def home(request):
    """Render a home page - a page of text for visitors and a sort of 'dashboard' view for authenticated members."""
    log_page_view(request, 'Home')
    if request.user.is_anonymous():
        template = 'index.html'
        context = {}    # main index doesn't require any context
    else:
        template = 'index_bros_only.html'
        user = request.user
        profile = user.get_profile()
        threads = profile.subscriptions.order_by('-updated')
        if len(threads) > 5:
            threads = threads[:5]
        announcements = Announcement.most_recent(False)
        two_months_ago = datetime.now() - timedelta(days=60)
        info_cards = InformationCard.objects.filter(created__gte=two_months_ago).order_by('-created')
        if len(info_cards) > 5:
            info_cards = info_cards[:5]
        accounts = UserProfile.objects.filter(user__date_joined__gte=two_months_ago).order_by('badge')
        context = {'subscriptions': threads, 'announcements': announcements, 'info_cards': info_cards, 'accounts': accounts}
    return render(request, template, context, context_instance=RequestContext(request))
Пример #3
0
def announcements_processor(request):
    """Add an item 'recent_news', containing the most recently posted announcements, to all requests."""
    return {'recent_news': Announcement.most_recent(public=request.user.is_anonymous())}
Пример #4
0
def announcements_processor(request):
    """Add an item 'recent_news', containing the most recently posted announcements, to all requests."""
    return {
        'recent_news':
        Announcement.most_recent(public=request.user.is_anonymous())
    }