-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrello_order_form.py
More file actions
126 lines (114 loc) · 5.27 KB
/
trello_order_form.py
File metadata and controls
126 lines (114 loc) · 5.27 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import streamlit as st
import pandas as pd
import numpy as np
from datetime import datetime
from deta import Deta
import json
import requests
import base64
order = Deta(st.secrets["DETA_PROJECT_ID"]).Base("trello_orders")
st.header("Trello Order with Deta")
if 'more' in st.session_state :
pass
else:
st.session_state['more'] = "Yes"
if 'items' in st.session_state :
pass
else:
st.session_state['items'] = []
if 'focus' in st.session_state:
pass
else:
st.session_state['focus'] = 1
if st.session_state['focus'] == 2 :
st.subheader("Your items :")
st.dataframe(st.session_state['items'])
if st.session_state['focus'] == 1:
with st.expander("Open to enter order details"):
#last_line = 0
items = st.session_state['items']
last = "No"
if st.session_state['more'] == "Yes" :
st.subheader("Your items :")
st.dataframe(items)
st.subheader("Create Line Items")
form_name = "Order Line Items {}".format(len(items))
with st.form(form_name, clear_on_submit=True):
line = {}
line['collar'] = st.selectbox("Collar", ("Round", "V-shaped"))
line['size'] = st.selectbox("Size", ("Extra Large", "Large", "Medium", "Small"))
line['quantity'] = st.number_input("Quantity", min_value=1)
line['remarks'] = st.text_input(label="Remarks")
last = st.selectbox("Last Item", ("No", "Yes"))
#last_line = len(items) + 1
enter = st.form_submit_button("Enter")
if enter :
items.append(line)
st.session_state['items'] = items
st.write("just before if check")
st.write(last)
if last == "Yes" :
st.write("just after if check")
st.session_state['more'] = "No"
st.write(st.session_state)
st.session_state['focus'] = 2
st.experimental_rerun()
if st.session_state['focus'] == 2 :
with st.expander("Open to create order card"):
items = st.session_state['items']
with st.form("Create Order Card", clear_on_submit=True):
st.subheader("Create an Order Card")
cfd = {}
res_get = requests.get('https://bpqc1s.deta.dev/get_definitions?board_id={}'.format("61120a2d004a725ed3f7f0db")) #st.write("slider", slider_val, "checkbox", checkbox_val)
cfd = res_get.json()['cfd']
collect = {}
collect['board_id'] ="61120a2d004a725ed3f7f0db"
collect['cardname'] = st.text_input('Card Name')
collect['carddescription'] = st.text_area('Card Description')
st.write("The form is dynamically created based on the custom field definitions of any Trello Board")
for df in cfd:
if df['type'] == 'text' :
collect[df['name']] = st.text_input(df['name'])
elif df['type'] == 'checkbox' :
collect[df['name']] = st.checkbox(df['name'], value=False)
elif df['type'] == 'date' :
date = st.date_input("Enter date for {}".format(df['name']))
time = st.time_input("Enter time for {}".format(df['name']))
collect[df['name']] = "{}T{}".format(date, time)
elif df['type'] == 'list' :
options = [choice['value']['text'] for choice in df['options']]
collect[df['name']] = st.selectbox(df['name'], options=options)
elif df['type'] == 'number' :
collect[df['name']] = round(st.number_input(df['name'],step=0.1), 2)
ready = st.form_submit_button("Submit")
if ready:
st.write("Creating a card....")
#st.dataframe(items)
#st.json(collect)
#st.write(st.session_state)
res_update = requests.post('https://bpqc1s.deta.dev/update', json=collect)
if res_update.status_code == 200:
st.write("Creating a order lines in Deta....")
st.session_state['card_id'] = res_update.json()['card_id']
order.put({"line_items" : items}, res_update.json()['card_id'])
st.write("Finishing cleaning up.....")
st.session_state['focus'] = 3
st.experimental_rerun()
else:
st.error(res_update.text)
if st.session_state['focus'] == 3 :
with st.expander("Open to upload samples"):
uploaded_file = st.file_uploader('Upload any file up to 200MB')
finished = st.button("Done")
attach = {}
if finished :
for key in st.session_state :
del st.session_state[key]
st.session_state['focus'] = 1
st.experimental_rerun()
else:
if uploaded_file is not None:
bytes_data = uploaded_file.getvalue()
attach['card_id'] = st.session_state['card_id']
attach['filename'] = uploaded_file.name
res_attach = requests.post('https://bpqc1s.deta.dev/attach', data=attach, files = {'upload_file': bytes_data})