Ver código fonte

일부 코드 최적화

Surplus_Up (2DU) 6 anos atrás
pai
commit
fc18c2da62
5 arquivos alterados com 28 adições e 57 exclusões
  1. 2 2
      app.py
  2. 3 27
      route/list_user.py
  3. 7 15
      route/recent_block.py
  4. 15 12
      route/tool/func.py
  5. 1 1
      version.json

+ 2 - 2
app.py

@@ -404,8 +404,8 @@ def recent_discuss():
 
 @app.route('/block_log')
 @app.route('/<regex("block_user|block_admin"):tool>/<name>')
-def list_block(name = None, tool = None):
-    return list_block_2(conn, name, tool)
+def recent_block(name = None, tool = None):
+    return recent_block_2(conn, name, tool)
 
 @app.route('/search', methods=['POST'])
 def search():

+ 3 - 27
route/list_user.py

@@ -4,40 +4,16 @@ def list_user_2(conn):
     curs = conn.cursor()
 
     num = int(number_check(flask.request.args.get('num', '1')))
-    if num * 50 > 0:
-        sql_num = num * 50 - 50
-    else:
-        sql_num = 0
+    sql_num = (num * 50 - 50) if num * 50 > 0 else 0
 
     list_data = '<ul>'
 
-    admin_one = admin_check(1)
-
     curs.execute(db_change("select id, date from user order by date desc limit ?, 50"), [sql_num])
     user_list = curs.fetchall()
     for data in user_list:
-        if admin_one == 1:
-            curs.execute(db_change("select block from rb where block = ? and ongoing = '1'"), [data[0]])
-            if curs.fetchall():
-                ban_button = ' <a href="/ban/' + url_pas(data[0]) + '">(' + load_lang('ban_release') + ')</a>'
-            else:
-                ban_button = ' <a href="/ban/' + url_pas(data[0]) + '">(' + load_lang('ban') + ')</a>'
-        else:
-            ban_button = ''
-
-        list_data += '<li>' + ip_pas(data[0]) + ban_button
-
-        if data[1] != '':
-            list_data += ' (' + data[1] + ')'
-
-        list_data += '</li>'
-
-    if num == 1:
-        list_data += '''
-            </ul>
-        '''
+        list_data += '<li>' + ip_pas(data[0]) + (' (' + data[1] + ')' if data[1] != '' else '') + '</li>'
 
-    list_data += next_fix('/user_log?num=', num, user_list)
+    list_data += '</ul>' + next_fix('/user_log?num=', num, user_list)
 
     return easy_minify(flask.render_template(skin_check(),
         imp = [load_lang('member_list'), wiki_set(), custom(), other2([0, 0])],

+ 7 - 15
route/list_block.py → route/recent_block.py

@@ -1,13 +1,10 @@
 from .tool.func import *
 
-def list_block_2(conn, name, tool):
+def recent_block_2(conn, name, tool):
     curs = conn.cursor()
 
     num = int(number_check(flask.request.args.get('num', '1')))
-    if num * 50 > 0:
-        sql_num = num * 50 - 50
-    else:
-        sql_num = 0
+    sql_num = (num * 50 - 50) if num * 50 > 0 else 0
 
     div = '''
         <table id="main_table_set">
@@ -64,17 +61,16 @@ def list_block_2(conn, name, tool):
     if data_list == '':
         data_list = curs.fetchall()
 
+    all_ip = ip_pas([i[1] for i in data_list] + [i[2] for i in data_list])
     for data in data_list:
-        why = html.escape(data[0])
-        if why == '':
-            why = '<br>'
+        why = '<br>' if data[0] == '' else html.escape(data[0])
 
         if data[5] == 'O':
             ip = data[1] + ' (' + load_lang('range') + ')'
         elif data[5] == 'regex':
             ip = data[1] + ' (' + load_lang('regex') + ')'
         else:
-            ip = ip_pas(data[1])
+            ip = all_ip[data[1]]
 
         if data[3] == '':
             end = load_lang('limitless')
@@ -88,7 +84,7 @@ def list_block_2(conn, name, tool):
         elif re.search(r'^tool:', data[2]):
             admin = data[2]
         else:
-            admin = ip_pas(data[2])
+            admin = all_ip[data[2]]
 
         start = load_lang('start') + ' : ' + (data[4] if data[4] != '' else '0')
         div += '''
@@ -107,11 +103,7 @@ def list_block_2(conn, name, tool):
         '''
 
     div += '</tbody></table>'
-
-    if not name:
-        div += next_fix('/block_log?num=', num, data_list)
-    else:
-        div += next_fix('/' + url_pas(tool) + '/' + url_pas(name) + '?num=', num, data_list)
+    div += next_fix('/block_log?num=', num, data_list) if not name else next_fix('/' + url_pas(tool) + '/' + url_pas(name) + '?num=', num, data_list)
 
     return easy_minify(flask.render_template(skin_check(),
         imp = [load_lang('recent_ban'), wiki_set(), custom(), other2([sub, 0])],

+ 15 - 12
route/tool/func.py

@@ -520,11 +520,20 @@ def next_fix(link, num, page, end = 50):
 
     if num == 1:
         if len(page) == end:
-            list_data += '<hr class=\"main_hr\"><a href="' + link + str(num + 1) + '">(' + load_lang('next') + ')</a>'
+            list_data += '' + \
+                '<hr class="main_hr">' + \
+                '<a href="' + link + str(num + 1) + '">(' + load_lang('next') + ')</a>' + \
+            ''
     elif len(page) != end:
-        list_data += '<hr class=\"main_hr\"><a href="' + link + str(num - 1) + '">(' + load_lang('previous') + ')</a>'
+        list_data += '' + \
+            '<hr class="main_hr">' + \
+            '<a href="' + link + str(num - 1) + '">(' + load_lang('previous') + ')</a>' + \
+        ''
     else:
-        list_data += '<hr class=\"main_hr\"><a href="' + link + str(num - 1) + '">(' + load_lang('previous') + ')</a> <a href="' + link + str(num + 1) + '">(' + load_lang('next') + ')</a>'
+        list_data += '' + \
+            '<hr class="main_hr">' + \
+            '<a href="' + link + str(num - 1) + '">(' + load_lang('previous') + ')</a> <a href="' + link + str(num + 1) + '">(' + load_lang('next') + ')</a>' + \
+        ''
 
     return list_data
 
@@ -762,11 +771,8 @@ def custom():
         user_name = ip
 
         curs.execute(db_change('select data from user_set where name = "email" and id = ?'), [ip])
-        data = curs.fetchall()
-        if data:
-            email = data[0][0]
-        else:
-            email = ''
+        email = curs.fetchall()
+        email = email[0][0] if email else ''
 
         if admin_check('all') == 1:
             user_admin = '1'
@@ -801,10 +807,7 @@ def custom():
         user_notice = '0'
 
     curs.execute(db_change("select title from rd where title = ? and stop = ''"), ['user:' + ip])
-    if curs.fetchall():
-        user_topic = '1'
-    else:
-        user_topic = '0'
+    user_topic = '1' if curs.fetchall() else '0'
 
     return [
         '',

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "master" : {
-        "r_ver" : "v3.1.9-master-29",
+        "r_ver" : "v3.1.9-master-30",
         "c_ver" : "3192800",
         "s_ver" : "9"
     }, "stable" : {