2DU 8 éve
szülő
commit
703ee7d755
2 módosított fájl, 30 hozzáadás és 58 törlés
  1. 20 44
      app.py
  2. 10 14
      func.py

+ 20 - 44
app.py

@@ -2602,27 +2602,12 @@ def user_ban(name = None):
             else:
             else:
                 plus = ''
                 plus = ''
             
             
-            data = '<select name="year"> \
-                        ' + year + ' \
-                    </select> 년 \
-                    <select name="month"> \
-                        ' + month + ' \
-                    </select> 월 \
-                    <select name="day"> \
-                        ' + day + ' \
-                    </select> 일 \
-                    <br> \
-                    <br> \
-                    <select name="hour"> \
-                        ' + hour + ' \
-                    </select> 시 \
-                    <select name="minu"> \
-                        ' + minu + ' \
-                    </select> 분 까지 \
-                    <br> \
-                    <br> \
-                    <input placeholder="사유" class="form-control" name="why"> \
-                    <br>' + plus
+            data = '<select name="year">' + year + '</select> 년'
+            data += '<select name="month">' + month + '</select> 월'
+            data += '<select name="day">' + day + '</select> 일 <br><br>'
+            data += '<select name="hour">' + hour + '</select> 시'
+            data += '<select name="minu">' + minu + '</select> 분 까지<br><br>'
+            data += '<input placeholder="사유" class="form-control" name="why"><br>' + plus
 
 
         return(html_minify(template('index', 
         return(html_minify(template('index', 
             imp = [name, wiki_set(conn, 1), custom(conn), other2([' (' + now + ')', 0])],
             imp = [name, wiki_set(conn, 1), custom(conn), other2([' (' + now + ')', 0])],
@@ -2790,34 +2775,25 @@ def user_admin(name = None):
             menu = [['manager', '관리자']]
             menu = [['manager', '관리자']]
         )))
         )))
     
     
-@route('/w/<name:path>/r/<a:int>/diff/<b:int>')
-def diff_data(name = None, a = None, b = None):
-    curs.execute("select data from history where id = ? and title = ?", [str(a), name])
-    a_raw_data = curs.fetchall()
-    if(a_raw_data):
-        curs.execute("select data from history where id = ? and title = ?", [str(b), name])
-        b_raw_data = curs.fetchall()
-        if(b_raw_data):
-            a_data = html.escape(a_raw_data[0][0])            
-            b_data = html.escape(b_raw_data[0][0])
-
-            if(a_data == b_data):
+@route('/w/<name:path>/r/<first:int>/diff/<second:int>')
+def diff_data(name = None, first = None, second = None):
+    curs.execute("select data from history where id = ? and title = ?", [str(first), name])
+    first_raw_data = curs.fetchall()
+    if(first_raw_data):
+        curs.execute("select data from history where id = ? and title = ?", [str(second), name])
+        second_raw_data = curs.fetchall()
+        if(second_raw_data):
+            first_data = html.escape(first_raw_data[0][0])            
+            second_data = html.escape(second_raw_data[0][0])
+            if(first == second):
                 result = '내용이 같습니다.'
                 result = '내용이 같습니다.'
             else:            
             else:            
-                diff_data = difflib.SequenceMatcher(None, a_data, b_data)
-                result_1 = diff(diff_data, 1)
-                result_2 = diff(diff_data, 0)
-
-                if(a_data == result_1):
-                    result = '<pre>' + result_2 + '</pre>'
-                elif(b_data == result_2):
-                    result = '<pre>' + result_1 + '</pre>'
-                else:
-                    result = '<pre>' + result_1 + '<hr>' + result_2 + '</pre>'
+                diff_data = difflib.SequenceMatcher(None, first_data, second_data)
+                result = diff(diff_data)
             
             
             return(html_minify(template('index', 
             return(html_minify(template('index', 
                 imp = [name, wiki_set(conn, 1), custom(conn), other2([' (비교)', 0])],
                 imp = [name, wiki_set(conn, 1), custom(conn), other2([' (비교)', 0])],
-                data = result,
+                data = '<pre>' + result + '</pre>',
                 menu = [['history/' + url_pas(name), '역사']]
                 menu = [['history/' + url_pas(name), '역사']]
             )))
             )))
 
 

+ 10 - 14
func.py

@@ -124,22 +124,18 @@ def wiki_set(conn, num):
     else:
     else:
         return(var_data)
         return(var_data)
 
 
-def diff(seqm, num):
-    output= []
+def diff(seqm):
+    output = []
     for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
     for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
-        if(opcode == 'equal' and num == 1):
-            output.append(seqm.a[a0:a1])
-        elif(opcode == 'insert' and num == 0):
-            output.append("<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>")
-        elif(opcode == 'delete' and num == 1):
-            output.append("<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>")
+        if(opcode == 'equal'):
+            output += [seqm.a[a0:a1]]
+        elif(opcode == 'insert'):
+            output += ["<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>"]
+        elif(opcode == 'delete'):
+            output += ["<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>"]
         elif(opcode == 'replace'):
         elif(opcode == 'replace'):
-            if(num == 1):
-                output.append("<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>")
-            else:
-                output.append("<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>")
-        elif(num == 0):
-            output.append(seqm.b[b0:b1])
+            output += ["<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>"]
+            output += ["<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>"]
             
             
     return(''.join(output))
     return(''.join(output))