Exemplo n.º 1
0
    def basic_validation(self,items):
    #items:validation対象となるデータ群
    #{kind:"アイテムの種類",type:"データタイプ,"item:"対象データ",len:"桁長",lenc:"桁長符号(以上、以下、イコール)",
    # alpha:"英文字",alphac:"英文字の扱い(NG、OK、ONLY)",
    # numer:"数字",numerc:"数字の扱い(NG、OK、ONLY)",code}
        try:
            code = 0
            msg ="エラーなし"
            for item in items:
                if item["item"] == '':
                #入力値チェック
                    msg = item["type"]+"が入力されていません"
                    code = 1
                    break

                else:
                #桁数確認
                    if item["lenc"] == "MT" and len(item["item"]) < item["len"]:
                        msg =item["type"]+"は"+str(item["len"])+"桁以上にしてください"
                        code = 1

                    elif item["lenc"] == "LT" and len(item["item"]) > item["len"]:
                        msg =item["type"]+"は"+str(item["len"])+"桁以下にしてください"
                        code = 1

                    elif item["lenc"] == "EQ" and len(item["item"]) <> item["len"]:
                        msg =item["type"]+"は"+str(item["len"])+"桁にしてください"
                        code = 1


                #数字の扱い

                #英文字の扱い

                #マイナス値の確認
                    if item['item'] < 0:
                        msg = item["kind"] + "がマイナスです"
                        code = 1

                #コード存在の確認
                    if item.has_key('code') and item["code"] == "Y":
                        if item["kind"] == "空港":
                            fetch = models.airport().get_by_id(item["item"])

                        elif item["kind"] == "航空会社":
                            fetch = models.airline().get_by_id(item["item"])

                        elif item["kind"] == "空路":
                            fetch = models.air_route().get_by_id(item["item"])

                        if fetch is not None:
                            msg = item["kind"] + "が登録済みです"
                            code = 1

                    if code == 1:
                        break

        except Exception as e:
            code = 1
            msg = "message:{0}".format(e.message)

        res = {'code':code,'msg':msg}
        return res
Exemplo n.º 2
0
    def post(self):
        if self.request.get("mode") == "u":
            items =[{"item":self.request.get("portname"),"type":"名称","kind":"空港","len":50,"lenc":"LT"},
                    {"item":self.request.get("portcode"),"type":"コード","kind":"空港","len":3,"lenc":"EQ"},
                    {"item":self.request.get("location"),"type":"所在地","kind":"空港","len":100,"lenc":"LT"}]

        else:
            items =[{"item":self.request.get("portname"),"type":"名称","kind":"空港","len":50,"lenc":"LT"},
                    {"item":self.request.get("portcode"),"type":"コード","kind":"空港","len":3,"lenc":"EQ","code":"Y"},
                    {"item":self.request.get("location"),"type":"所在地","kind":"空港","len":100,"lenc":"LT"}]

        valres = self.basic_validation(items)

        user_hash = self.request.cookies.get('hash', '')
        user = models.user().get_by_id(user_hash)

        recd = 0
        if valres['code'] == 1:
            recd = valres['code']
            remsg = valres['msg']
        else:

            equip = []
            runway1 = models.runway()
            runway1.number = 1
            runway1.distance = 2000
            runway1.degree = 0
            runway1.root_pointX = 0
            runway1.root_pointY = 0
            runway1.initialize()
            equip.append(runway1)

            runway2 = models.runway()
            runway2.number = 2
            runway2.distance = 3000
            runway2.degree = 0
            runway2.root_pointX = 0
            runway2.root_pointY = 0
            runway2.initialize()
            equip.append(runway2)

            arg = {'portname': self.request.get("portname"),
                   'portcode': self.request.get("portcode"),
                   'location': self.request.get("location"),
                   'runway'  : equip,
                   'origin_key':user.key,
                   'maxpoint'  :user.port_point}

            if self.request.get("mode") == "u":
                oldpoint = 0
                portid = int(self.request.get("portid"))
                target_port = models.airport().get_by_id(portid)
                oldpoint = target_port.portPoint

                remsg = "空港情報を更新しました"
                rescd = target_port.update(arg)
                portpoint = target_port.portPoint
                respoint = portpoint - oldpoint

            else:
                portid = int(self.request.get("portcode"))
                remsg = "空港情報を登録しました"
                rescd = target_port.create(arg)
                respoint = target_port.portPoint

            if rescd['code'] == 0:
                user.port_point -= respoint
                user.put()
                target_port.put()

            else:
                recd  = rescd['code']
                remsg = user.port_point

        res = self.setval(user)
        res['rescd'] = recd
        res['msg'] = remsg
        self.display(res)
        return
Exemplo n.º 3
0
def airport(iata):
    return jsonify(models.airport(iata))