Parcourir la source

검색 추가

2DU il y a 9 ans
Parent
commit
6a2d4131f4
2 fichiers modifiés avec 25 ajouts et 2 suppressions
  1. 20 1
      app.py
  2. 5 1
      templates/index.html

+ 20 - 1
app.py

@@ -789,7 +789,26 @@ def gethistory(name = None, number = None):
 @app.route('/search', methods=['POST', 'GET'])
 def search():
     if(request.method == 'POST'):
-        return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '" />'
+        curs.execute("select * from data where title = '" + pymysql.escape_string(request.form["search"]) + "'")
+        rows = curs.fetchall()
+        if(rows):
+            return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '" />'
+        else:
+            curs.execute("select * from data where title like '%" + pymysql.escape_string(request.form["search"]) + "%'")
+            rows = curs.fetchall()
+            div = ''
+            if(rows):
+                i = 0
+                div = div + '<li>문서가 없습니다. <a href="/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '">바로가기</a></li><br>'
+                while True:
+                    try:
+                        div = div + '<li><a href="/w/' + parse.quote(rows[i]['title']).replace('/','%2F') + '">' + rows[i]['title'] + '</a></li>'
+                    except:
+                        break
+                    i = i + 1
+            else:
+                div = div + '<li>문서가 없습니다. <a href="/w/' + parse.quote(request.form["search"]).replace('/','%2F') + '">바로가기</a></li>'
+            return render_template('index.html', logo = data['name'], data = div, title = '검색')
     else:
         return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']).replace('/','%2F') + '" />'
 

+ 5 - 1
templates/index.html

@@ -24,7 +24,7 @@
 				<form method="POST" action="/search" id="search">
 					<div class="input-group">
 						<input class="form-control" name="search" type="text">
-						<span class="input-group-button"><button class="btn"><i class="fa fa-long-arrow-left" aria-hidden="true"></i></button></span>
+						<span class="input-group-button"><button class="btn"><i class="fa fa-search" aria-hidden="true"></i></button></span>
 					</div>
 				</form>
 			</div>
@@ -323,6 +323,7 @@
                 <li>관리자 기능 접근성</li>
                 <li>사용자 문서 생성</li>
                 <li>파일 문서 생성</li>
+                <li>검색 기능 수정 (완료)</li>
 				<h2>계속</h2>
 				<li>버그 수정</li>
 				<li>파서 제작</li>
@@ -337,6 +338,9 @@
 				<br>
 				<h2>기타</h2>
 				<li>현재 버전 1.4.0 - Beta <s>정식 버전은 10.0이라더라.</s></li>
+                <br>
+                <h2>개발 이념</h2>
+                <li>나(2DU) 쓰기 편한 엔진을 만들자</li>
 			</div>
 			{% elif tn == 15 %}
 			<h1 class="title">{{title}}</h1>