Ejemplo n.º 1
0
def get_months(request):
    app_context = request.app_context
    routes = app_context.routes
    month_route = routes['month']
    months = []
    for month in app_context.catalog.months(effective_principals(request)):
        y, m = month.split('-')
        label = format_month(int(y), int(m))
        url = month_route.url(
            request, year=y, month=m
        )
        months.append(dict(label=label, url=url))
    return months
Ejemplo n.º 2
0
def homepage_view(request):
    catalog = request.app_context.catalog
    recent_albums = []
    for album in catalog.albums(effective_principals(request), limit=40):
        recent_albums.append(dict(
            title=album.title,
            url=album.url(request),
            date_range=format_date_range(album.date_range)
            )
        )

    return request.app_context.templates.render_to_response(
        'homepage.pt',
        api=TemplateAPI(request),
        recent_albums=recent_albums,
    )
Ejemplo n.º 3
0
def photo_view(request, photo):
    app_context = request.app_context
    images_route = app_context.routes['images']
    version = app_context.images.version(photo, PHOTO_SIZE)
    src = images_route.url(request, fname=version['fname'])
    width, height = version['size']

    catalog = app_context.catalog
    siblings = list(catalog.photos(photo.__parent__,
                                   effective_principals(request)))
    index = 0
    n_siblings = len(siblings)
    for i in xrange(n_siblings):
        if siblings[i].id == photo.id:
            index = i
            break

    app_url = request.application_url.rstrip('/')
    prev_link = next_link = None
    if index > 0:
        prev_link = siblings[index-1].url(request)
    if index < n_siblings -1:
        next_link = siblings[index+1].url(request)
    back_link = model_url(request, photo.__parent__)

    ajax_url = model_url(request, photo, 'edit.json')

    return app_context.templates.render_to_response(
        'photo.pt',
        api=TemplateAPI(request),
        title=photo.title,
        location=photo.location,
        date=format_date(photo.date),
        desc=photo.desc,
        visibility=photo.visibility,
        src=src,
        width=width,
        height=height,
        prev_link=prev_link,
        next_link=next_link,
        back_link=back_link,
        download_link=model_url(request, photo, 'dl'),
        ajax_url=ajax_url,
        actions=simplejson.dumps(get_actions(photo, request)),
    )
Ejemplo n.º 4
0
def _get_photos(request, album):
    app_context = request.app_context
    catalog = app_context.catalog
    images = app_context.images
    images_route = app_context.routes['images']
    photos = []
    for photo in catalog.photos(album, effective_principals(request)):
        thumbnail = images.version(photo, THUMBNAIL_SIZE)
        photos.append(dict(
            id=photo.id,
            url=photo.url(request),
            thumb=thumbnail,
            src=images_route.url(request, fname=thumbnail['fname']),
            visibility=photo.visibility,
            )
        )

    return photos
Ejemplo n.º 5
0
def month_view(request, year, month):
    app_context = request.app_context
    catalog = app_context.catalog
    albums = []
    for album in catalog.albums(
        effective_principals(request),
        month='%s-%s' % (year, month)):
        albums.append(dict(
            title=album.title,
            url=album.url(request),
            date_range=format_date_range(album.date_range),
            )
        )

    return app_context.templates.render_to_response(
        'month.pt',
        api=TemplateAPI(request),
        albums=albums,
        date=format_month(int(year), int(month))
    )
Ejemplo n.º 6
0
def get_new_albums(request, catalog=None):
    catalog = request.app_context.catalog
    return [dict(label=_title_or_path(a), url=brain_url(request, a)) for a in
            catalog.new_albums(effective_principals(request))]