2DU vor 9 Jahren
Ursprung
Commit
52ec3462ac
2 geänderte Dateien mit 79 neuen und 31 gelöschten Zeilen
  1. 64 25
      app.py
  2. 15 6
      templates/index.html

+ 64 - 25
app.py

@@ -9,6 +9,7 @@ import time
 import re
 import bcrypt
 import os
+import difflib
 
 json_data = open('set.json').read()
 data = json.loads(json_data)
@@ -22,6 +23,17 @@ app.secret_key = data['key']
 
 ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
 
+def show_diff(seqm):
+    output= []
+    for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
+        if opcode == 'equal':
+            output.append(seqm.a[a0:a1])
+        elif opcode == 'insert':
+            output.append("<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>")
+        elif opcode == 'delete':
+            output.append("<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>")
+    return ''.join(output)
+
 def allowed_file(filename):
     return '.' in filename and \
            filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@@ -534,7 +546,7 @@ def recentdiscuss():
             i = i + 1
         return render_template('index.html', logo = data['name'], rows = div, tn = 12, title = '최근 토론내역')
     else:
-         return render_template('index.html', logo = data['name'], rows = '', tn = 12, title = '최근 토론내역')
+        return render_template('index.html', logo = data['name'], rows = '', tn = 12, title = '최근 토론내역')
          
 @app.route('/recentblock')
 def recentblock():
@@ -556,33 +568,36 @@ def recentblock():
             i = i + 1
         return render_template('index.html', logo = data['name'], rows = div, tn = 20, title = '최근 차단내역')
     else:
-         return render_template('index.html', logo = data['name'], rows = '', tn = 20, title = '최근 차단내역')
+        return render_template('index.html', logo = data['name'], rows = '', tn = 20, title = '최근 차단내역')
 
-@app.route('/history/<name>')
+@app.route('/history/<name>', methods=['POST', 'GET'])
 def gethistory(name = None):
-    i = 0
-    div = '<div>'
-    curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' order by id+0 desc")
-    rows = curs.fetchall()
-    if(rows):
-        while True:
-            try:
-                a = rows[i]
-            except:
-                div = div + '</div>'
-                break
-            if(rows[i]['send']):
-                send = rows[i]['send']
-                send = re.sub('<', '&lt;', send)
-                send = re.sub('>', '&gt;', send)
-                send = re.sub('&lt;a href="\/w\/(?P<in>[^"]*)"&gt;(?P<out>[^&]*)&lt;\/a&gt;', '<a href="/w/\g<in>">\g<out></a>', send)
-            else:
-                send = '<br>'
-            div = div + '<table style="width: 100%;"><tbody><tr><td style="text-align: center;width:33.33%;">r' + rows[i]['id'] + '</a> <a href="/w/' + parse.quote(rows[i]['title']) + '/r/' + rows[i]['id'] + '">(w)</a> <a href="/w/' + parse.quote(rows[i]['title']) + '/raw/' + rows[i]['id'] + '">(Raw)</a> <a href="/revert/' + parse.quote(rows[i]['title']) + '/r/' + rows[i]['id'] + '">(되돌리기)</a> (' + rows[i]['leng'] + ')</td><td style="text-align: center;width:33.33%;">' + rows[i]['ip'] + '</td><td style="text-align: center;width:33.33%;">' + rows[i]['date'] + '</td></tr><tr><td colspan="3" style="text-align: center;width:100%;">' + send + '</td></tr></tbody></table>'
-            i = i + 1
-        return render_template('index.html', logo = data['name'], rows = div, tn = 5, title = name, page = parse.quote(name))
+    if(request.method == 'POST'):
+        return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name) + '/r/' + request.form["a"] + '/diff/' + request.form["b"] + '" />'
     else:
-         return render_template('index.html', logo = data['name'], rows = '', tn = 5, title = name, page = parse.quote(name))
+        i = 0
+        div = '<div>'
+        curs.execute("select * from history where title = '" + pymysql.escape_string(name) + "' order by id+0 desc")
+        rows = curs.fetchall()
+        if(rows):
+            while True:
+                try:
+                    a = rows[i]
+                except:
+                    div = div + '</div>'
+                    break
+                if(rows[i]['send']):
+                    send = rows[i]['send']
+                    send = re.sub('<', '&lt;', send)
+                    send = re.sub('>', '&gt;', send)
+                    send = re.sub('&lt;a href="\/w\/(?P<in>[^"]*)"&gt;(?P<out>[^&]*)&lt;\/a&gt;', '<a href="/w/\g<in>">\g<out></a>', send)
+                else:
+                    send = '<br>'
+                div = div + '<table style="width: 100%;"><tbody><tr><td style="text-align: center;width:33.33%;">r' + rows[i]['id'] + '</a> <a href="/w/' + parse.quote(rows[i]['title']) + '/r/' + rows[i]['id'] + '">(w)</a> <a href="/w/' + parse.quote(rows[i]['title']) + '/raw/' + rows[i]['id'] + '">(Raw)</a> <a href="/revert/' + parse.quote(rows[i]['title']) + '/r/' + rows[i]['id'] + '">(되돌리기)</a> (' + rows[i]['leng'] + ')</td><td style="text-align: center;width:33.33%;">' + rows[i]['ip'] + '</td><td style="text-align: center;width:33.33%;">' + rows[i]['date'] + '</td></tr><tr><td colspan="3" style="text-align: center;width:100%;">' + send + '</td></tr></tbody></table>'
+                i = i + 1
+            return render_template('index.html', logo = data['name'], rows = div, tn = 5, title = name, page = parse.quote(name))
+        else:
+            return render_template('index.html', logo = data['name'], rows = '', tn = 5, title = name, page = parse.quote(name))
 
 @app.route('/search', methods=['POST', 'GET'])
 def search():
@@ -1407,6 +1422,30 @@ def aban():
         end = '권한이 맞지 않는 상태 입니다.'
     
     return render_template('index.html', title = '권한 오류', logo = data['name'], data = end)
+   
+@app.route('/w/<name>/r/<a>/diff/<b>')
+def diff(name = None, a = None, b = None):
+    curs.execute("select * from history where id = '" + pymysql.escape_string(a) + "' and title = '" + pymysql.escape_string(name) + "'")
+    rows = curs.fetchall()
+    if(rows):
+        curs.execute("select * from history where id = '" + pymysql.escape_string(b) + "' and title = '" + pymysql.escape_string(name) + "'")
+        row = curs.fetchall()
+        if(row):
+            indata = re.sub('<', '&lt;', rows[0]['data'])
+            indata = re.sub('>', '&gt;', indata)
+            indata = re.sub('"', '&quot;', indata)
+            indata = re.sub('\n', '<br>', indata)
+            enddata = re.sub('<', '&lt;', row[0]['data'])
+            enddata = re.sub('>', '&gt;', enddata)
+            enddata = re.sub('"', '&quot;', enddata)
+            enddata = re.sub('\n', '<br>', enddata)
+            sm = difflib.SequenceMatcher(None, indata, enddata)
+            c = show_diff(sm)
+            return render_template('index.html', title = 'Diff', logo = data['name'], data = c)
+        else:
+            return render_template('index.html', title = 'Diff 오류', logo = data['name'], data = '<a href="/w/' + name + '">이 리비전이나 문서가 없습니다.</a>')
+    else:
+        return render_template('index.html', title = 'Diff 오류', logo = data['name'], data = '<a href="/w/' + name + '">이 리비전이나 문서가 없습니다.</a>')
 
 @app.route('/version')
 def version():

+ 15 - 6
templates/index.html

@@ -131,6 +131,12 @@
 				</nav>
 			</div>
 			<h1 class="title">{{title}} <sub>(역사)</sub></h1>
+            <form class="usrform" method='POST' action='/history/{{page}}'>
+            <input id="form-control input-sm" type='text' id='history' name='a'>
+            <input id="form-control input-sm" type='text' id='history' name='b'>
+            <button class="btn btn-primary" type='submit'>리비전 비교</button>
+            <br>
+            <br>
 			<table style="width: 100%;">
 				<tbody>
 					<tr>
@@ -301,15 +307,18 @@
 				<li>어드민 부여 구현</li>
 				<h2>1.2 (진행중)</h2>
                 <li>미리보기 구현 (완료)</li>
-                <li>토론 목록 보강</li>
 				<li>대역 차단 구현</li>
-				<li>diff 구현</li>
+				<li>diff 구현 (완료)</li>
+                <li>파일 업로드 개선 (완료)</li>
                 <li>파일 업로드 구현 (완료)</li>
-				<li>관리자 기능의 접근성 향상</li>
-				<li>기본적인 다중 검사 기능</li>
+				<li>기본적인 다중 검사 기능 (완료)</li>
                 <h2>1.3</h2>
-                <li>파일 업로드 개선</li>
+                <li>토론 목록 보강</li>
+                <li>파일 문서 생성</li>
                 <li>설계 약간 변경</li>
+                <li>하위 문서 지원</li>
+                <li>관리자 기능의 접근성 향상</li>
+                <li>사용자 문서 생성</li>
 				<h2>계속</h2>
 				<li>버그 수정</li>
 				<li>파서 제작</li>
@@ -321,7 +330,7 @@
 				<li>일부 파일 <a href="https://twitter.com/Basix1120">Basix</a></li>
 				<br>
 				<h2>기타</h2>
-				<li>현재 버전 1.2.6 - Beta</li>
+				<li>현재 버전 1.2.9 - Beta</li>
 			</div>
 			{% elif tn == 15 %}
 			<h1 class="title">{{title}}</h1>