Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +130 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import airtable
|
3 |
+
import os
|
4 |
+
|
5 |
+
menu = {
|
6 |
+
'Nourriture': {
|
7 |
+
'Pizza': 10.00,
|
8 |
+
'Burger': 8.00,
|
9 |
+
'Sandwich': 6.00,
|
10 |
+
'Salade': 7.00,
|
11 |
+
},
|
12 |
+
'Boisson': {
|
13 |
+
'Soda': 2.00,
|
14 |
+
'Jus': 3.00,
|
15 |
+
'Café': 4.00,
|
16 |
+
'Thé': 3.50,
|
17 |
+
},
|
18 |
+
'Mystère': {
|
19 |
+
'Lot mystère A': 15.00,
|
20 |
+
'Lot mystère B': 20.00,
|
21 |
+
},
|
22 |
+
}
|
23 |
+
|
24 |
+
def add_to_airtable(name, num_person, order):
|
25 |
+
base_key = os.environ.get('AIRTABLE_BASE_KEY')
|
26 |
+
api_key = os.environ.get('AIRTABLE_API_KEY')
|
27 |
+
base = airtable.Airtable(base_key, 'Orders', api_key)
|
28 |
+
|
29 |
+
items = []
|
30 |
+
total = 0
|
31 |
+
|
32 |
+
for category, items_dict in order.items():
|
33 |
+
for item, qty in items_dict.items():
|
34 |
+
if qty > 0:
|
35 |
+
item_str = f'{qty} x {item} ({menu[category][item] * qty} €)'
|
36 |
+
items.append(item_str)
|
37 |
+
total += menu[category][item] * qty
|
38 |
+
|
39 |
+
record = {
|
40 |
+
'Nom': name,
|
41 |
+
'Nombre de Personne': num_person,
|
42 |
+
'Items': ', '.join(items),
|
43 |
+
'Total': total
|
44 |
+
}
|
45 |
+
|
46 |
+
base.insert(record)
|
47 |
+
|
48 |
+
def restaurant_ordering_system():
|
49 |
+
st.set_page_config(page_title="📎 Soirée Collecte de Fond")
|
50 |
+
st.title('📎 Soirée Collecte de Fond')
|
51 |
+
st.markdown("---")
|
52 |
+
|
53 |
+
if 'page' not in st.session_state:
|
54 |
+
st.session_state.page = 0
|
55 |
+
|
56 |
+
if 'order' not in st.session_state:
|
57 |
+
st.session_state.order = {'Nourriture': {}, 'Boisson': {}, 'Mystère': {}}
|
58 |
+
|
59 |
+
if 'name' not in st.session_state:
|
60 |
+
st.session_state.name = None
|
61 |
+
|
62 |
+
if 'num_person' not in st.session_state:
|
63 |
+
st.session_state.num_person = None
|
64 |
+
|
65 |
+
if st.session_state.page == 0:
|
66 |
+
st.write('# 📍 **Information:**')
|
67 |
+
st.session_state.name = st.text_input('✏️ Nom')
|
68 |
+
st.session_state.num_person = st.number_input('✏️ Nombre de personnes', min_value=1, max_value=10, value=1)
|
69 |
+
|
70 |
+
disabled = not st.session_state.name or st.session_state.num_person < 1
|
71 |
+
|
72 |
+
if st.button('Suivant ➡️', key='next1', disabled=disabled):
|
73 |
+
st.session_state.page += 1
|
74 |
+
st.rerun()
|
75 |
+
|
76 |
+
elif st.session_state.page == 1:
|
77 |
+
st.write('# 🏷️ **Menu:**')
|
78 |
+
|
79 |
+
col1, col2, col3 = st.columns(3)
|
80 |
+
|
81 |
+
with col1:
|
82 |
+
st.markdown("---")
|
83 |
+
st.markdown('### 😋 Nourriture')
|
84 |
+
food_order = st.multiselect('Sélectionner les plats:', list(menu['Nourriture'].keys()), key='food_select')
|
85 |
+
st.session_state.order['Nourriture'] = {item: st.number_input(f'Quantité pour {item}:', min_value=1, max_value=10, value=1, key=f'food_{item}') for item in food_order}
|
86 |
+
|
87 |
+
with col2:
|
88 |
+
st.markdown("---")
|
89 |
+
st.markdown('### 🥤 Boissons')
|
90 |
+
drink_order = st.multiselect('Sélectionner les boissons:', list(menu['Boisson'].keys()), key='drink_select')
|
91 |
+
st.session_state.order['Boisson'] = {item: st.number_input(f'Quantité pour {item}:', min_value=1, max_value=10, value=1, key=f'drink_{item}') for item in drink_order}
|
92 |
+
|
93 |
+
with col3:
|
94 |
+
st.markdown("---")
|
95 |
+
st.markdown('### 👁️🗨️ Lots mystères')
|
96 |
+
mystery_order = st.multiselect('Sélectionner les lots mystères:', list(menu['Mystère'].keys()), key='mystery_select')
|
97 |
+
st.session_state.order['Mystère'] = {item: st.number_input(f'Quantité pour {item}:', min_value=1, max_value=10, value=1, key=f'mystery_{item}') for item in mystery_order}
|
98 |
+
|
99 |
+
# Désactiver le bouton si moins d'un élément est sélectionné
|
100 |
+
disabled = sum(st.session_state.order['Nourriture'].values()) < 1 and sum(st.session_state.order['Boisson'].values()) < 1 and sum(st.session_state.order['Mystère'].values()) < 1
|
101 |
+
|
102 |
+
if st.button('Suivant ➡️', key='next2', disabled=disabled):
|
103 |
+
st.session_state.page += 1
|
104 |
+
st.rerun()
|
105 |
+
if st.button('⬅️ Précédent', key='prev2'):
|
106 |
+
st.session_state.page -= 1
|
107 |
+
st.rerun()
|
108 |
+
|
109 |
+
elif st.session_state.page == 2:
|
110 |
+
total = 0.0
|
111 |
+
st.write('# 🧺 **Récapitulatif de la commande:**')
|
112 |
+
for category, items in st.session_state.order.items():
|
113 |
+
if items:
|
114 |
+
for item, qty in items.items():
|
115 |
+
if qty > 0: # Affiche seulement si la quantité est supérieure à 0
|
116 |
+
price = menu[category][item] * qty
|
117 |
+
st.write(f'- {qty} x {item}: {price} €')
|
118 |
+
total += price
|
119 |
+
st.metric('🧮 Total de la commande', f'{total} €')
|
120 |
+
|
121 |
+
if st.button('💵 Passer la commande'):
|
122 |
+
add_to_airtable(st.session_state.name, st.session_state.num_person, st.session_state.order)
|
123 |
+
st.success(f'✅ Merci {st.session_state.name} pour votre commande! Vous pouvez fermer cet onglet.')
|
124 |
+
|
125 |
+
if st.button('⬅️ Précédent', key='prev3'):
|
126 |
+
st.session_state.page -= 1
|
127 |
+
st.rerun()
|
128 |
+
|
129 |
+
if __name__ == '__main__':
|
130 |
+
restaurant_ordering_system()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
airtable-python-wrapper
|
2 |
+
streamlit
|