Example #1
0
    def post(self, account):
        """
            Post records handler
        """
        struct = yield check_json(self.request.body)
        db = self.settings["db"]

        format_pass = True if struct else False
        if not format_pass:
            self.set_status(400)
            self.finish({"JSON": format_pass})
            return

        if account == self.get_current_user():
            struct["account"] = account

        # check if ORGs follows same pattern.

        else:
            self.set_status(404)
            self.finish({"WARNING": "Pre-Access patterns research"})
            return

        record = yield self.new_detail_record(struct)

        if not record:
            model = "Records"
            error = {"record": False}
            reason = {"duplicates": [("Record", "uniqueid"), (model, "uuid")]}

            message = yield self.let_it_crash(struct, model, error, reason)

            self.set_status(400)
            self.finish(message)
            return

        # -- handle this out-of-band.

        resource = {"account": account, "resource": "records", "uuid": record}

        update = yield new_resource(db, resource)

        # logging new resource update
        logging.info("update %s" % update)

        if not update:
            logging.warning("account: %s new_resource record: %s update." % (account, record))

        self.set_status(201)
        self.finish({"uuid": record})
Example #2
0
    def post(self):
        """
            POST tasks handler
        """
        struct = yield check_json(self.request.body)
        db = self.settings["db"]

        format_pass = True if struct else False
        if not format_pass:
            self.set_status(400)
            self.finish({"JSON": format_pass})
            return

        task = yield self.new_task(struct)

        if not task:
            model = "Tasks"
            error = {"task": False}
            reason = {"duplicates": [("Task", "uniqueid"), (model, "uuid")]}

            message = yield self.let_it_crash(struct, model, error, reason)

            self.set_status(400)
            self.finish(message)
            return

        if "accountcode" in struct:

            account = struct.get("accountcode")

            resource = {"account": account, "resource": "tasks", "uuid": task}

            exist = yield self.check_exist(account)

            logging.info("check if exist %s " % exist)

            if exist:
                update = yield new_resource(db, resource)

                logging.info("update %s" % update)

                flag = yield self.set_assigned_flag(account, task)

        logging.info("new spawned task %s " % task)

        self.set_status(201)
        self.finish({"uuid": task})