Ejemplo n.º 1
0
    def DELETE(self):
        if not self.session.has_group("phots"):
            return Unauthorized()

        phot = self.request.id
        if len(phot.rsplit(".")) == 1:
            f = r.table(pm.Phot.table).filter({"short_code": phot})\
                .coerce_to("array").run()
        else:
            f = r.table(pm.Phot.table).filter({"filename": phot})\
                .coerce_to("array").run()

        if f:
            photo = pm.Phot(**f[0])
            photo.disable = not photo.disable if "disable" in photo else True
            photo.save()

            searcher = PhotSearcher()
            searcher.update(photo)
            searcher.save()

            return {"success": True, "state": photo.disable}

        else:
            return {
                "success": False,
                "error": "That image couldn't be found. :/"
            }
Ejemplo n.º 2
0
    def POST(self):
        if not self.session.has_group("phots"):
            return Unauthorized()

        new_name = self.request.get_param("name")
        tags = self.request.get_param("tags")

        if tags:
            tag = tags.split(",")
        else:
            tag = []

        phot = self.request.id
        if len(phot.rsplit(".")) == 1:
            f = r.table(pm.Phot.table).filter({"short_code": phot})\
                .coerce_to("array").run()
        else:
            f = r.table(pm.Phot.table).filter({"filename": phot})\
                .coerce_to("array").run()

        if f:
            photo = pm.Phot(**f[0])
            photo.title = new_name
            photo.tags = tag
            photo.save()

            searcher = PhotSearcher()
            searcher.update(photo)
            searcher.save()

            return Redirect("/phots/" + photo.short_code)

        else:
            return NotFound()
Ejemplo n.º 3
0
    def POST(self):
        current = pm.Phot(self.request.get_param("phot"))

        if current.filename:
            current.disable = not current.disable if "disable" in current else True
            current.save()

            return {"success": True, "state": current.disable}

        else:
            return {
                "success": False,
                "error": "That image couldn't be found. :/"
            }
Ejemplo n.º 4
0
    def build(self):
        phot = pm.Phot(self.data)

        path = ''.join([c.dirs.gifs, phot.filename])

        logger.info("Downloading photo {}".format(phot.url))
        req = requests.get(phot.url)

        if req.status_code == 200:
            with open(path, 'w+b') as f:
                f.write(req.content)

            logger.info("Download for photo {} finished.".format(phot.url))

        else:
            logger.warn("Resource {} failed with status code: {}".format(
                phot.url, req.status_code))
Ejemplo n.º 5
0
    def GET(self):
        phot = self.request.id

        # check if its a short code by looking for an extension
        # otherwise we assume it's a filename
        if len(phot.rsplit(".")) == 1:
            f = r.table(pm.Phot.table).filter({"short_code": phot})\
                .coerce_to("array").run()
        else:
            f = r.table(pm.Phot.table).filter({"filename": phot})\
                .coerce_to("array").run()

        if not f:
            return NotFound()

        if "disable" in f[0] and f[0]["disable"] and \
                not self.session.has_group("phots"):
            return NotFound()

        photo = pm.Phot(**f[0])

        return photo
Ejemplo n.º 6
0
    def GET(self):
        phot = self.request.id

        # check if its a short code by looking for an extension
        # otherwise we assume it's a filename

        # TODO: This could probably be just one but I'm too lazy to try
        if len(phot.rsplit(".")) == 1:
            f = r.table(pm.Phot.table).filter({"short_code": phot})\
                .coerce_to("array").run()
        else:
            f = r.table(pm.Phot.table).filter({"filename": phot})\
                .coerce_to("array").run()

        if not f:
            return NotFound()

        if "disable" in f[0] and f[0]["disable"] and \
                not self.session.has_group("phots"):
            return NotFound()

        photo = pm.Phot(f[0]["id"])

        return {"phot": photo}