Beispiel #1
0
    def put(self, id):
        district = District.get(id)
        if not district:
            abort(400)

        district_name = request.json.get('district_name')
        district.update_distrct(district_name)
        db.session.add(district)
        db.session.commit()

        return district, 201
Beispiel #2
0
    def post(self):
        district_name = request.json.get('district_name')
        if not district_fields:
            abort(400)

        district = District(district_name=district_name)
        try:
            db.session.add(district)
            db.session.commit()
            return marshal(district, district_fields), 201
        except IntegrityError, e:
            db.session.rollback()
            res = jsonify({'resCode': '31', 'resMsg': u'区域名已经存在'})
            res.status_code = 422
            return res
Beispiel #3
0
 def delete(self, id):
     district = District.get(id)
     if district:
         # if district.routes:
         #     res = jsonify({'error': 'theere is some routes index for it'})
         #     res.status_code = 422
         #     return res
         # else:
         #     db.session.delete(district)
         #     db.session.commit()
         #     return District.get_district_list()
         db.session.delete(district)
         db.session.commit()
     else:
         return jsonify({"resCode": '30', 'resMsg': 'District is not exit'})
Beispiel #4
0
 def get(self):
     current_user = g.user
     districts = District.get_district_list()
     return districts