-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.py
92 lines (76 loc) · 2.87 KB
/
add.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import json
from typing import Tuple
from db import BirdRepository, COLORS
from base import BaseScreen
from hashmap import HashMap
def save_bird(hashMap: HashMap) -> Tuple[HashMap, bool]:
"""Function for saving bird to the database."""
if not hashMap.containsKey("name"):
hashMap.put("toast", "Name is unfilled")
return hashMap, False
else:
name = hashMap.get("name")
if len(name) == 0:
hashMap.put("toast", "Name is unfilled")
return hashMap, False
if not hashMap.containsKey("description"):
hashMap.put("toast", "Description is unfilled")
return hashMap, False
else:
description = hashMap.get("description")
if len(name) == 0:
hashMap.put("toast", "Description is unfilled")
return hashMap, False
if not hashMap.containsKey("color"):
hashMap.put("toast", "Color is unfilled")
return hashMap, False
else:
color = hashMap.get("color")
if len(color) == 0:
hashMap.put("toast", "Color is unfilled")
return hashMap, False
if not hashMap.containsKey("photo_path"):
hashMap.put("toast", "Picture is required")
return hashMap, False
else:
photo_path = hashMap.get("photo_path")
if len(photo_path) == 0:
hashMap.put("toast", "Picture is required")
return hashMap, False
bird = BirdRepository.create(
name=name,
feather_color=color,
description=description,
picture=photo_path
)
hashMap.put("toast", "Bird saved!")
return hashMap, True
class Add(BaseScreen):
"""Adding bird screen."""
@classmethod
def on_start(cls, hashMap: HashMap, _files=None, _data=None) -> HashMap:
hashMap.put("mm_local", "")
hashMap.put("mm_compression", "70")
hashMap.put("mm_size", "65")
hashMap.put("fill_name", json.dumps({"hint": "Bird`s name"}))
hashMap.put("colors", ";".join(COLORS))
return hashMap
@classmethod
def on_input(cls, hashMap: HashMap, _files=None, _data=None) -> HashMap:
listener = hashMap.get("listener")
if listener == "btn_save":
hashMap, is_success = save_bird(hashMap)
if is_success:
hashMap.put("ShowScreen", "Menu")
elif listener == 'ON_BACK_PRESSED':
hashMap.put("ShowScreen", "Menu")
elif listener == 'menu_del':
hashMap.put("ShowScreen", "Menu")
hashMap.put("toast", "Deleted...")
elif listener == "photo":
hashMap.put("description", hashMap.get("description"))
hashMap.put("toast", str(hashMap.get("photo_path")))
elif listener == "gallery_change":
hashMap.put("description", hashMap.get("description"))
hashMap.put("toast", str(hashMap.get("photo_path")))
return hashMap