DRF serializer.is_valid()からエラー情報を取り出す
sampleView.py
hoge_serializer.is_valid() error_datas = hoge_serializer.errors # rest_framework.utils.serializer_helpers.ReturnDict型 error_list = [] for k,v in error_datas.items(): # key:エラーになった項目名、value:ErrorDetailのリスト(その項目に関するエラーがリストで格納されている) # ErrorDetail.codeでエラーコードが取得できる error_list.append({'key': k, 'value': v, 'code': v[0].code})
エラーコードを判定してメッセージを置き換えるなどしたい
error_list = [] for key,details in error_datas.items(): # エラーコードを変換 for d in details: if d.code in required_check_codes : error_list.append({'error_id': 'XX, 'item': key}) elif d.code in invalid_check_codes : error_list.append({'error_id': 'YY', 'item': key}) else: error_list.append({'error_id': '147','d': d}) return error_list
こんな感じになった。
herokuのデプロイでエラー
上記チュートリアルの、herokuへのpush(デプロイ)で
remote: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-faareu3_/psycopg2/ remote: ! Push rejected, failed to compile Python app. remote: remote: ! Push failed
というエラーが出て、pushに失敗する。
https://ykonishi.tokyo/cannot_push_heroku/
を参考にして、psycopg2を更新&requirements.txtに反映したところ、通るようになった。
java 変数の操作メモ
public class xx {
String A
String B = ほげ + A
public void aaa {
A = ほげ
system.out.println(B); // ほげほげにならない
}
}
メモ
MKMapViewの directionの取り方と、回転
let direction = self.mapView!.camera.heading
let angle : Double = (-1 * direction * Double.pi) / 180
self.targetView!.transform = CGAffineTransform(rotationAngle: CGFloat(angle))
画像の回転を制御したい
こう書いてしまうと
self.targetView!.transform = self.targetView!.transform.rotated(by: gesture.rotation)
グリングリン回りすぎる。。
↓
if(gesture.state == .began || gesture.state == .changed) {
let roundedRotation = round(gesture.rotation*10)/10
if(roundedRotation != beforeRotation) { // 回転量を調整する
self.gisView!.transform = self.gisView!.transform.rotated(by: roundedRotation)
}
beforeRotation = roundedRotation
}
これで無理やり調整。
let direction = self.mapView!.camera.heading
if(gesture.state == .began || gesture.state == .changed) {
// 回転量を調整する
let roundedRotation = round(gesture.rotation*10)/10
if(roundedRotation != beforeRotation) {
self.gisView!.transform = self.gisView!.transform.rotated(by: roundedRotation)
self.mapView!.camera.heading = direction + CLLocationDirection (gesture.rotation*100) * (-1)
}
beforeRotation = roundedRotation
}
地図も一緒に回転するようにした!