コード例 #1
0
 def test_save(self):
     lm = member.build()
     lm.attr["member_id"] = 2
     lm.attr["name"] = "鈴木 たろう"
     lm.attr["gender"] = "男"
     lm.attr["position"] = "アルバイト"
     lm.attr["detail"] = None
     lm.attr["money"] += 5000
     lm_id = lm.save()
     #import pdb; pdb.set_trace()
     self.assertTrue(type(lm_id) is int)
     self.assertTrue(lm.attr["member_id"] is not None)
     self.assertTrue(lm_id == lm.attr["member_id"])
     self.assertTrue(lm_id == 2)
コード例 #2
0
    def post(self):

        # POSTされたパラメータを取得
        p_name = self.get_argument("form-name", None)
        p_birthday = self.get_argument("form-birthday", None)
        p_gender = self.get_argument("form-gender", None)
        p_position = self.get_argument("form-position", None)
        p_detail = self.get_argument("form-detail", None)
        p_money = self.get_argument("form-money", None)

        # 従業員管理データの組み立て
        lm = member.build()

        # パラメータエラーチェック
        errors = []
        if p_birthday is None:
            errors.append("生年月日は必須です。")
        else:
            # 文字列をdatetime.dateオブジェクトへをキャスト
            lm.attr["birthday"] = datetime.datetime.strptime(p_birthday, '%Y-%m-%d').date()
            # 年月計算
            lm.attr["ym"] = lm.attr["birthday"].year * 100 + lm.attr["birthday"].month
        
        if p_name is None: errors.append("名前は必須です。")
        lm.attr["name"] = p_name
        lm.attr["gender"] = p_gender
        lm.attr["position"] = p_position
        lm.attr["detail"] = p_detail
        if p_money is None: p_money = 0
        lm.attr["money"] = Decimal(p_money)
        

        if len(errors) > 0: # エラーは新規登録画面に渡す
            self.render("member_form.html", mode="new", member=lm, messages=[], errors=[])
            return
        
        # 登録
        # print(vars(lm))
        lm_id = lm.save()
        if lm_id == False:
            self.render("member_form.html", mode="new", member=lm, messages=[], errors=["登録時に致命的なエラーが発生しました。"])
        else:
            # 登録画面へリダイレクト(登録完了の旨を添えて)
            self.redirect("/members?message=%s" % tornado.escape.url_escape("新規登録完了しました。(ID:%s)" % lm_id))
コード例 #3
0
    def get(self):
        # 他の画面からのメッセージを取得
        _message = self.get_argument("message", None)
        messages = []
        if _message is not None: messages.append(_message)

        lm = member.build()
        results = member.order_by_member_id(lm.attr["member_id"])

        _name = self.get_argument("name", None)
        _position = self.get_argument("position", None)
        _gender = self.get_argument("gender", None)

        if _name != None:
            results = list(filter(lambda item: _name.lower() in item.attr["name"].lower(), results))
        if _position != None:
            results = list(filter(lambda item: _position.lower() in item.attr["position"].lower(), results))
        if _gender != None:
            results = list(filter(lambda item: _gender.lower() in item.attr["gender"].lower(), results))

        
        self.render("members.html", members=results, messages=messages, errors=[], name=_name, position=_position, gender=_gender)
コード例 #4
0
 def test_build(self):
     b_lm = member.build()
     self.assertTrue(type(b_lm) is member)
コード例 #5
0
 def get(self):
     lm = member.build()
     self.render("member_form.html", mode="new", member=lm, messages=[], errors=[])