Update app.py
Browse files
app.py
CHANGED
@@ -118,6 +118,14 @@ def login():
|
|
118 |
return render_template("login.html", error=f"Error: {str(e)}")
|
119 |
|
120 |
return render_template("login.html")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
@app.route('/reward_status')
|
122 |
def reward_status():
|
123 |
# Get the user email from session (assuming the session is already set during checkout)
|
@@ -144,60 +152,53 @@ def reward_status():
|
|
144 |
|
145 |
# Define point ranges for each tier
|
146 |
tiers = {
|
147 |
-
"Bronze": 100,
|
148 |
-
"Silver": 200,
|
149 |
-
"Gold": 300,
|
150 |
"Platinum": 500
|
151 |
}
|
152 |
|
153 |
-
#
|
154 |
-
current_tier = ""
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
current_tier = tier
|
164 |
-
points_needed_for_next_tier = 0
|
165 |
-
|
166 |
-
# Progress bar logic (percentage for current tier progress)
|
167 |
-
if current_tier != "Platinum":
|
168 |
-
next_tier_threshold = tiers[current_tier] if current_tier else 0
|
169 |
-
max_points_for_tier = tiers.get(current_tier, 500)
|
170 |
-
|
171 |
-
# Prevent division by zero if the user is at the maximum points for the current tier
|
172 |
-
if max_points_for_tier > next_tier_threshold:
|
173 |
-
progress_percentage = (user_points - next_tier_threshold) / (max_points_for_tier - next_tier_threshold) * 100
|
174 |
-
else:
|
175 |
-
progress_percentage = 100 # If the user has already maxed out the tier
|
176 |
else:
|
177 |
-
|
178 |
-
#
|
179 |
-
user_points = round(user_points)
|
180 |
-
points_needed_for_next_tier = round(points_needed_for_next_tier)
|
181 |
|
182 |
-
# Calculate
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
186 |
|
187 |
-
#
|
188 |
-
|
189 |
-
|
190 |
|
|
|
191 |
return render_template(
|
192 |
'reward_status.html',
|
193 |
user_points=user_points,
|
194 |
current_tier=current_tier,
|
195 |
-
points_needed_for_next_tier=points_needed_for_next_tier,
|
196 |
progress_percentage=progress_percentage,
|
|
|
|
|
|
|
197 |
next_tier=next_tier,
|
198 |
-
tiers=tiers
|
199 |
)
|
200 |
|
|
|
|
|
|
|
|
|
201 |
@app.route("/logout")
|
202 |
def logout():
|
203 |
# Retrieve table number before clearing session
|
|
|
118 |
return render_template("login.html", error=f"Error: {str(e)}")
|
119 |
|
120 |
return render_template("login.html")
|
121 |
+
from flask import Flask, render_template, session
|
122 |
+
from simple_salesforce import Salesforce
|
123 |
+
|
124 |
+
app = Flask(__name__)
|
125 |
+
|
126 |
+
# Set up the Salesforce connection
|
127 |
+
sf = Salesforce(username='your_salesforce_username', password='your_salesforce_password', security_token='your_salesforce_security_token')
|
128 |
+
|
129 |
@app.route('/reward_status')
|
130 |
def reward_status():
|
131 |
# Get the user email from session (assuming the session is already set during checkout)
|
|
|
152 |
|
153 |
# Define point ranges for each tier
|
154 |
tiers = {
|
155 |
+
"Bronze": 100, # Example: 0 to 100 for Bronze
|
156 |
+
"Silver": 200, # Example: 100 to 200 for Silver
|
157 |
+
"Gold": 300, # Example: 200 to 300 for Gold
|
158 |
"Platinum": 500
|
159 |
}
|
160 |
|
161 |
+
# Logic for calculating the next tier's range and current progress
|
162 |
+
current_tier = "Silver" # Example, dynamically determine this
|
163 |
+
|
164 |
+
# Calculate the range for the current tier
|
165 |
+
if current_tier == "Silver":
|
166 |
+
start_point = 100 # Silver starts at 100
|
167 |
+
end_point = 200 # Silver ends at 200
|
168 |
+
elif current_tier == "Gold":
|
169 |
+
start_point = 200 # Gold starts at 200
|
170 |
+
end_point = 300 # Gold ends at 300
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
else:
|
172 |
+
start_point = 0 # Default start point for other tiers
|
173 |
+
end_point = 100 # Default end point for other tiers
|
|
|
|
|
174 |
|
175 |
+
# Calculate progress as a percentage
|
176 |
+
if user_points >= start_point:
|
177 |
+
progress_percentage = ((user_points - start_point) / (end_point - start_point)) * 100
|
178 |
+
else:
|
179 |
+
progress_percentage = 0
|
180 |
|
181 |
+
# Calculate points to next tier
|
182 |
+
points_needed_for_next_tier = end_point - user_points
|
183 |
+
next_tier = "Gold" # Next tier name (you can dynamically calculate this)
|
184 |
|
185 |
+
# Pass these values to your template
|
186 |
return render_template(
|
187 |
'reward_status.html',
|
188 |
user_points=user_points,
|
189 |
current_tier=current_tier,
|
|
|
190 |
progress_percentage=progress_percentage,
|
191 |
+
points_needed_for_next_tier=points_needed_for_next_tier,
|
192 |
+
start_point=start_point,
|
193 |
+
end_point=end_point,
|
194 |
next_tier=next_tier,
|
195 |
+
tiers=tiers
|
196 |
)
|
197 |
|
198 |
+
if __name__ == '__main__':
|
199 |
+
app.run(debug=True)
|
200 |
+
|
201 |
+
|
202 |
@app.route("/logout")
|
203 |
def logout():
|
204 |
# Retrieve table number before clearing session
|