예제 #1
0
파일: views.py 프로젝트: ainci/gazjango
def homepage(request, social_len=7, num_tweets=3, num_comments=3,
             template="index.html"):

    recent_comments = PublicComment.visible.order_by('-time')[:25]
    
    # creating the social stream
    entries = Entry.published.get_entries(num=social_len, tweet=num_tweets)
    
    stream = heapq.nlargest(social_len,
       [("entry", entry) for entry in entries] +
       [("comment", comment) for comment in recent_comments[:num_comments]],
       key=lambda (kind, obj): obj.timestamp if kind == "entry" else obj.time
    )
    
    # getting the highlighted comment
    top_comment = max(recent_comments, key=lambda c: c.score)
    
    # getting comment list for facebook-style listings
    comment_list = defaultdict(list)
    for comment in recent_comments:
        comment_list[comment.subject].insert(0, comment)

    sorted_comment_list = sorted(comment_list.values(),
                    key=lambda lst: lst[-1].time, reverse=True)[:5]
    
    # events and announcements
    events = Announcement.events.order_by('event_date', 'event_time', 'pk') \
                         .filter(event_date__gte=datetime.date.today())
    announcements = Announcement.regular.order_by('-date_end', '-date_start')
    jobs = JobListing.unfilled.order_by('-pub_date')
    
    data = {
        'topstories': Article.published.filter(position='1').order_by('-pub_date')[:7],
        'stories': Article.published.order_by('-pub_date')[:4],
        
        'weather': Weather.objects.for_today(),
        'joke': WeatherJoke.objects.latest(),
        
        'specials': Special.objects.order_by('-date').all()[:10],
        'announcements': announcements[:5],
        'events':events[:4],
        'jobs': jobs[:3],
        
        'bico_news': get_bico_news(),
        'text_link_ads': [ad.render() for ad in TextLinkAd.objects.all()],
        'banner_ad': BannerAd.front.pick(),
        
        'stream':stream,
        'top_comment':top_comment,
        'sorted_comment_list':sorted_comment_list,
    }
    rc = RequestContext(request)
    return render_to_response(template, data, context_instance=rc)
예제 #2
0
파일: views.py 프로젝트: ainci/gazjango
def april_fools(request, template="aprilfools.html"):
    section = 'features'
    subsection = 'april-fools'
    
    sec = get_object_or_404(Section, slug=section)
    sub = get_object_or_404(Subsection, section=sec, slug=subsection)
    
    tops, mids, lows = sub.get_stories(num_top=2,num_mid=4, num_low=3)
    data = {
        'topstories': tops,
        'midstories': mids,
        'lowstories': lows,
        'announcements': Announcement.community.get_n(3),
        'bico_news': get_bico_news(),
        # 'tla_links': get_tla_links(),
        # 'manual_links': manual_links,
        # 'lca_links': lca_links,
    }
    rc = RequestContext(request)
    return render_to_response(template, data, context_instance=rc)
예제 #3
0
def april_fools(request, template="aprilfools.html"):
    section = 'features'
    subsection = 'april-fools'

    sec = get_object_or_404(Section, slug=section)
    sub = get_object_or_404(Subsection, section=sec, slug=subsection)

    tops, mids, lows = sub.get_stories(num_top=2, num_mid=4, num_low=3)
    data = {
        'topstories': tops,
        'midstories': mids,
        'lowstories': lows,
        'announcements': Announcement.community.get_n(3),
        'bico_news': get_bico_news(),
        # 'tla_links': get_tla_links(),
        # 'manual_links': manual_links,
        # 'lca_links': lca_links,
    }
    rc = RequestContext(request)
    return render_to_response(template, data, context_instance=rc)
예제 #4
0
def around_swarthmore(request, template="listings/around/index.html"):
    today = datetime.date.today()
    year = today.year
    month = today.month
    day = today.day

    date = datetime.date(int(year), int(month), int(day))
    current = Announcement.community.filter(date_start__lte=date,
                                            date_end__gte=date)

    regular = current.filter(is_lost_and_found=False, event_date=None)
    events = current.exclude(event_date=None)
    lost_and_found = current.filter(is_lost_and_found=True)

    one_week = datetime.timedelta(days=7)
    if date == datetime.date.today():
        jobs = JobListing.unfilled.get_for_show(num=5, cutoff=one_week)
    else:
        jobs = JobListing.published.get_for_show(num=5,
                                                 base_date=date,
                                                 cutoff=one_week)

    if not current.count() and not jobs.count():
        raise Http404

    tomorrow = date + datetime.timedelta(days=1)
    comments = PublicComment.visible.filter(
        time__lt=tomorrow).order_by('-time')

    t, m, l = Article.published.get_stories(num_top=0, num_mid=4, num_low=0)

    if request.method == 'POST':
        announcement_form = SubmitAnnouncementForm()
        job_form = SubmitJobForm()

        if announcement_form.is_valid():
            announcement_form.save_m2m()
            return HttpResponseRedirect(reverse(around_swarthmore))

        if job_form.is_valid():
            job_form.save_m2m()
            return HttpResponseRedirect(reverse(around_swarthmore))
    else:
        announcement_form = SubmitAnnouncementForm()
        job_form = SubmitJobForm()

    if datetime.datetime.now().hour < 21:
        menu = Menu.objects.for_today()
    else:
        menu = Menu.objects.for_tomorrow()

    data = {
        'year': year,
        'month': month,
        'day': day,
        'date': date,
        'announcements': regular.order_by('-date_start', 'pk'),
        'events': events.order_by('event_date', 'event_time', 'pk'),
        'lost_and_found': lost_and_found.order_by('-date_start', 'pk'),
        'jobs': jobs,
        'comments': comments[:10],
        'stories': m,
        'announcement_form': announcement_form,
        'job_form': job_form,
        'menu': menu,
        'bico_news': get_bico_news(),
        'poster': Poster.published.get_running(),
    }
    rc = RequestContext(request)
    return render_to_response(template, data, context_instance=rc)
예제 #5
0
def homepage(request,
             social_len=7,
             num_tweets=3,
             num_comments=3,
             template="index.html"):

    recent_comments = PublicComment.visible.order_by('-time')[:25]

    # creating the social stream
    entries = Entry.published.get_entries(num=social_len, tweet=num_tweets)

    stream = heapq.nlargest(social_len,
                            [("entry", entry) for entry in entries] +
                            [("comment", comment)
                             for comment in recent_comments[:num_comments]],
                            key=lambda (kind, obj): obj.timestamp
                            if kind == "entry" else obj.time)

    # getting the highlighted comment
    top_comment = max(recent_comments, key=lambda c: c.score)

    # getting comment list for facebook-style listings
    comment_list = defaultdict(list)
    for comment in recent_comments:
        comment_list[comment.subject].insert(0, comment)

    sorted_comment_list = sorted(comment_list.values(),
                                 key=lambda lst: lst[-1].time,
                                 reverse=True)[:5]

    # events and announcements
    events = Announcement.events.order_by('event_date', 'event_time', 'pk') \
                         .filter(event_date__gte=datetime.date.today())
    announcements = Announcement.regular.order_by('-date_end', '-date_start')
    jobs = JobListing.unfilled.order_by('-pub_date')

    data = {
        'topstories':
        Article.published.filter(position='1').order_by('-pub_date')[:7],
        'stories':
        Article.published.order_by('-pub_date')[:4],
        'weather':
        Weather.objects.for_today(),
        'joke':
        WeatherJoke.objects.latest(),
        'specials':
        Special.objects.order_by('-date').all()[:10],
        'announcements':
        announcements[:5],
        'events':
        events[:4],
        'jobs':
        jobs[:3],
        'bico_news':
        get_bico_news(),
        'text_link_ads': [ad.render() for ad in TextLinkAd.objects.all()],
        'banner_ad':
        BannerAd.front.pick(),
        'stream':
        stream,
        'top_comment':
        top_comment,
        'sorted_comment_list':
        sorted_comment_list,
    }
    rc = RequestContext(request)
    return render_to_response(template, data, context_instance=rc)
예제 #6
0
파일: views.py 프로젝트: ainci/gazjango
def around_swarthmore(request,template = "listings/around/index.html"):
    today = datetime.date.today()
    year = today.year
    month = today.month
    day = today.day
    
    date = datetime.date(int(year), int(month), int(day))
    current = Announcement.community.filter(date_start__lte=date, date_end__gte=date)

    regular = current.filter(is_lost_and_found=False, event_date=None)
    events = current.exclude(event_date=None)
    lost_and_found = current.filter(is_lost_and_found=True)

    one_week = datetime.timedelta(days=7)
    if date == datetime.date.today():
        jobs = JobListing.unfilled.get_for_show(num=5, cutoff=one_week)
    else:
        jobs = JobListing.published.get_for_show(num=5, base_date=date, cutoff=one_week)

    if not current.count() and not jobs.count():
        raise Http404

    tomorrow = date + datetime.timedelta(days=1)
    comments = PublicComment.visible.filter(time__lt=tomorrow).order_by('-time')

    t,m,l = Article.published.get_stories(num_top=0, num_mid=4, num_low=0)
        
    if request.method == 'POST':
        announcement_form = SubmitAnnouncementForm()
        job_form = SubmitJobForm()
        
        if announcement_form.is_valid():
            announcement_form.save_m2m()
            return HttpResponseRedirect(reverse(around_swarthmore))
            
        if job_form.is_valid():
            job_form.save_m2m()
            return HttpResponseRedirect(reverse(around_swarthmore))
    else:
        announcement_form = SubmitAnnouncementForm()
        job_form = SubmitJobForm()
        
    if datetime.datetime.now().hour < 21:
        menu = Menu.objects.for_today()
    else:
        menu = Menu.objects.for_tomorrow()

    data = {
        'year': year, 'month': month, 'day': day,
        'date': date,
        'announcements': regular.order_by('-date_start', 'pk'),
        'events': events.order_by('event_date', 'event_time', 'pk'),
        'lost_and_found': lost_and_found.order_by('-date_start', 'pk'),
        'jobs': jobs,
        'comments': comments[:10],
        'stories': m,
        'announcement_form': announcement_form,
        'job_form': job_form,
        'menu': menu,
        'bico_news': get_bico_news(),
        'poster': Poster.published.get_running(),
    }
    rc = RequestContext(request)
    return render_to_response(template, data, context_instance=rc)