def get()

in hosting/server/pictures.py [0:0]


def get(id, user, cache):
    debug('pictures.py::get::id', id)

    # Get the requested picture
    picid = user.get(()) if isNull(id) else car(id)
    picture = cache.get(pictureid(picid))
    if isNull(picture):
        return mkentry(picid, picid, picid, now(), ())

    # Get image and token from picture
    def image(c):
        img = assoc("'image", c)
        return None if isNull(img) else cadr(img)
    def token(c):
        tok = assoc("'token", c)
        return None if isNull(tok) else cadr(tok)
    img = image(content(picture))
    tok = token(content(picture))

    # Return the picture
    picc = (() if isNull(img) else (("'image", img),)) + (() if isNull(tok) or (user.get(()) != author(picture) and user.get(()) != 'admin') else (("'token", tok),))
    if isNull(picc):
        picentry = mkentry(title(picture), picid, author(picture), updated(picture), ())
        debug('pictures.py::get::picentry', picentry)
        return picentry

    picentry = mkentry(title(picture), picid, author(picture), updated(picture), ("'picture",) + picc)
    debug('pictures.py::get::picentry', picentry)
    return picentry