Exemplo n.º 1
0
def albumsAndImages(webin):
    """ both kinds of entities for the logged in user. Includes images mentioned in albums, and images owned by the user"""
    cks = webin.checkSessionResponse()
    if cks: return cks
    sess = webin.session
    user = sess.user
    albums = album.allAlbums(user)
    images = image.allImages(user)
    imbytopic = {}
    for im in images:
        tp = im.topic
        imbytopic[tp] = im
    missingIms = {}
    for a in albums:
        aim = a.image
        if imbytopic.get(aim, None) == None:
            missingIms[aim] = 1
    mlist = missingIms.keys()
    if len(mlist) > 0:
        getem = image.getImages(mlist)
        images.extend(getem)
    adicts = [a.__dict__ for a in albums]
    imdicts = [i.__dict__ for i in images]
    rs = {"albums": adicts, "images": imdicts}
    return okResponse(rs)
Exemplo n.º 2
0
def allAlbums(webin):
    cks = webin.checkSessionResponse()
    if cks: return cks
    cob = json.loads(webin.content())
    sess = webin.session
    user = cob.get("user", None)
    if not user:
        user = sess.user
    albums = album.allAlbums(user)
    rs = [a.__dict__ for a in albums]
    toemit = {"status": "ok", "value": rs}
    return okResponse(rs)
Exemplo n.º 3
0
def clearBandwidthExceeded(usr):
    if not getattr(usr, "bandwidth_exceeded", False):
        if getattr(usr, "bandwidth_warning", False):
            usr.bandwidth_warning = 0
            usr.dynsave(isNew=False)
        return
        # already cleared
    usr.bandwidth_warning = 0
    usr.bandwidth_exceeded = 0
    usr.dynsave(isNew=False)
    tp = usr.topic
    albums = album.allAlbums(usr.topic, onlyPublished=True)
    for a in albums:
        vprint("clearWidthExceeded " + a.topic)
        a.sendPageToS3()
Exemplo n.º 4
0
def whenBandwidthExceeded(usr, bwa=None, bwu=None):
    if getattr(usr, "bandwidth_exceeded", False):
        return False  # already known to be exceeded
    if bwa:  # this print is for the log. For use of this funtion from a shell, bwa,bwu, and this print, are optional
        print "Bandwidth Exceeded for User " + (
            usr.topic) + " allocation " + misc.bytesstring(
                bwa) + " used " + misc.bytesstring(bwu)
    albums = album.allAlbums(usr.topic, onlyPublished=True)
    for a in albums:
        vprint("bandWidthExceeded " + a.topic)
        bandwidthExceededToS3(a)

    ses.sendBandwidthEmail(usr)
    usr.bandwidth_exceeded = 1
    usr.dynsave(isNew=False)
    return True
Exemplo n.º 5
0
def allImages(webin):
    " featured images; ie images with featured albums "
    cob = json.loads(webin.content())
    includeAlbums = cob.get("includeAlbums")
    forUser = cob.get("forUser")
    featuredOnly = cob.get("featuredOnly", False)
    if includeAlbums:
        rs = album.allImagesForAlbums(featuredOnly=featuredOnly, asDicts=True)
    else:
        rsi = image.allImages(publicOnly=True)
        rs = [im.__dict__ for im in rsi]
    return okResponse(rs)
    albs = album.allAlbums(featuredOnly=True)
    #ims = image.allImages()
    #cnts = image.albumCounts()
    abyt = {}  # albums by topic
    abyi = {}  # albums by image topic
    for a in albs:
        itp = a.image
        cab = abyi.get(itp, None)
        if cab == None:
            cab = [a.__dict__]
        else:
            cab.append(a.__dict__)
    imtps = keys(abyi)
    ims = image.getDicts(imtps)
    for i in ims:
        i.albums = abyi[i.topic]
    return okResponse()
    rs = []
    rd = {}  # by topic
    if forUser:
        utopic = "/user/" + forUser
    for im in ims:
        if not getattr(im, "atS3", None):
            continue
        if not getattr(im, "isPublic", None):
            continue
        if forUser:
            if getattr(im, "owner", None) != utopic:
                continue
        tp = im.topic
        acnt = cnts.get(tp, 0)
        d = im.__dict__
        rd[tp] = d
        d["albums"] = []
        d["albumCount"] = acnt
        rs.append(d)
    # associate the featured or unique album with each image
    for alb in albs:
        if not getattr(alb, "published", False):
            continue
        imd = rd.get(alb.image, None)

        if imd:
            imd["albums"].append(alb.__dict__)
            """
      if im.albumCount == 1:
        im.album = alb.__dict__
      else:
        if getattr(alb,"featured",False):
          im.album = alb.__dict__
      """
    return okResponse(rs)