Beispiel #1
0
    def post(self):
        code = self.request.get("comp_abb")+self.request.get("code")
        items =[{"item":self.request.get("dist"),"type":"時間","kind":"空路", "len":3,"lenc":"LT"},
                {"item":code,"type":"路線コード","kind":"空路","len":8,"lenc":"LT"}]

        valres = self.basic_validation(items)
        valres2 = self.validate()

        if valres['code'] * valres2['code'] == 1:
            recd = valres['code']
            remsg = valres['msg']

        else:
            str_airline = models.airline.get_by_id(self.request.get("airline")).company_name
            code = self.request.get("comp_abb")+self.request.get("code")
            times = self.timeset()

            if times['code'] == 1:
                recd = times['code']
                remsg = times['msg']

            else:
                arg = {'departure':self.request.get("departure"),
                        'arrival': self.request.get("arrival"),
                        'airline': self.request.get("airline"),
                        'str_airline':str_airline,
                        'code'   : code,
                        'Distance' : self.request.get("dist"),
                        'Numbers'  : self.request.get("frec"),
                        'Plane'    : self.request.get("plane"),
                        'dept_time': times['dept_time'],
                        'arrv_time': times['arrv_time']}

                newroute = models.air_route(id = code)
                rescd = newroute.create(arg)
                recd =  rescd['code']
                remsg = rescd['msg']

                if rescd['code'] == 0:
                    newroute.put()

                    tkey = newroute.key

                    arrv_port = models.airport.query(models.airport.portname == self.request.get("arrival")).get()
                    port_list = []
                    port_list = arrv_port.ls_route_arrival
                    port_list.append(tkey)
                    arrv_port.ls_route_arrival = port_list
                    arrv_port.put()

                    dept_port = models.airport.query(models.airport.portname == self.request.get("departure")).get()
                    port_list = []
                    port_list = dept_port.ls_route_departure
                    port_list.append(tkey)
                    dept_port.ls_route_departure = port_list
                    dept_port.put()

        res = self.setval()
        res['rescd'] = recd
        res['msg']   = remsg
        self.display(res)

        return
Beispiel #2
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