Parcourir la source

https://github.com/openNAMU/openNAMU/issues/1499

잉여개발기 (SPDV) il y a 2 ans
Parent
commit
f2d3bc5f91
6 fichiers modifiés avec 118 ajouts et 131 suppressions
  1. 1 0
      route/__init__.py
  2. 1 1
      route/main_setting.py
  3. 24 37
      route/main_setting_sitemap.py
  4. 91 0
      route/main_setting_sitemap_set.py
  5. 0 92
      route/tool/func.py
  6. 1 1
      version.json

+ 1 - 0
route/__init__.py

@@ -93,6 +93,7 @@ from route.main_setting_main_logo import main_setting_main_logo
 from route.main_setting_phrase import main_setting_phrase
 from route.main_setting_robot import main_setting_robot
 from route.main_setting_sitemap import main_setting_sitemap
+from route.main_setting_sitemap_set import main_setting_sitemap_set
 from route.main_setting_skin_set import main_setting_skin_set
 from route.main_setting_top_menu import main_setting_top_menu
 

+ 1 - 1
route/main_setting.py

@@ -10,7 +10,7 @@ def main_setting():
             ['head', load_lang('main_head')],
             ['body/top', load_lang('main_body')],
             ['body/bottom', load_lang('main_bottom_body')],
-            ['sitemap', load_lang('sitemap_management')],
+            ['sitemap_set', load_lang('sitemap_management')],
             ['top_menu', load_lang('top_menu_setting')],
             ['skin_set', load_lang('main_skin_set_default')],
             ['acl', load_lang('main_acl_setting')]

+ 24 - 37
route/main_setting_sitemap.py

@@ -1,36 +1,47 @@
 from .tool.func import *
 
-def main_setting_sitemap():
+def main_setting_sitemap(do_type = 0):
     with get_db_connect() as conn:
         curs = conn.cursor()
 
-        if admin_check() != 1:
-            return re_error('/ban')
+        if not do_type == 1:
+            if admin_check() != 1:
+                return re_error('/ban')
         
-        if flask.request.method == 'POST':
-            admin_check(None, 'make sitemap')
+        if do_type == 1 or flask.request.method == 'POST':
+            if not do_type == 1:
+                admin_check(None, 'make sitemap')
 
             data = '' + \
                 '<?xml version="1.0" encoding="UTF-8"?>\n' + \
                 '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' + \
             ''
 
-            if flask.request.form.get('exclude_domain', None):
+            curs.execute(db_change('select data from other where name = "sitemap_auto_exclude_domain"'))
+            db_data = curs.fetchall()
+            if db_data and db_data[0][0] != '':
                 domain = ''
             else:
                 domain = load_domain('full')
 
             sql_add = ''
-            if flask.request.form.get('exclude_user_page', None):
+
+            curs.execute(db_change('select data from other where name = "sitemap_auto_exclude_user_page"'))
+            db_data = curs.fetchall()
+            if db_data and db_data[0][0] != '':
                 sql_add += ' title not like "user:%"'
 
-            if flask.request.form.get('exclude_file_page', None):
+            curs.execute(db_change('select data from other where name = "sitemap_auto_exclude_file_page"'))
+            db_data = curs.fetchall()
+            if db_data and db_data[0][0] != '':
                 if sql_add != '':
                     sql_add += ' and'
 
                 sql_add += ' title not like "file:%"'
 
-            if flask.request.form.get('exclude_category_page', None):
+            curs.execute(db_change('select data from other where name = "sitemap_auto_exclude_category_page"'))
+            db_data = curs.fetchall()
+            if db_data and db_data[0][0] != '':
                 if sql_add != '':
                     sql_add += ' and'
 
@@ -39,7 +50,6 @@ def main_setting_sitemap():
             if sql_add != '':
                 sql_add = ' where' + sql_add
 
-            print(sql_add)
             curs.execute(db_change("select title from data" + sql_add))
             all_data = curs.fetchall()
 
@@ -79,38 +89,15 @@ def main_setting_sitemap():
                 f.write(data)
                 f.close()
 
-            return redirect('/setting/sitemap')
+            if not do_type == 1:
+                return redirect('/setting/sitemap')
         else:
-            sitemap_list = ''
-            if os.path.exists('sitemap.xml'):
-                sitemap_list += '<a href="/sitemap.xml">(' + load_lang('view') + ')</a>'
-
-                for_a = 0
-                while os.path.exists('sitemap_' + str(for_a) + '.xml'):
-                    sitemap_list += ' <a href="/sitemap_' + str(for_a) + '.xml">(sitemap_' + str(for_a) + '.xml)</a>'
-
-                    for_a += 1
-
             return easy_minify(flask.render_template(skin_check(),
-                imp = [load_lang('sitemap_management'), wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('beta') + ')', 0])],
+                imp = [load_lang('sitemap_manual_create'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
                 data = '''
-                    ''' + sitemap_list + '''
-                    <hr class="main_hr">
                     <form method="post">
-                        <input type="checkbox" name="exclude_domain"> ''' + load_lang('stiemap_exclude_domain') + '''
-                        <hr class="main_hr">
-
-                        <input type="checkbox" name="exclude_user_page"> ''' + load_lang('stiemap_exclude_user_page') + '''
-                        <hr class="main_hr">
-
-                        <input type="checkbox" name="exclude_file_page"> ''' + load_lang('stiemap_exclude_file_page') + '''
-                        <hr class="main_hr">
-
-                        <input type="checkbox" name="exclude_category_page"> ''' + load_lang('stiemap_exclude_category_page') + '''
-                        <hr class="main_hr">
-
                         <button id="opennamu_save_button" type="submit">''' + load_lang('create') + '''</button>
                     </form>
                 ''',
-                menu = [['setting', load_lang('return')]]
+                menu = [['setting/sitemap_set', load_lang('return')]]
             ))

+ 91 - 0
route/main_setting_sitemap_set.py

@@ -0,0 +1,91 @@
+from .tool.func import *
+
+def main_setting_sitemap_set():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
+
+        if admin_check() != 1:
+            return re_error('/ban')
+        
+        setting_list = {
+            0 : ['sitemap_auto_exclude_domain', ''],
+            1 : ['sitemap_auto_exclude_user_page', ''],
+            2 : ['sitemap_auto_exclude_file_page', ''],
+            3 : ['sitemap_auto_exclude_category_page', ''],
+            4 : ['sitemap_auto_make', '']
+        }
+
+        if flask.request.method == 'POST':
+            for i in setting_list:
+                curs.execute(db_change("update other set data = ? where name = ?"), [
+                    flask.request.form.get(setting_list[i][0], setting_list[i][1]),
+                    setting_list[i][0]
+                ])
+
+            conn.commit()
+
+            admin_check(None, 'edit_set (sitemap)')
+
+            return redirect('/setting/sitemap_set')
+        else:
+            d_list = {}
+            for i in setting_list:
+                curs.execute(db_change('select data from other where name = ?'), [setting_list[i][0]])
+                db_data = curs.fetchall()
+                if not db_data:
+                    curs.execute(db_change('insert into other (name, data, coverage) values (?, ?, "")'), [
+                        setting_list[i][0],
+                        setting_list[i][1]
+                    ])
+
+                d_list[i] = db_data[0][0] if db_data else setting_list[i][1]
+            else:
+                conn.commit()
+
+            check_box_div = [0, 1, 2, 3, 4, '']
+            for i in range(0, len(check_box_div)):
+                acl_num = check_box_div[i]
+                if acl_num != '' and d_list[acl_num]:
+                    check_box_div[i] = 'checked="checked"'
+                else:
+                    check_box_div[i] = ''
+
+            sitemap_list = ''
+            if os.path.exists('sitemap.xml'):
+                sitemap_list += '<a href="/sitemap.xml">(' + load_lang('view') + ')</a>'
+
+                for_a = 0
+                while os.path.exists('sitemap_' + str(for_a) + '.xml'):
+                    sitemap_list += ' <a href="/sitemap_' + str(for_a) + '.xml">(sitemap_' + str(for_a) + '.xml)</a>'
+
+                    for_a += 1
+
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('sitemap_management'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                data = '''
+                    ''' + sitemap_list + '''
+                    <hr class="main_hr">
+                    <form method="post">
+                        <a href="/setting/sitemap">(''' + load_lang('sitemap_manual_create') + ''')</a>
+                        <hr class="main_hr">
+
+                        <input type="checkbox" ''' + check_box_div[4] + ''' name="sitemap_auto_make"> ''' + load_lang('sitemap_auto_make') + '''
+                        <hr class="main_hr">
+
+                        <input type="checkbox" ''' + check_box_div[0] + ''' name="sitemap_auto_exclude_domain"> ''' + load_lang('stiemap_exclude_domain') + '''
+                        <hr class="main_hr">
+
+                        <input type="checkbox" ''' + check_box_div[1] + ''' name="sitemap_auto_exclude_user_page"> ''' + load_lang('stiemap_exclude_user_page') + '''
+                        <hr class="main_hr">
+
+                        <input type="checkbox" ''' + check_box_div[2] + ''' name="sitemap_auto_exclude_file_page"> ''' + load_lang('stiemap_exclude_file_page') + '''
+                        <hr class="main_hr">
+
+                        <input type="checkbox" ''' + check_box_div[3] + ''' name="sitemap_auto_exclude_category_page"> ''' + load_lang('stiemap_exclude_category_page') + '''
+                        <hr class="main_hr">
+
+                        <button id="opennamu_save_button" type="submit">''' + load_lang('save') + '''</button>
+                    </form>
+                ''',
+                menu = [['setting', load_lang('return')]]
+            ))

+ 0 - 92
route/tool/func.py

@@ -350,98 +350,6 @@ def get_db_table_list():
     
     return create_data
 
-def back_up(data_db_set):
-    with get_db_connect() as conn:
-        curs = conn.cursor()
-    
-        try:
-            curs.execute(db_change('select data from other where name = "back_up"'))
-            back_time = curs.fetchall()
-            back_time = float(number_check(back_time[0][0], True)) if back_time and back_time[0][0] != '' else 0
-
-            curs.execute(db_change('select data from other where name = "backup_count"'))
-            back_up_count = curs.fetchall()
-            back_up_count = int(number_check(back_up_count[0][0])) if back_up_count and back_up_count[0][0] != '' else 3
-
-            if back_time != 0:
-                curs.execute(db_change('select data from other where name = "backup_where"'))
-                back_up_where = curs.fetchall()
-                back_up_where = back_up_where[0][0] if back_up_where and back_up_where[0][0] != '' else data_db_set['name'] + '.db'
-
-                print('Back up state : ' + str(back_time) + ' hours')
-                print('Back up directory : ' + back_up_where)
-                if back_up_count != 0:
-                    print('Back up max number : ' + str(back_up_count))
-
-                    file_dir = os.path.split(back_up_where)[0]
-                    file_dir = '.' if file_dir == '' else file_dir
-                    
-                    file_name = os.path.split(back_up_where)[1]
-                    file_name = re.sub(r'\.db$', '_[0-9]{14}.db', file_name)
-
-                    backup_file = [for_a for for_a in os.listdir(file_dir) if re.search('^' + file_name + '$', for_a)]
-                    backup_file = sorted(backup_file)
-                    
-                    if len(backup_file) >= back_up_count:
-                        remove_dir = os.path.join(file_dir, backup_file[0])
-                        os.remove(remove_dir)
-                        print('Back up : Remove (' + remove_dir + ')')
-
-                now_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
-                new_file_name = re.sub(r'\.db$', '_' + now_time + '.db', back_up_where)
-                shutil.copyfile(
-                    data_db_set['name'] + '.db', 
-                    new_file_name
-                )
-
-                print('Back up : OK (' + new_file_name + ')')
-            else:
-                print('Back up state : Turn off')
-
-                back_time = 1
-        except Exception as e:
-            print('Back up : Error')
-            print(e)
-
-            back_time = 1
-
-        threading.Timer(60 * 60 * back_time, back_up, [data_db_set]).start()
-
-def do_ban_end():
-    with get_db_connect() as conn:
-        curs = conn.cursor()
-
-        curs.execute(db_change("update rb set ongoing = '' where end < ? and end != '' and ongoing = '1'"), [get_time()])
-        conn.commit()
-
-        threading.Timer(60, do_ban_end).start()
-
-def do_vote_end():
-    with get_db_connect() as conn:
-        curs = conn.cursor()
-    
-        curs.execute(db_change('select id, type from vote where type = "open" or type = "n_open"'))
-        for for_a in curs.fetchall():
-            curs.execute(db_change('select data from vote where id = ? and name = "end_date" and type = "option"'), [for_a[0]])
-            db_data = curs.fetchall()
-            if db_data:
-                time_db = db_data[0][0].split()[0]
-                time_today = get_time().split()[0]
-
-                if time_today > time_db:
-                    curs.execute(db_change("update vote set type = ? where user = '' and id = ? and type = ?"), ['close' if for_a[1] == 'open' else 'n_close', for_a[0], for_a[1]])
-
-        conn.commit()
-
-        threading.Timer(60 * 60 * 24, do_ban_end).start()
-
-def auto_do_something(data_db_set):
-    if data_db_set['type'] == 'sqlite':
-        back_up(data_db_set)
-
-    do_ban_end()
-    do_vote_end()
-
 def update(ver_num, set_data):
     with get_db_connect() as conn:
         curs = conn.cursor()

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.4.6-RC5-dev66",
+        "r_ver" : "v3.4.6-RC5-dev67",
         "c_ver" : "3500373",
         "s_ver" : "3500112"
     }