Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import json
|
| 3 |
from flask import Flask, render_template, request, redirect, url_for, abort
|
| 4 |
from datasets import load_dataset
|
|
@@ -8,6 +9,137 @@ from werkzeug.security import generate_password_hash, check_password_hash
|
|
| 8 |
app = Flask(__name__)
|
| 9 |
auth = HTTPBasicAuth()
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Thiết lập thư mục cache cho Hugging Face
|
| 12 |
os.environ["HF_HOME"] = "/app/hf_cache"
|
| 13 |
os.environ["HF_DATASETS_CACHE"] = "/app/hf_cache/datasets"
|
|
@@ -76,19 +208,48 @@ def index():
|
|
| 76 |
# Route cho trang thư viện
|
| 77 |
@app.route('/thuvien')
|
| 78 |
def thuvien():
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# Route cho trang before/after
|
| 83 |
@app.route('/bfat', defaults={'case_id': None})
|
| 84 |
@app.route('/bfat/<int:case_id>')
|
| 85 |
def bfat(case_id):
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
if case_id is not None:
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
if not selected_case:
|
|
|
|
| 90 |
abort(404)
|
|
|
|
|
|
|
| 91 |
return render_template('bfat.html', cases=cases, selected_case=selected_case)
|
|
|
|
|
|
|
| 92 |
return render_template('bfat.html', cases=cases, selected_case=None)
|
| 93 |
|
| 94 |
# Route cho trang dịch vụ
|
|
@@ -96,10 +257,22 @@ def bfat(case_id):
|
|
| 96 |
def dichvu():
|
| 97 |
return render_template('dichvu.html')
|
| 98 |
|
| 99 |
-
# Route cho trang liên hệ
|
| 100 |
@app.route('/lienhe')
|
| 101 |
def lienhe():
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# Route cho trang blog
|
| 105 |
@app.route('/blog')
|
|
@@ -113,10 +286,39 @@ def bloglist():
|
|
| 113 |
posts = data['blog_posts']
|
| 114 |
return render_template('bloglist.html', posts=posts)
|
| 115 |
|
| 116 |
-
# Route cho trang về chúng tôi
|
| 117 |
@app.route('/vechungtoi')
|
| 118 |
def vechungtoi():
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
# Route cho trang hành trình khách hàng
|
| 122 |
@app.route('/hanhtrinhkh')
|
|
@@ -137,31 +339,49 @@ def cms():
|
|
| 137 |
def add_case():
|
| 138 |
if not check_auth():
|
| 139 |
abort(401)
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
if request.method == 'POST':
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
return redirect(url_for('cms'))
|
|
|
|
|
|
|
| 165 |
return render_template('cms.html', section='case-editor-section', case=None, cases=cases)
|
| 166 |
|
| 167 |
# Route để chỉnh sửa case study
|
|
@@ -169,30 +389,59 @@ def add_case():
|
|
| 169 |
def edit_case(id):
|
| 170 |
if not check_auth():
|
| 171 |
abort(401)
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
if not case:
|
|
|
|
| 175 |
return "Case not found", 404
|
|
|
|
|
|
|
|
|
|
| 176 |
if request.method == 'POST':
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
return redirect(url_for('cms'))
|
|
|
|
|
|
|
| 196 |
return render_template('cms.html', section='case-editor-section', case=case, cases=cases)
|
| 197 |
|
| 198 |
# Route để xóa case study
|
|
@@ -200,10 +449,111 @@ def edit_case(id):
|
|
| 200 |
def delete_case(id):
|
| 201 |
if not check_auth():
|
| 202 |
abort(401)
|
| 203 |
-
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
return redirect(url_for('cms'))
|
| 206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
# Xử lý lỗi 401
|
| 208 |
@app.errorhandler(401)
|
| 209 |
def unauthorized(e):
|
|
|
|
| 1 |
import os
|
| 2 |
+
import sqlite3
|
| 3 |
import json
|
| 4 |
from flask import Flask, render_template, request, redirect, url_for, abort
|
| 5 |
from datasets import load_dataset
|
|
|
|
| 9 |
app = Flask(__name__)
|
| 10 |
auth = HTTPBasicAuth()
|
| 11 |
|
| 12 |
+
# Hàm kết nối với SQLite
|
| 13 |
+
def get_db_connection():
|
| 14 |
+
conn = sqlite3.connect('/app/database.db')
|
| 15 |
+
conn.row_factory = sqlite3.Row # Để trả về dữ liệu dưới dạng dictionary
|
| 16 |
+
return conn
|
| 17 |
+
|
| 18 |
+
# Tạo các bảng nếu chưa tồn tại
|
| 19 |
+
def init_db():
|
| 20 |
+
conn = get_db_connection()
|
| 21 |
+
cursor = conn.cursor()
|
| 22 |
+
|
| 23 |
+
# Tạo bảng case_studies
|
| 24 |
+
cursor.execute('''
|
| 25 |
+
CREATE TABLE IF NOT EXISTS case_studies (
|
| 26 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 27 |
+
title TEXT NOT NULL,
|
| 28 |
+
treatment TEXT,
|
| 29 |
+
description TEXT,
|
| 30 |
+
before_image TEXT,
|
| 31 |
+
after_image TEXT,
|
| 32 |
+
patient_name TEXT,
|
| 33 |
+
patient_age TEXT,
|
| 34 |
+
patient_rating TEXT DEFAULT '5',
|
| 35 |
+
patient_avatar TEXT,
|
| 36 |
+
status TEXT DEFAULT 'draft',
|
| 37 |
+
date TEXT,
|
| 38 |
+
duration TEXT,
|
| 39 |
+
visits TEXT,
|
| 40 |
+
case_id TEXT,
|
| 41 |
+
seo_title TEXT,
|
| 42 |
+
seo_description TEXT,
|
| 43 |
+
seo_keywords TEXT,
|
| 44 |
+
category TEXT,
|
| 45 |
+
tag TEXT
|
| 46 |
+
)
|
| 47 |
+
''')
|
| 48 |
+
|
| 49 |
+
# Tạo bảng our_story
|
| 50 |
+
cursor.execute('''
|
| 51 |
+
CREATE TABLE IF NOT EXISTS our_story (
|
| 52 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 53 |
+
history TEXT NOT NULL
|
| 54 |
+
)
|
| 55 |
+
''')
|
| 56 |
+
|
| 57 |
+
# Tạo bảng timeline
|
| 58 |
+
cursor.execute('''
|
| 59 |
+
CREATE TABLE IF NOT EXISTS timeline (
|
| 60 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 61 |
+
year TEXT NOT NULL,
|
| 62 |
+
title TEXT NOT NULL,
|
| 63 |
+
description TEXT NOT NULL
|
| 64 |
+
)
|
| 65 |
+
''')
|
| 66 |
+
|
| 67 |
+
# Tạo bảng mission_values
|
| 68 |
+
cursor.execute('''
|
| 69 |
+
CREATE TABLE IF NOT EXISTS mission_values (
|
| 70 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 71 |
+
title TEXT NOT NULL,
|
| 72 |
+
icon TEXT,
|
| 73 |
+
description TEXT NOT NULL
|
| 74 |
+
)
|
| 75 |
+
''')
|
| 76 |
+
|
| 77 |
+
# Tạo bảng team
|
| 78 |
+
cursor.execute('''
|
| 79 |
+
CREATE TABLE IF NOT EXISTS team (
|
| 80 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 81 |
+
name TEXT NOT NULL,
|
| 82 |
+
specialty TEXT NOT NULL,
|
| 83 |
+
photo TEXT,
|
| 84 |
+
description TEXT,
|
| 85 |
+
facebook_url TEXT,
|
| 86 |
+
linkedin_url TEXT,
|
| 87 |
+
instagram_url TEXT
|
| 88 |
+
)
|
| 89 |
+
''')
|
| 90 |
+
|
| 91 |
+
# Tạo bảng technologies
|
| 92 |
+
cursor.execute('''
|
| 93 |
+
CREATE TABLE IF NOT EXISTS technologies (
|
| 94 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 95 |
+
title TEXT NOT NULL,
|
| 96 |
+
description TEXT NOT NULL,
|
| 97 |
+
icon TEXT,
|
| 98 |
+
image TEXT
|
| 99 |
+
)
|
| 100 |
+
''')
|
| 101 |
+
|
| 102 |
+
# Tạo bảng testimonials
|
| 103 |
+
cursor.execute('''
|
| 104 |
+
CREATE TABLE IF NOT EXISTS testimonials (
|
| 105 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 106 |
+
patient_name TEXT NOT NULL,
|
| 107 |
+
treatment_type TEXT NOT NULL,
|
| 108 |
+
avatar TEXT,
|
| 109 |
+
content TEXT NOT NULL,
|
| 110 |
+
rating INTEGER DEFAULT 5
|
| 111 |
+
)
|
| 112 |
+
''')
|
| 113 |
+
|
| 114 |
+
# Tạo bảng contact_info
|
| 115 |
+
cursor.execute('''
|
| 116 |
+
CREATE TABLE IF NOT EXISTS contact_info (
|
| 117 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 118 |
+
address TEXT NOT NULL,
|
| 119 |
+
phone TEXT NOT NULL,
|
| 120 |
+
email TEXT NOT NULL,
|
| 121 |
+
working_hours_mon_fri TEXT,
|
| 122 |
+
working_hours_sat TEXT,
|
| 123 |
+
working_hours_sun TEXT,
|
| 124 |
+
map_iframe TEXT
|
| 125 |
+
)
|
| 126 |
+
''')
|
| 127 |
+
|
| 128 |
+
# Tạo bảng faqs
|
| 129 |
+
cursor.execute('''
|
| 130 |
+
CREATE TABLE IF NOT EXISTS faqs (
|
| 131 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 132 |
+
question TEXT NOT NULL,
|
| 133 |
+
answer TEXT NOT NULL
|
| 134 |
+
)
|
| 135 |
+
''')
|
| 136 |
+
|
| 137 |
+
conn.commit()
|
| 138 |
+
conn.close()
|
| 139 |
+
|
| 140 |
+
# Gọi hàm init_db khi ứng dụng khởi động
|
| 141 |
+
init_db()
|
| 142 |
+
|
| 143 |
# Thiết lập thư mục cache cho Hugging Face
|
| 144 |
os.environ["HF_HOME"] = "/app/hf_cache"
|
| 145 |
os.environ["HF_DATASETS_CACHE"] = "/app/hf_cache/datasets"
|
|
|
|
| 208 |
# Route cho trang thư viện
|
| 209 |
@app.route('/thuvien')
|
| 210 |
def thuvien():
|
| 211 |
+
conn = get_db_connection()
|
| 212 |
+
cursor = conn.cursor()
|
| 213 |
+
|
| 214 |
+
# Lấy danh sách case studies
|
| 215 |
+
cursor.execute('SELECT * FROM case_studies')
|
| 216 |
+
gallery = [dict(row) for row in cursor.fetchall()]
|
| 217 |
+
|
| 218 |
+
# Lấy danh sách testimonials
|
| 219 |
+
cursor.execute('SELECT * FROM testimonials')
|
| 220 |
+
testimonials = [dict(row) for row in cursor.fetchall()]
|
| 221 |
+
|
| 222 |
+
# Lấy thông tin liên hệ
|
| 223 |
+
cursor.execute('SELECT * FROM contact_info LIMIT 1')
|
| 224 |
+
contact_info = cursor.fetchone()
|
| 225 |
+
contact_info = dict(contact_info) if contact_info else {}
|
| 226 |
+
|
| 227 |
+
conn.close()
|
| 228 |
+
return render_template('thuvien.html', gallery=gallery, testimonials=testimonials, contact_info=contact_info)
|
| 229 |
|
| 230 |
# Route cho trang before/after
|
| 231 |
@app.route('/bfat', defaults={'case_id': None})
|
| 232 |
@app.route('/bfat/<int:case_id>')
|
| 233 |
def bfat(case_id):
|
| 234 |
+
conn = get_db_connection()
|
| 235 |
+
cursor = conn.cursor()
|
| 236 |
+
|
| 237 |
+
# Lấy danh sách case studies
|
| 238 |
+
cursor.execute('SELECT * FROM case_studies')
|
| 239 |
+
cases = [dict(row) for row in cursor.fetchall()]
|
| 240 |
+
|
| 241 |
if case_id is not None:
|
| 242 |
+
# Tìm case study theo ID
|
| 243 |
+
cursor.execute('SELECT * FROM case_studies WHERE id = ?', (case_id,))
|
| 244 |
+
selected_case = cursor.fetchone()
|
| 245 |
if not selected_case:
|
| 246 |
+
conn.close()
|
| 247 |
abort(404)
|
| 248 |
+
selected_case = dict(selected_case)
|
| 249 |
+
conn.close()
|
| 250 |
return render_template('bfat.html', cases=cases, selected_case=selected_case)
|
| 251 |
+
|
| 252 |
+
conn.close()
|
| 253 |
return render_template('bfat.html', cases=cases, selected_case=None)
|
| 254 |
|
| 255 |
# Route cho trang dịch vụ
|
|
|
|
| 257 |
def dichvu():
|
| 258 |
return render_template('dichvu.html')
|
| 259 |
|
|
|
|
| 260 |
@app.route('/lienhe')
|
| 261 |
def lienhe():
|
| 262 |
+
conn = get_db_connection()
|
| 263 |
+
cursor = conn.cursor()
|
| 264 |
+
|
| 265 |
+
# Lấy thông tin liên hệ
|
| 266 |
+
cursor.execute('SELECT * FROM contact_info LIMIT 1')
|
| 267 |
+
contact_info = cursor.fetchone()
|
| 268 |
+
contact_info = dict(contact_info) if contact_info else {}
|
| 269 |
+
|
| 270 |
+
# Lấy danh sách FAQ
|
| 271 |
+
cursor.execute('SELECT * FROM faqs')
|
| 272 |
+
faqs = [dict(row) for row in cursor.fetchall()]
|
| 273 |
+
|
| 274 |
+
conn.close()
|
| 275 |
+
return render_template('lienhe.html', contact_info=contact_info, faqs=faqs)
|
| 276 |
|
| 277 |
# Route cho trang blog
|
| 278 |
@app.route('/blog')
|
|
|
|
| 286 |
posts = data['blog_posts']
|
| 287 |
return render_template('bloglist.html', posts=posts)
|
| 288 |
|
|
|
|
| 289 |
@app.route('/vechungtoi')
|
| 290 |
def vechungtoi():
|
| 291 |
+
conn = get_db_connection()
|
| 292 |
+
cursor = conn.cursor()
|
| 293 |
+
|
| 294 |
+
# Lấy dữ liệu cho "Câu chuyện của chúng tôi"
|
| 295 |
+
cursor.execute('SELECT * FROM our_story LIMIT 1')
|
| 296 |
+
our_story = cursor.fetchone()
|
| 297 |
+
our_story = dict(our_story) if our_story else {}
|
| 298 |
+
|
| 299 |
+
# Lấy dòng thời gian
|
| 300 |
+
cursor.execute('SELECT * FROM timeline ORDER BY year ASC')
|
| 301 |
+
timeline = [dict(row) for row in cursor.fetchall()]
|
| 302 |
+
|
| 303 |
+
# Lấy dữ liệu "Sứ mệnh & Giá trị"
|
| 304 |
+
cursor.execute('SELECT * FROM mission_values')
|
| 305 |
+
mission_values = [dict(row) for row in cursor.fetchall()]
|
| 306 |
+
|
| 307 |
+
# Lấy danh sách bác sĩ
|
| 308 |
+
cursor.execute('SELECT * FROM team')
|
| 309 |
+
team = [dict(row) for row in cursor.fetchall()]
|
| 310 |
+
|
| 311 |
+
# Lấy danh sách công nghệ
|
| 312 |
+
cursor.execute('SELECT * FROM technologies')
|
| 313 |
+
technologies = [dict(row) for row in cursor.fetchall()]
|
| 314 |
+
|
| 315 |
+
# Lấy thông tin liên hệ
|
| 316 |
+
cursor.execute('SELECT * FROM contact_info LIMIT 1')
|
| 317 |
+
contact_info = cursor.fetchone()
|
| 318 |
+
contact_info = dict(contact_info) if contact_info else {}
|
| 319 |
+
|
| 320 |
+
conn.close()
|
| 321 |
+
return render_template('vechungtoi.html', our_story=our_story, timeline=timeline, mission_values=mission_values, team=team, technologies=technologies, contact_info=contact_info)
|
| 322 |
|
| 323 |
# Route cho trang hành trình khách hàng
|
| 324 |
@app.route('/hanhtrinhkh')
|
|
|
|
| 339 |
def add_case():
|
| 340 |
if not check_auth():
|
| 341 |
abort(401)
|
| 342 |
+
|
| 343 |
+
conn = get_db_connection()
|
| 344 |
+
cursor = conn.cursor()
|
| 345 |
+
|
| 346 |
+
# Lấy danh sách case studies
|
| 347 |
+
cursor.execute('SELECT * FROM case_studies')
|
| 348 |
+
cases = [dict(row) for row in cursor.fetchall()]
|
| 349 |
+
|
| 350 |
if request.method == 'POST':
|
| 351 |
+
# Tạo case study mới
|
| 352 |
+
cursor.execute('''
|
| 353 |
+
INSERT INTO case_studies (
|
| 354 |
+
title, treatment, description, before_image, after_image,
|
| 355 |
+
patient_name, patient_age, patient_rating, patient_avatar,
|
| 356 |
+
status, date, duration, visits, case_id,
|
| 357 |
+
seo_title, seo_description, seo_keywords, category, tag
|
| 358 |
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
| 359 |
+
''', (
|
| 360 |
+
request.form['case-title'],
|
| 361 |
+
request.form['case-treatment'],
|
| 362 |
+
request.form['case-description'],
|
| 363 |
+
request.form.get('case-before-image', ''),
|
| 364 |
+
request.form.get('case-after-image', ''),
|
| 365 |
+
request.form.get('case-patient-name', ''),
|
| 366 |
+
request.form.get('case-patient-age', ''),
|
| 367 |
+
request.form.get('case-patient-rating', '5'),
|
| 368 |
+
request.form.get('case-patient-avatar', ''),
|
| 369 |
+
request.form.get('case-status', 'draft'),
|
| 370 |
+
request.form.get('case-date', ''),
|
| 371 |
+
request.form.get('case-duration', ''),
|
| 372 |
+
request.form.get('case-visits', ''),
|
| 373 |
+
request.form.get('case-id', ''),
|
| 374 |
+
request.form.get('case-seo-title', ''),
|
| 375 |
+
request.form.get('case-seo-description', ''),
|
| 376 |
+
request.form.get('case-seo-keywords', ''),
|
| 377 |
+
request.form.get('case-category', ''), # Thêm category
|
| 378 |
+
request.form.get('case-tag', '') # Thêm tag
|
| 379 |
+
))
|
| 380 |
+
conn.commit()
|
| 381 |
+
conn.close()
|
| 382 |
return redirect(url_for('cms'))
|
| 383 |
+
|
| 384 |
+
conn.close()
|
| 385 |
return render_template('cms.html', section='case-editor-section', case=None, cases=cases)
|
| 386 |
|
| 387 |
# Route để chỉnh sửa case study
|
|
|
|
| 389 |
def edit_case(id):
|
| 390 |
if not check_auth():
|
| 391 |
abort(401)
|
| 392 |
+
|
| 393 |
+
conn = get_db_connection()
|
| 394 |
+
cursor = conn.cursor()
|
| 395 |
+
|
| 396 |
+
# Lấy danh sách case studies
|
| 397 |
+
cursor.execute('SELECT * FROM case_studies')
|
| 398 |
+
cases = [dict(row) for row in cursor.fetchall()]
|
| 399 |
+
|
| 400 |
+
# Tìm case study theo ID
|
| 401 |
+
cursor.execute('SELECT * FROM case_studies WHERE id = ?', (id,))
|
| 402 |
+
case = cursor.fetchone()
|
| 403 |
if not case:
|
| 404 |
+
conn.close()
|
| 405 |
return "Case not found", 404
|
| 406 |
+
|
| 407 |
+
case = dict(case)
|
| 408 |
+
|
| 409 |
if request.method == 'POST':
|
| 410 |
+
# Cập nhật case study
|
| 411 |
+
cursor.execute('''
|
| 412 |
+
UPDATE case_studies
|
| 413 |
+
SET title = ?, treatment = ?, description = ?, before_image = ?, after_image = ?,
|
| 414 |
+
patient_name = ?, patient_age = ?, patient_rating = ?, patient_avatar = ?,
|
| 415 |
+
status = ?, date = ?, duration = ?, visits = ?, case_id = ?,
|
| 416 |
+
seo_title = ?, seo_description = ?, seo_keywords = ?, category = ?, tag = ?
|
| 417 |
+
WHERE id = ?
|
| 418 |
+
''', (
|
| 419 |
+
request.form['case-title'],
|
| 420 |
+
request.form['case-treatment'],
|
| 421 |
+
request.form['case-description'],
|
| 422 |
+
request.form.get('case-before-image', ''),
|
| 423 |
+
request.form.get('case-after-image', ''),
|
| 424 |
+
request.form.get('case-patient-name', ''),
|
| 425 |
+
request.form.get('case-patient-age', ''),
|
| 426 |
+
request.form.get('case-patient-rating', '5'),
|
| 427 |
+
request.form.get('case-patient-avatar', ''),
|
| 428 |
+
request.form.get('case-status', 'draft'),
|
| 429 |
+
request.form.get('case-date', ''),
|
| 430 |
+
request.form.get('case-duration', ''),
|
| 431 |
+
request.form.get('case-visits', ''),
|
| 432 |
+
request.form.get('case-id', ''),
|
| 433 |
+
request.form.get('case-seo-title', ''),
|
| 434 |
+
request.form.get('case-seo-description', ''),
|
| 435 |
+
request.form.get('case-seo-keywords', ''),
|
| 436 |
+
request.form.get('case-category', ''),
|
| 437 |
+
request.form.get('case-tag', ''),
|
| 438 |
+
id
|
| 439 |
+
))
|
| 440 |
+
conn.commit()
|
| 441 |
+
conn.close()
|
| 442 |
return redirect(url_for('cms'))
|
| 443 |
+
|
| 444 |
+
conn.close()
|
| 445 |
return render_template('cms.html', section='case-editor-section', case=case, cases=cases)
|
| 446 |
|
| 447 |
# Route để xóa case study
|
|
|
|
| 449 |
def delete_case(id):
|
| 450 |
if not check_auth():
|
| 451 |
abort(401)
|
| 452 |
+
|
| 453 |
+
conn = get_db_connection()
|
| 454 |
+
cursor = conn.cursor()
|
| 455 |
+
|
| 456 |
+
# Xóa case study
|
| 457 |
+
cursor.execute('DELETE FROM case_studies WHERE id = ?', (id,))
|
| 458 |
+
conn.commit()
|
| 459 |
+
conn.close()
|
| 460 |
+
|
| 461 |
return redirect(url_for('cms'))
|
| 462 |
|
| 463 |
+
# Route hiển thị danh sách bác sĩ trong CMS
|
| 464 |
+
@app.route('/cms/team')
|
| 465 |
+
def cms_team():
|
| 466 |
+
if not check_auth():
|
| 467 |
+
abort(401)
|
| 468 |
+
|
| 469 |
+
conn = get_db_connection()
|
| 470 |
+
cursor = conn.cursor()
|
| 471 |
+
cursor.execute('SELECT * FROM team')
|
| 472 |
+
team = [dict(row) for row in cursor.fetchall()]
|
| 473 |
+
conn.close()
|
| 474 |
+
|
| 475 |
+
return render_template('cms.html', section='team-section', team=team)
|
| 476 |
+
|
| 477 |
+
# Route thêm bác sĩ mới
|
| 478 |
+
@app.route('/cms/team/new', methods=['GET', 'POST'])
|
| 479 |
+
def add_team_member():
|
| 480 |
+
if not check_auth():
|
| 481 |
+
abort(401)
|
| 482 |
+
|
| 483 |
+
conn = get_db_connection()
|
| 484 |
+
cursor = conn.cursor()
|
| 485 |
+
|
| 486 |
+
if request.method == 'POST':
|
| 487 |
+
cursor.execute('''
|
| 488 |
+
INSERT INTO team (name, specialty, photo, description, facebook_url, linkedin_url, instagram_url)
|
| 489 |
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
| 490 |
+
''', (
|
| 491 |
+
request.form['name'],
|
| 492 |
+
request.form['specialty'],
|
| 493 |
+
request.form.get('photo', ''),
|
| 494 |
+
request.form.get('description', ''),
|
| 495 |
+
request.form.get('facebook_url', '#'),
|
| 496 |
+
request.form.get('linkedin_url', '#'),
|
| 497 |
+
request.form.get('instagram_url', '#')
|
| 498 |
+
))
|
| 499 |
+
conn.commit()
|
| 500 |
+
conn.close()
|
| 501 |
+
return redirect(url_for('cms_team'))
|
| 502 |
+
|
| 503 |
+
conn.close()
|
| 504 |
+
return render_template('cms.html', section='team-editor-section', member=None)
|
| 505 |
+
|
| 506 |
+
# Route sửa bác sĩ
|
| 507 |
+
@app.route('/cms/team/edit/<int:id>', methods=['GET', 'POST'])
|
| 508 |
+
def edit_team_member(id):
|
| 509 |
+
if not check_auth():
|
| 510 |
+
abort(401)
|
| 511 |
+
|
| 512 |
+
conn = get_db_connection()
|
| 513 |
+
cursor = conn.cursor()
|
| 514 |
+
|
| 515 |
+
cursor.execute('SELECT * FROM team WHERE id = ?', (id,))
|
| 516 |
+
member = cursor.fetchone()
|
| 517 |
+
if not member:
|
| 518 |
+
conn.close()
|
| 519 |
+
return "Team member not found", 404
|
| 520 |
+
member = dict(member)
|
| 521 |
+
|
| 522 |
+
if request.method == 'POST':
|
| 523 |
+
cursor.execute('''
|
| 524 |
+
UPDATE team
|
| 525 |
+
SET name = ?, specialty = ?, photo = ?, description = ?, facebook_url = ?, linkedin_url = ?, instagram_url = ?
|
| 526 |
+
WHERE id = ?
|
| 527 |
+
''', (
|
| 528 |
+
request.form['name'],
|
| 529 |
+
request.form['specialty'],
|
| 530 |
+
request.form.get('photo', ''),
|
| 531 |
+
request.form.get('description', ''),
|
| 532 |
+
request.form.get('facebook_url', '#'),
|
| 533 |
+
request.form.get('linkedin_url', '#'),
|
| 534 |
+
request.form.get('instagram_url', '#'),
|
| 535 |
+
id
|
| 536 |
+
))
|
| 537 |
+
conn.commit()
|
| 538 |
+
conn.close()
|
| 539 |
+
return redirect(url_for('cms_team'))
|
| 540 |
+
|
| 541 |
+
conn.close()
|
| 542 |
+
return render_template('cms.html', section='team-editor-section', member=member)
|
| 543 |
+
|
| 544 |
+
# Route xóa bác sĩ
|
| 545 |
+
@app.route('/cms/team/delete/<int:id>')
|
| 546 |
+
def delete_team_member(id):
|
| 547 |
+
if not check_auth():
|
| 548 |
+
abort(401)
|
| 549 |
+
|
| 550 |
+
conn = get_db_connection()
|
| 551 |
+
cursor = conn.cursor()
|
| 552 |
+
cursor.execute('DELETE FROM team WHERE id = ?', (id,))
|
| 553 |
+
conn.commit()
|
| 554 |
+
conn.close()
|
| 555 |
+
return redirect(url_for('cms_team'))
|
| 556 |
+
|
| 557 |
# Xử lý lỗi 401
|
| 558 |
@app.errorhandler(401)
|
| 559 |
def unauthorized(e):
|