예제 #1
0
    def test_it(self):
        root = DummyModel()
        b = root['b'] = DummyModel()
        c = b['c'] = DummyModel()

        import webob
        req = webob.Request.blank('/')

        from happy.traversal import model_url
        self.assertEqual(model_url(req, root), 'http://localhost/')
        self.assertEqual(model_url(req, c), 'http://localhost/b/c/')
        self.assertEqual(model_url(req, c, 'foo', 'bar'),
                         'http://localhost/b/c/foo/bar')
예제 #2
0
파일: album.py 프로젝트: chrisrossi/edwin
def get_actions(request, album, photos):
    if not has_permission(request, 'edit', album):
        return []

    actions = []
    visibilities = set()
    for photo in photos:
        visibilities.add(photo['visibility'])

    if len(visibilities) == 1:
        visibility = iter(visibilities).next()
        if visibility != 'public':
            actions.append(dict(name='publish_all',
                                title='publish all photos'))
        if visibility != 'private':
            actions.append(dict(name='hide_all',
                                title='hide all photos'))

    else:
        actions.append(dict(name='publish_all',
                            title='publish all photos'))
        actions.append(dict(name='hide_all',
                            title='hide all photos'))
        if 'new' in visibilities:
            actions.append(dict(name='publish_new',
                                title='publish new photos'))
            actions.append(dict(name='hide_new',
                                title='hide new photos'))
            if 'public' in visibilities:
                actions.append(dict(name='hide_public',
                                    title='hide public photos'))
            if 'private' in visibilities:
                actions.append(dict(name='publish_hidden',
                                    title='publish hidden photos'))

    actions.append(dict(name='delete_all',
                        title='delete all photos',
                        href=model_url(request, album, 'delete_photos')))
    if 'new' in visibilities:
        actions.append(dict(name='delete_new',
                            title='delete new photos',
                            href=model_url(request, album,
                                           'delete_photos', 'new')))
    if 'private' in visibilities:
        actions.append(dict(name='delete_hidden',
                            title='delete hidden photos',
                            href=model_url(request, album,
                                           'delete_photos', 'private')))

    return actions
예제 #3
0
파일: photo.py 프로젝트: chrisrossi/edwin
def delete_photo_view(request, photo):
    request.app_context.catalog.unindex(photo)
    trash = find_trash(photo)
    trash_id = trash.trash(photo)
    response = HTTPFound(location=model_url(request, photo.__parent__))
    response.set_cookie('undo', 'trash:%s|Photo+deleted.' % trash_id)
    return response
예제 #4
0
파일: album.py 프로젝트: chrisrossi/edwin
def album_view(request, album):
    app_context = request.app_context
    months_route = app_context.routes['month']
    if album.date_range is not None:
        date = album.date_range[0]
        back_link = months_route.url(
            request, year=str(date.year), month='%02d' % date.month
        )
    else:
        back_link = ''
    photos = _get_photos(request, album)

    return app_context.templates.render_to_response(
        'album.pt',
        api=TemplateAPI(request),
        title=album.title,
        location=album.location,
        desc=album.desc,
        date_range=format_date_range(album.date_range),
        date_range_edit=format_editable_date_range(album.date_range),
        photos=photos,
        back_link=back_link,
        actions=get_actions(request, album, photos),
        ajax_url=model_url(request, album, 'edit.json'),
    )
예제 #5
0
파일: photo.py 프로젝트: chrisrossi/edwin
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)),
    )
예제 #6
0
파일: undo.py 프로젝트: chrisrossi/edwin
def undo_view(request, code):
    if not code.startswith('trash:'):
        return None

    # XXX Need security here.  Probably need to add api to trash to be able
    # to retrieve context(s) involved for purposes of security checking, before
    # performing undo operation.
    trash_id = code[6:]
    trash = find_trash(request.context)
    restored = trash.restore(trash_id, request.app_context.catalog)
    response = HTTPFound(location=model_url(request, restored))
    response.set_cookie('undo', '')
    return response
예제 #7
0
파일: photo.py 프로젝트: chrisrossi/edwin
def get_actions(photo, request):
    if not has_permission(request, 'edit', photo):
        return []

    actions = []
    if photo.visibility != 'public':
        actions.append(dict(name='publish', title='publish photo'))
    if photo.visibility != 'private':
        actions.append(dict(name='hide', title='hide photo'))
    actions.append(dict(name='left', title='rotate left'))
    actions.append(dict(name='right', title='rotate right'))
    actions.append(dict(name='delete', title='delete photo',
                        href=model_url(request, photo, 'delete')))

    return actions
예제 #8
0
파일: album.py 프로젝트: chrisrossi/edwin
def delete_photos_view(request, album):
    if request.subpath:
        visibility = request.subpath.pop(0)
    else:
        visibility = None

    photos = []
    for photo in album.photos():
        if visibility is None or photo.visibility == visibility:
            photos.append(photo)

    assert photos, "Nothing to delete."

    catalog = request.app_context.catalog
    catalog.unindex_photos_in_album(album, photos)

    trash = find_trash(album)
    trash_id = trash.trash_photos_in_album(album, photos)

    response = HTTPFound(location=model_url(request, album))
    response.set_cookie('undo', 'trash:%s|Deleted+photos' % trash_id)
    return response