Exemplo n.º 1
0
def recent(request, tag_name=None, page=None):
    tag = Tag.with_name(tag_name)
    if not tag:
        photo_set = Photo.recent()
        video_set = Video.recent()
    else:
        photo_set = tag.get_recent_photos()
        video_set = tag.get_recent_videos()

    media_set = list(photo_set) + list(video_set)
    total = len(media_set)
    page, start, end, nb_pages = get_page(page, total)

    medias = media_set[start:end]
    total_pages = range(nb_pages)

    slug = "/%s/recent/" % G_URL
    if tag_name:
        slug += "%s/" % tag_name

    params = {
        "tag": tag,
        "page": page,
        "slug": slug,
        "tag_name": tag_name,
        "nb_pages": nb_pages,
        "total_pages": total_pages,
        "medias": medias,
    }
    params.update(DEFAULT_PARAMS)
    return render_to_response("gallery/tag.html", params, context_instance=RequestContext(request))
Exemplo n.º 2
0
def date(request, year, month, day, page=None):
    year = int(year)
    month = int(month)
    day = int(day)
    photo_set = Photo.for_date(year, month, day)
    video_set = Video.for_date(year, month, day)
    media_set = list(photo_set) + list(video_set)

    total = len(media_set)
    page, start, end, nb_pages = get_page(page, total)

    medias = media_set[start:end]
    total_pages = range(nb_pages)
    slug = "%s/date/%s/%s/%s/" % (G_URL, year, month, day)

    human_date = datetime.date(year, month, day).strftime("%A %d %B")

    params = {
        "year": year,
        "month": month,
        "day": day,
        "page": page,
        "slug": slug,
        "human_date": human_date,
        "nb_pages": nb_pages,
        "total_pages": total_pages,
        "medias": medias,
    }
    params.update(DEFAULT_PARAMS)
    return render_to_response("gallery/date.html", params, context_instance=RequestContext(request))
Exemplo n.º 3
0
def medias_in_tag(request, tag_name, photo_id=None, video_id=None, page=None):
    if photo_id:
        return photo(request, photo_id, in_tag_name=tag_name)
    elif video_id:
        return video(request, video_id, in_tag_name=tag_name)
    else:
        if tag_name.find("+") > -1:
            # combination of tags
            media_set = Tag.build_set(tag_name)
            tag = None
        else:
            # display all photos of the tag
            tag = Tag.with_name(tag_name)
            if not tag:
                raise Http404
            else:
                photo_set = tag.photo_set.order_by("timestamp")
                video_set = tag.video_set.order_by("time_created")
                media_set = list(photo_set) + list(video_set)

        total = len(media_set)
        page, start, end, nb_pages = get_page(page, total)

        medias = media_set[start:end]
        total_pages = range(nb_pages)
        slug = "%s/tag/%s/" % (G_URL, tag_name)
        params = {
            "tag": tag,
            "page": page,
            "slug": slug,
            "tag_name": tag_name,
            "nb_pages": nb_pages,
            "total_pages": total_pages,
            "medias": medias,
        }
        params.update(DEFAULT_PARAMS)
        return render_to_response("gallery/tag.html", params, context_instance=RequestContext(request))