示例#1
0
def editAlbum(webin):
    """
  Handles the api/editAlbum request
  """
    cks = webin.checkSessionResponse()
    if cks: return cks
    sess = webin.session
    user = sess.user
    cob = json.loads(webin.content())
    Logr.log("api", "COB: " + str(cob))

    topic = cob.get("topic", None)
    albumD = album.loadAlbumD(topic, webin.pageStore)
    Logr.log("api", "ALBUM: " + str(album.__dict__))

    if albumD.owner != user:
        return failResponse("notOwner")
    Logr.log("api", "EDITING ALBUM " + topic)

    caption = cob.get("caption", None)
    if caption == None:
        caption = "unnamed"
    description = cob.get("description", None)
    if description == None:
        description = ""
    albumD.caption = caption
    albumD.description = description
    albumD.externalLink = cob.get("externalLink", None)
    albumD.dynsave()
    albumD.updateS3()
    return okResponse(albumD.__dict__)
示例#2
0
 def loadAlbum(u, inm, aid, altCaption=None):
     tp = albumTopic(u, inm, aid)
     albumList.append(tp)
     vprint("loading ", tp)
     #albums[u+"_"+inm+"_"+aid] = models.loadAlbumD(tp)
     alb = album.loadAlbumD(tp)
     if alb == None: print "MISSING ", tp
     if altCaption != None:
         alb.caption = altCaption
     albums[tp] = alb.__dict__
示例#3
0
def deleteAlbum(webin):
    cks = webin.checkSessionResponse()
    if cks: return cks
    sess = webin.session
    user = sess.user
    cob = json.loads(webin.content())
    Logr.log("api", "DELETE SNAP COB: " + str(cob))
    topic = cob["topic"]
    albumD = album.loadAlbumD(topic, webin.pageStore)
    if not albumD:
        return okResponse("already deleted")
    if user != albumD.owner:
        return failResponse("notOwner")
    """ todo :delete the snaps db file """
    albumD.delete()
    #snaps.closeStore(webin.pageStore)
    return okResponse()
示例#4
0
def publishAlbum(webin):
    cks = webin.checkSessionResponse()
    if cks: return cks
    sess = webin.session
    user = sess.user
    cob = json.loads(webin.content())
    Logr.log("api", "COB: " + str(cob))

    topic = cob.get("topic", None)
    albumD = album.loadAlbumD(topic, webin.pageStore)

    if albumD.owner != user:
        failResponse("notOwner")
    Logr.log("api", "EDITING ALBUM " + topic)
    albumD.publish()  #compressJs=constants.compressJs)
    #snaps.closeStore(webin.pageStore)
    return okResponse()
示例#5
0
def editImage(webin):
    """
  Handles the api/addSnap request; this is used for editing snaps too
  """
    cks = webin.checkSessionResponse()
    if cks: return cks

    sess = webin.session
    user = sess.user
    uname = models.pathLast(user)
    #  Logr.activeTags = ["dispatch","api"]
    #Logr.log("api",str(napi.__dict__))
    cob = json.loads(webin.content())
    Logr.log("api", "COB: " + str(cob))
    imagetopic = cob["image"]
    albumTopic = cob.get("albumTopic", None)
    albumTitle = cob.get("albumTitle", "")
    albumDescription = cob.get("albumDescription", "")
    imD = image.loadImageD(imagetopic, webin.pageStore)
    Logr.log("api", "IMD " + str(imD.__dict__))
    imowner = getattr(imD, "owner", None)
    Logr.log("api", "OWNER " + str(imowner))
    if not imowner:
        imowner = getattr(imD, "user", None)
        imD.owner = imowner
    if user != imowner:
        return failResponse("notOwner")
    imD.title = cob["title"]
    imD.description = cob["description"]
    imD.author = cob.get("author", None)
    imD.year = cob.get("year", None)
    imD.externalLink = cob.get("externalLink", None)
    imD.isPublic = cob.get("isPublic", None)
    imD.license = cob.get("license", None)
    imD.tags = cob.get("tags", None)
    imD.dynsave()
    if albumTopic:
        albumD = album.loadAlbumD(albumTopic, webin.pageStore)
        albumD.caption = albumTitle
        albumD.description = albumDescription
        albumD.dynsave()

    return okResponse({"title": imD.title, "description": imD.description})
示例#6
0
def emitJson(webin):
    itm = time.time()
    sess = getattr(webin, "session", None)
    user = None
    if sess:
        user = sess.user
    jsonMimeType = "application/json"
    #jsonMimeType = "text/plain";
    jsonMissing = json.dumps({"status": "error", "id": "missing"})
    path = webin.path
    parsedPath = parseApiPath(webin.path)
    name = parsedPath.name
    category = parsedPath.category
    owner = parsedPath.owner
    vprint("category", category)
    if category == "image":
        imageTopic = "/image/" + owner + "/" + name
        #albumTopic = "/album/"+imowner+"/"+imname+"/"+album;
        Logr.log("api", "imageTopic=" + imageTopic)
        im = image.loadImageD(imageTopic, webin.pageStore)
        if not im:
            #todo add error page here
            return WebResponse('200 OK', jsonMimeType, jsonMissing)
        #Logr.log("api","IMAGE "+str(im.__dict__))
        #print "IMAGE",im.__dict__
        imob = {}
        improps = [
            "topic", "externalLink", "dimensions", "author", "title", "owner",
            "tags", "description", "name", "year", "tilingDepth", "license",
            "shared", "beenTiled", "atS3", "current_item_create_time",
            "source", "isPublic", "s3Storage"
        ]

        misc.setDictPropsFromObject(imob, im, improps)
        #imob = {"id":im.topic,"dimensions":im.dimensions,"title":getattr(im,"title",""),"owner":"/user/"+owner,
        #      "author":getattr(im,"author",""),"source":getattr(im,"source",""),"externalLink":getattr(im,"externalLink","")}
        #js = json.dumps(im.__dict__)
        #Logr.log("api","IMAGEJS"+js)
        js = json.dumps(imob)
        Logr.log("api", "IMAGEJS2" + js)
        return WebResponse('200 OK', jsonMimeType, js)
    if category == "album":
        """ the album id "-" means the snaps album of the current user """
        imname = getattr(parsedPath, "name", None)
        id = getattr(parsedPath, "id", None)
        if not id:
            js = json.dumps({"status": "error", "id": "bad_path"})
            return WebResponse('200 OK', jsonMimeType, js)
        albumTopic = "/album/" + owner + "/" + imname + "/" + id
        imTopic = "/image/" + owner + "/" + imname
        #ofl = open("/mnt/ebs0/imagediverdev/static"+albumTopic+"/topic.json","w")
        if id == "-":  # the snaps album, if any
            if not user:
                return failResponse("missing")
            sna = dynamo.getSnapsAlbumTopic(imTopic, user)
            if sna:
                albumTopic = sna
            else:
                return failResponse("missing")

        albumD = album.loadAlbumD(albumTopic, webin.pageStore)
        js = albumD.compute_json(wrapInStatus=True)
        #snapst.closeStore(webin.pageStore)
        return WebResponse('200 OK', jsonMimeType, js)
    if category == "snap":
        imname = getattr(parsedPath, "name", None)
        id = getattr(parsedPath, "id", None)
        subid = getattr(parsedPath, "subid", None)
        if (not id) or (not subid):
            js = json.dumps({"status": "error", "id": "bad_path"})
            return WebResponse('200 OK', jsonMimeType, js)
        snapTopic = "/snap/" + owner + "/" + imname + "/" + id + "/" + subid
        #ofl = open("/mnt/ebs0/imagediverdev/static"+albumTopic+"/topic.json","w")
        snapD = snapm.loadSnapD(snapTopic, webin.pageStore)
        js = snapD.compute_json(wrapInStatus=True)
        #snapst.closeStore(webin.pageStore)
        return WebResponse('200 OK', jsonMimeType, js)

    OBSOLETE()
    #ds  = dstore.DStore(constants.descriptorStore)
    #imds = ds.descriptor(topicpath,'/type/imageD')
    snaps = models.snapsInAlbum(albumTopic)
    #theStore.topicsWithPropertyValue('/type/snapD','album',albumTopic)
    albums = models.albumsForImage(imageTopic)
    Logr.log("image", "snaps: " + str(snaps))
    Logr.log("image", "image: " + str(im.__dict__))
    Logr.log("image", "albums: " + str(albums))
    snapDs = theStore.descriptor(snaps, '/type/snapD')
    albumDs = theStore.descriptor(albums, '/type/albumD')
    Logr.log("image", "albumDs" + str(albumDs))
    thisAlbumD = None
    for albumD in albumDs:
        if albumD["topic"] == albumTopic:
            thisAlbumD = albumD
            break

    if im:
        otxt = pg0 + \
          "<script>" + \
          "var imD="+json.dumps(im.__dict__)+";\n" + \
          "var snapDs="+json.dumps(snapDs)+";\n" + \
          "var albumDs="+json.dumps(albumDs)+";\n"+ \
          "var albumD="+json.dumps(thisAlbumD)+";\n"+ \
          "var loggedInUser='******';\n"
        if forHomePage:
            otxt += "page.thisIsHomePage=1;\n"
        otxt += pg1

    else:
        otxt = "NO SUCH IMAGE for " + topicpath
    snapst.closeStore(webin.pageStore)

    #Logr.log("image","description: "+str(imds))
    return WebResponse('200 OK', 'text/html', otxt)
示例#7
0
def emitAlbumPage(webin, parsedPath, parsedQuery, forHomePage):
    pageStore = {}
    import model.album
    album = model.album
    vprint("parsedQuery " + str(parsedQuery))
    vprint("emitAlbumPage")
    sess = webin.session
    if sess == None:
        user = ""
    else:
        user = sess.user

    qs = getattr(webin, "queryString", None)
    published = 0  # is this the published version?
    """
  now, if we're here its unpublished 
  if qs:
    qsp = urlparse.parse_qs(qs)
    published = 0 if qsp.get('unpublished',False) else 1
  """

    name = parsedPath.name
    Logr.log("newdb", str(name))
    if len(name) < 3:
        return gen.emitNotFound(webin)

        #return gen.genStaticPage(webin,"ImageDiver Message"," <center><b>404</b></center><p><center>No such page</center></p>");

    imowner = name[0]
    imname = name[1]
    albumname = name[2]
    albumTopic = "/album/" + imowner + "/" + imname + "/" + albumname
    imageTopic = "/image/" + imowner + "/" + imname
    if albumname == "-":
        albumD = "-"
    else:
        albumD = album.loadAlbumD(albumTopic, webin.pageStore)

    if not albumD:
        #todo add error page here
        return gen.genStaticPage(webin, "ImageDiver Message",
                                 "<center><b>No such album</b></center>")
    im = image.loadImageD(imageTopic, webin.pageStore)
    imHasAlbums = album.hasAlbums(
        imageTopic, user)  # does this user have albums on this image
    imDict = models.toDict(im, [
        "dimensions", "title", "name", "author", "year", "externalLink",
        "description", "owner", "topic", "tilingDepthBump", "zoomDepthBump",
        "source"
    ])

    if albumD == "-":
        ownerD = models.loadUserD(user, webin.pageStore)
        ownerName = getattr(ownerD, "name", None)

        options = {
            "imageD": imDict,
            "imageTopic": imageTopic,
            "loggedInUser": user,
            "ownerName": ownerName,
            "albumOwner": user,
            "published": False
        }
        otxt = genAlbumPage(options)
        return htmlResponse(otxt)

    #print "IMDICT ",imDict
    author = getattr(im, "author", None)
    if author == None:
        author = ""
    else:
        author = ", " + author
    ttl = getattr(im, "title", "")
    albowner = albumD.owner
    vprint("OWNER ", albowner, user)
    if (not constants.devVersion) and (albowner != user):
        return gen.genStaticPage(
            webin, "ImageDiver Message",
            "<center><b>This is an unpublished album</b></center>")

    beenPublished = getattr(albumD, "published", 0)
    vprint("beenPublished", beenPublished)
    ownerD = models.loadUserD(albowner, webin.pageStore)
    ownerName = getattr(ownerD, "name", None)
    apub = getattr(albumD, "published", None)
    if published and (not apub):
        return gen.genStaticPage(
            webin, "ImageDiver Message",
            "<center><b>This album has not yet been published</b></center>")

    #imageTopic = albumD.image
    #options = {"imageD":imDict,"albumOwner":albumD.owner,"albumOwnerName":ownerName,"loggedInUser":user,"hasAlbums":imHasAlbums,
    #          "albumTopic":albumD.topic,"published":published,"beenPublished":beenPublished,"path":"/"}

    options = {
        "imageD": imDict,
        "albumOwner": albumD.owner,
        "albumOwnerName": ownerName,
        "loggedInUser": user,
        "imTitle": ttl,
        "imAuthor": author,
        "albumTopic": albumD.topic,
        "imageTopic": imageTopic,
        "published": published,
        "beenPublished": beenPublished,
        "path": webin.path
    }
    vprint("OPTIONS", options)
    otxt = genAlbumPage(options)
    #snaps.closeStore(webin.pageStore)

    return htmlResponse(otxt)
示例#8
0
ii = tl.findIntersectingTiles(rct,5,[])
print [t.id for t in ii]

imdir = imd.imDir()
ofl = imdir+"cfoob.jpg"
afl = imdir+"afoob.jpg"
#tl.assembleTiles(ii,ofl)
tl.cropFromTiles(ofl,rct,targetWidth=500,targetHeight=None,targetArea=None,asmFile=afl)

til = tl.tiles[0]
ifl = til.filename()
pim = image.openImageFile(ifl)



aa = album.loadAlbumD('/album/4294b0e/the_dutch_proverbs/1')
dyn.assertPublished(aa,True)
cnts = image.albumCounts()

albumD = aa
published = getattr(albumD,"published",False)
if published and not force:
  return
albumD.published = 1
saveAlbum(albumD)
im = albumD.image
ii = dyn.getImageToAlbumsItem(albumD)
tab = getTable("ImageToAlbums")
ii["published"] = 1
ii.put()
示例#9
0
import model.models
models = model.models
import model.image
image = model.image
import model.album
album = model.album
from model.image import Point,Rect
import store.snaps
snaps = store.snaps
import store.jobs
jobs = store.jobs
import api.job
ajob = api.job

import ops.logs
logs = ops.logs
import store.log
logstore = store.log


albumD = album.loadAlbumD('/album/test22/t14/12')

js = albumD.compute_json()
print js
albumD.publish()