model
# Dispenser QR model file
# made : 이유진@hunature.net
# date : 2021-06-28
from flask import session
import app.utils.constants as const
from app.models import connect_database
from app.utils.query import get_qr_code_no
def query_qr_by_uuid_poster(qr_uuid):
""" qr_uuid가 일치하는 company_name을 조회하여 반환합니다.
Args:
qr_uuid ([string]): 조회할 QR의 uuid 값
Returns:
[dict]: API 결과 형식의 dict 객체 = { 'resultCode': 200, 'resultMsg': 'success', 'resultData': {} }
"""
if qr_uuid == None or qr_uuid == '':
return None
database = connect_database()
connection = None
cursor = None
if database == None:
# 데이터베이스 연결 실패 오류 처리 필요
return None
try:
connection = database.raw_connection()
except:
return None
try:
cursor = connection.cursor() # get DISPENSER_V2 mariadb cursor
except:
return None
query = f"""
SELECT
M.company_name
, M.logo_file_name
FROM MEMBER AS M
WHERE 1 = 1
AND M.member_no = (
SELECT
QM.member_no
FROM QR_CODE_MEMBER AS QM
INNER JOIN QR_CODE AS Q ON Q.qr_code_no = QM.qr_code_no
AND Q.qr_uuid = %s
WHERE 1 = 1
AND QM.is_deleted = 0
ORDER BY QM.member_qr_no DESC
LIMIT 1
)
; """
try:
cursor.execute(query, (qr_uuid, ))
except:
return None
result = [dict((cursor.description[i][0], value) for i, value in enumerate(row)) \
for row in cursor.fetchall()]
if len(result) > 0:
return result[0]
else:
return None
constroller
@buyer.route('/show_qr_poster/<string:qr_uuid>', methods=['Get'])
def show_qr_poster(qr_uuid):
company_name_test = query_qr_by_uuid_poster(qr_uuid)
print(company_name_test)
# print(company_name_test.get('company_name'))
print(company_name_test.get(const.COMPANY_NAME))
return render_template('poster.html', data = {'qr_uuid' : qr_uuid, 'company_name_test' : company_name_test})
templates(html폴더)
<img id="qr_3" src="/api/v2.0/qr_image/buyer/{{ data.get('qr_uuid') }}">
반응형
'Backend' 카테고리의 다른 글
[오류][해결] attributeerror 'nonetype' object has no attribute 'get' (0) | 2021.07.07 |
---|---|
파이썬 빠른테스트 (0) | 2021.07.07 |
[flask] mvc패턴에따른 session 사용예시 example (0) | 2021.06.28 |
[해결] 경로문제 python could not be resolved (0) | 2021.06.28 |
[요류][해결중]'pip'은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는 배치파일이 아닙니다. (0) | 2021.06.21 |