예제 #1
0
    def post(self):
        datas = self.request.get("data")
        secret = self.request.get("secret")

        datas = datas.split(",")

        userdata = UserData.all().filter("secret = ", secret).get()
        if userdata:
            email = userdata.email.lower()
        else:
            return

        # merge
        imagedatas = {}
        for data in datas:
            hash, tags = data.split(":")
            if hash in imagedatas:
                imagedatas[hash] += ";" + tags
            else:
                imagedatas[hash] = tags

        hkeys = imagedatas.keys()

        keys = [db.Key.from_path("Image", "hash:" + hash) for hash in hkeys]
        userkeys = [db.Key.from_path("UserImage", "email:" + email + "#hash:" + hash) for hash in hkeys]

        images = Image.get(keys)
        userimages = UserImage.get(userkeys)

        updated = []
        for hash, image, userimage in zip(hkeys, images, userimages):
            tags = imagedatas[hash]
            tags = [kk for kk in [k.strip() for k in tags.split(";")] if kk]

            if not image:
                image = Image(key_name="hash:" + hash, hash=hash)
                image.tags = tags
                updated.append(image)
            elif not set(image.tags) == set(tags):
                image.tags = list(set(image.tags).union(tags))
                updated.append(image)

            if not userimage:
                userimage = UserImage(key_name="email:" + email + "#hash:" + hash, email=email, hash=hash)
                userimage.tags = tags
                updated.append(userimage)
            elif not set(userimage.tags) == set(tags):
                userimage.tags = list(set(image.tags).union(tags))
                updated.append(userimage)

        db.put(updated)
        return
예제 #2
0
    def post(self):
        hashs = self.request.get("hash")
        secret = self.request.get("secret")

        hashs = hashs.split(",")

        userdata = UserData.all().filter("secret = ", secret).get()
        if userdata:
            email = userdata.email
        else:
            return

        userkeys = [db.Key.from_path("UserImage", "email:" + email + "#hash:" + hash) for hash in hashs]
        userimages = UserImage.get(userkeys)

        returned = []
        for image in userimages:
            if image:
                returned.append(";".join(image.tags))
            else:
                returned.append("")

        self.response.out.write(",".join(returned))