@app.route('/mypage')
def my_page():
if session.get('u_id'):
info = db_session.query(User).filter_by(u_id=session['u_id']).first()
question = db_session.query(QuestionContent).all()
imageInfo = db_session.query(ImageInfo).all()
limit = 5 # 한 페이지당 최대 게시물
page = int(request.args.get('page', type=int, default=1)) # 페이지 값
question_list = db_session.query(QuestionContent).filter_by(writer=session['u_id']).all()
tot_cnt = len(question_list) # 게시물 총 개수
# list를 각 페이지에 맞게 slice 시킴
if page == 1:
question_list = question_list[-((page - 1) * limit + limit):]
else:
question_list = question_list[-((page - 1) * limit + limit):-((page - 1) * limit)]
last_page_num = math.ceil(tot_cnt / limit) # 마지막 페이지 수, 반드시 올림 해야 함.
block_size = 5 # 페이지 블럭 5개씩 표기
block_num = int((page - 1) / block_size) # 현재 블럭의 위치 (첫번째 블럭이라면, block_num=0)
# 현재 블럭의 맨 처음 페이지 넘버 (첫번째 블럭이라면 block_start = 1, 두번째 블럭이라면 block_start = 6)
block_start = (block_size * block_num) + 1
# 현재 블럭의 맨 끝 페이지 넘버 (첫 번째 블럭이라면, block_end = 5)
block_end = block_start + (block_size - 1)
return render_template('/user_templates/mypage.html', now_uname=info.u_name, now_uphone=info.u_phone,
now_uid=info.u_id, now_upw=info.u_pw, writer=info.u_id, question=question,
question_list=question_list, limit=limit, page=page, tot_cnt=tot_cnt,
block_size=block_size,
block_num=block_num, block_start=block_start, block_end=block_end,
last_page_num=last_page_num, imageinfo=imageInfo)
else:
flash('로그인 후 이용가능합니다.')
return redirect('/login')
@app.route('/q&a', methods=['GET', 'POST'])
def question_notice():
limit = 5 # 한 페이지당 최대 게시물
page = int(request.args.get('page', type=int, default=1)) # 페이지 값
question_list = db_session.query(QuestionContent).all()
tot_cnt = len(question_list) # 게시물 총 개수
# list를 각 페이지에 맞게 slice 시킴
if page == 1:
question_list = question_list[-((page - 1) * limit + limit):]
else:
question_list = question_list[-((page - 1) * limit + limit):-((page - 1) * limit)]
last_page_num = math.ceil(tot_cnt/limit) # 마지막 페이지 수, 반드시 올림 해야 함.
block_size = 5 # 페이지 블럭 5개씩 표기
block_num = int((page-1)/block_size) # 현재 블럭의 위치 (첫번째 블럭이라면, block_num=0)
# 현재 블럭의 맨 처음 페이지 넘버 (첫번째 블럭이라면 block_start = 1, 두번째 블럭이라면 block_start = 6)
block_start = (block_size * block_num)+1
# 현재 블럭의 맨 끝 페이지 넘버 (첫 번째 블럭이라면, block_end = 5)
block_end = block_start + (block_size - 1)
if not session.get('u_id'):
return render_template('/user_templates/q&a.html', question_list=question_list, limit=limit, page=page,
tot_cnt=tot_cnt,
block_size=block_size, block_num=block_num, block_start=block_start, block_end=block_end,
last_page_num=last_page_num)
else:
return render_template('/user_templates/q&a.html', question_list=question_list, limit=limit, page=page, tot_cnt=tot_cnt,
block_size=block_size, block_num=block_num, block_start=block_start, block_end=block_end,
last_page_num=last_page_num, now_user=session['u_id'])
from sqlalchemy import Column, Integer, Boolean, String, Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
Base = declarative_base()
class User(Base): # 사용자 정보
__tablename__ = 'user'
id = Column(Integer, primary_key=True) # 유저 번호
u_name = Column(String(50), nullable=False) # 유저 이름
u_phone = Column(String(50), nullable=False) # 유저 핸드폰 번호
u_id = Column(String(100), nullable=False) # 유저 id
u_pw = Column(String(100), nullable=False) # 유저 pw
@property
def serialize(self):
return {
'id': self.id,
'u_name': self.u_nameame,
'u_phone': self.u_phone,
'u_id': self.u_id,
'u_pw': self.u_pw,
}
class QuestionContent(Base): # 게시글 정보
__tablename__ = 'question'
id = Column(Integer, primary_key=True) # 질문 번호
title = Column(Text, nullable=False) # 질문 제목
content = Column(Text, nullable=False) # 질문 내용
create_date = Column(String(50), nullable=False) # 질문 등록날짜
is_secret = Column(Boolean, nullable=False) # 비밀글 설정 여부
category = Column(String(50), nullable=False) # 카테고리 번호
writer = Column(String(100), nullable=False) # 작성자 아이디
@property
def serialize(self):
return {
'id': self.id,
'title': self.title,
'content': self.content,
'create_date': self.create_date,
'is_secret': self.is_secret,
'writer' : self.writer,
}
class Comment(Base): # 댓글 정보
__tablename__ = 'comment_info'
id = Column(Integer, primary_key=True) # 댓글 번호
comment_content = Column(Text, nullable=False) # 댓글 내용
commenter = Column(String(100), nullable=False) # 작성자 아이디
question_id = Column(Integer, nullable=False) # 질문 번호
@property
def serialize(self):
return {
'id': self.id,
'content': self.content,
'writer': self.writer,
'question_id': self.question_id,
}
class ImageInfo(Base): # 모자이크 처리한 image file 정보
__tablename__ = 'image_info'
id = Column(Integer, primary_key=True) # 이미지 번호
url = Column(Text, nullable=False) # 이미지 링크
user = Column(String(100), nullable=False) # 사용자 id
date = Column(String(50), nullable=False) # 등록 날짜
name = Column(Text, nullable=False) # image 이름
@property
def serialize(self):
return {
'id': self.id,
'url': self.url,
'user': self.user,
'date': self.date,
'name': self.name,
}
engine = create_engine('mysql+pymysql://root:root@localhost/mosaic')
Base.metadata.create_all(engine)