Ejemplo n.º 1
0
    def _POST(self, *param, **params):
        if not validates_tag(self):
            self.logger.debug("Failed to create tag. The value of input is invalid.")
            return web.badrequest(self.view.alert)

        tag = findby1name(self.orm, self.input.name)
        if tag:
            self.logger.debug("Failed to create tag. The same tag already exist - id='%s'" % (tag.id))
            return web.conflict(web.ctx.path)

        new_tag = new(self.input.name)

        save(self.orm, new_tag)
        return web.created(None)
Ejemplo n.º 2
0
    def _POST(self, *param, **params):
        if not validates_tag(self):
            self.logger.debug(
                "Failed to create tag. The value of input is invalid.")
            return web.badrequest(self.view.alert)

        tag = findby1name(self.orm, self.input.name)
        if tag:
            self.logger.debug(
                "Failed to create tag. The same tag already exist - id='%s'" %
                (tag.id))
            return web.conflict(web.ctx.path)

        new_tag = new(self.input.name)

        save(self.orm, new_tag)
        return web.created(None)
Ejemplo n.º 3
0
    def _GET(self, *param, **params):
        if not validates_query(self):
            self.logger.debug(
                "Failed to get tags. The value of query is invalid.")
            return web.badrequest(self.view.alert)

        if not validates_page(self):
            self.logger.debug(
                "Failed to get tags. The value of page is invalid.")
            return web.badrequest(self.view.alert)

        if is_param(self.input, 'q') is True:
            tags = findbyand(self.orm, self.input.q)
            if not tags:
                self.logger.debug(
                    "Failed to get tags. No such tag - query=%s" %
                    self.input.q)
                return web.nocontent()
            self.view.search_value = self.input.q
        else:
            tags = findbyall(self.orm)
            self.view.search_value = ""
            if not tags:
                self.logger.debug("Failed to get tag. No tags found.")
                return web.notfound()

        if is_param(self.input, 'p') is True:
            start = int(self.input.p)
        else:
            start = 0

        pager = Pager(tags, start, TAG_LIST_RANGE)
        if not pager.exist_now_page():
            self.logger.debug(
                "Failed to get tag. Could not find page - page=%s" %
                self.input.p)
            return web.nocontent()

        self.view.pager = pager

        if self.is_mode_input():
            self.view.tag = new('')

        self.view.input = self.input
        return True
Ejemplo n.º 4
0
    def _GET(self, *param, **params):
        if not validates_query(self):
            self.logger.debug("Failed to get tags. The value of query is invalid.")
            return web.badrequest(self.view.alert)

        if not validates_page(self):
            self.logger.debug("Failed to get tags. The value of page is invalid.")
            return web.badrequest(self.view.alert)

        if is_param(self.input, 'q') is True:
            tags = findbyand(self.orm, self.input.q)
            if not tags:
                self.logger.debug("Failed to get tags. No such tag - query=%s" % self.input.q)
                return web.nocontent()
            self.view.search_value = self.input.q
        else:
            tags = findbyall(self.orm)
            self.view.search_value = ""
            if not tags:
                self.logger.debug("Failed to get tag. No tags found.")
                return web.notfound()

        if is_param(self.input, 'p') is True:
            start = int(self.input.p)
        else:
            start = 0

        pager = Pager(tags, start, TAG_LIST_RANGE)
        if not pager.exist_now_page():
            self.logger.debug("Failed to get tag. Could not find page - page=%s" % self.input.p)
            return web.nocontent()

        self.view.pager = pager

        if self.is_mode_input():
            self.view.tag = new('')

        self.view.input = self.input
        return True