예제 #1
0
def show_issue(request, issue, plain=False):
    tomorrow = issue.date + datetime.timedelta(days=1)
    comments = PublicComment.visible.filter(
        time__lt=tomorrow).order_by('-time')

    one_week = datetime.timedelta(days=7)
    if issue.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=issue.date,
                                                 cutoff=one_week)

    articles = issue.articles_in_order(
        racy=boolean_arg(request.GET.get('racy', ''), True))
    try:
        topstory = articles[0]
    except IndexError:
        raise Http404

    data = {
        'issue': issue,
        'topstory': articles[0],
        'midstories': articles[1:issue.num_full],
        'lowstories': articles[issue.num_full:],
        'jobs': jobs,
        'comments': comments[:5],
        'for_email': boolean_arg(request.GET.get('for_email', ''), False)
    }
    template = "issue/issue." + ('txt' if plain else 'html')
    return render_to_response(template, data)
예제 #2
0
def show_issue(request, issue, plain=False):
    tomorrow = issue.date + datetime.timedelta(days=1)
    comments = PublicComment.visible.filter(time__lt=tomorrow).order_by("-time")

    one_week = datetime.timedelta(days=7)
    if issue.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=issue.date, cutoff=one_week)

    articles = issue.articles_in_order(racy=boolean_arg(request.GET.get("racy", ""), True))
    try:
        topstory = articles[0]
    except IndexError:
        raise Http404

    data = {
        "issue": issue,
        "topstory": articles[0],
        "midstories": articles[1 : issue.num_full],
        "lowstories": articles[issue.num_full :],
        "jobs": jobs,
        "comments": comments[:5],
        "for_email": boolean_arg(request.GET.get("for_email", ""), False),
    }
    template = "issue/issue." + ("txt" if plain else "html")
    return render_to_response(template, data)
예제 #3
0
파일: views.py 프로젝트: ainci/gazjango
def approve_comment(request, slug, year, month, day, num, val='1'):
    if not request.user.has_perm('comments.change_publiccomment'):
        if request.is_ajax():
            raise Http404
        else:
            return HttpResponseRedirect("%s?next_page=%s" % (settings.LOGIN_URL, request.path))
    
    comment = _get_comment_or_404(year, month, day, slug, num)
    approve = boolean_arg(val, default=True)
    
    if bool(comment.is_approved) != approve:
        comment.is_approved = approve
        comment.save()
    
    if request.is_ajax():
        return render_to_response('comment/authorship.html', {
            'comment': comment,
        }, context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect(comment.get_absolute_url())
예제 #4
0
def show_rsd_thing(request, date, plain=False, regular=False, events=False, lost_and_found=False, jobs=False):
    """Show the RSD with some subset of sections."""

    if regular:
        regular = Announcement.regular.running_on(date).order_by("-date_start", "pk")
    if events:
        events = Announcement.events.running_on(date).order_by("event_date", "event_time", "pk")
    if lost_and_found:
        lost_and_found = Announcement.lost_and_found.running_on(date).order_by("-date_start", "pk")
    if jobs:
        midnight = datetime.datetime.combine(date, datetime.time(23, 59))
        jobs = (
            JobListing.published.order_by("is_filled", "-pub_date")
            .filter(pub_date__lte=midnight)
            .filter(pub_date__gte=midnight - datetime.timedelta(days=7))
        )
        if date == datetime.date.today():
            jobs = jobs.filter(is_filled=False)

    if not any(x.count() if x else 0 for x in (regular, events, lost_and_found, jobs)):
        raise Http404

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

    order = lambda x, *ord: x.order_by(*ord) if x else []
    data = {
        "year": date.year,
        "month": date.month,
        "day": date.day,
        "date": date,
        "announcements": regular or [],
        "events": events or [],
        "jobs": jobs or [],
        "lost_and_found": lost_and_found or [],
        "comments": comments[:3],
        "stories": Article.published.order_by("-pub_date").filter(is_racy=False)[:3],
        "for_email": boolean_arg(request.GET.get("for_email", ""), False),
    }
    template = "issue/rsd." + ("txt" if plain else "html")
    return render_to_response(template, data)
예제 #5
0
def approve_comment(request, slug, year, month, day, num, val='1'):
    if not request.user.has_perm('comments.change_publiccomment'):
        if request.is_ajax():
            raise Http404
        else:
            return HttpResponseRedirect("%s?next_page=%s" %
                                        (settings.LOGIN_URL, request.path))

    comment = _get_comment_or_404(year, month, day, slug, num)
    approve = boolean_arg(val, default=True)

    if bool(comment.is_approved) != approve:
        comment.is_approved = approve
        comment.save()

    if request.is_ajax():
        return render_to_response('comment/authorship.html', {
            'comment': comment,
        },
                                  context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect(comment.get_absolute_url())
예제 #6
0
def show_rsd_thing(request,
                   date,
                   plain=False,
                   regular=False,
                   events=False,
                   lost_and_found=False,
                   jobs=False):
    """Show the RSD with some subset of sections."""

    if regular:
        regular = Announcement.regular.running_on(date).order_by(
            '-date_start', 'pk')
    if events:
        events = Announcement.events.running_on(date).order_by(
            'event_date', 'event_time', 'pk')
    if lost_and_found:
        lost_and_found = Announcement.lost_and_found.running_on(date).order_by(
            '-date_start', 'pk')
    if jobs:
        midnight = datetime.datetime.combine(date, datetime.time(23, 59))
        jobs = JobListing.published.order_by('is_filled', '-pub_date') \
                     .filter(pub_date__lte=midnight) \
                     .filter(pub_date__gte=midnight - datetime.timedelta(days=7))
        if date == datetime.date.today():
            jobs = jobs.filter(is_filled=False)

    if not any(x.count() if x else 0
               for x in (regular, events, lost_and_found, jobs)):
        raise Http404

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

    order = lambda x, *ord: x.order_by(*ord) if x else []
    data = {
        'year':
        date.year,
        'month':
        date.month,
        'day':
        date.day,
        'date':
        date,
        'announcements':
        regular or [],
        'events':
        events or [],
        'jobs':
        jobs or [],
        'lost_and_found':
        lost_and_found or [],
        'comments':
        comments[:3],
        'stories':
        Article.published.order_by('-pub_date').filter(is_racy=False)[:3],
        'for_email':
        boolean_arg(request.GET.get('for_email', ''), False),
    }
    template = "issue/rsd." + ('txt' if plain else 'html')
    return render_to_response(template, data)