main_setting_sitemap_set.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. from .tool.func import *
  2. def main_setting_sitemap_set():
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. if admin_check() != 1:
  6. return re_error('/ban')
  7. setting_list = {
  8. 0 : ['sitemap_auto_exclude_domain', ''],
  9. 1 : ['sitemap_auto_exclude_user_page', ''],
  10. 2 : ['sitemap_auto_exclude_file_page', ''],
  11. 3 : ['sitemap_auto_exclude_category_page', ''],
  12. 4 : ['sitemap_auto_make', '']
  13. }
  14. if flask.request.method == 'POST':
  15. for i in setting_list:
  16. curs.execute(db_change("update other set data = ? where name = ?"), [
  17. flask.request.form.get(setting_list[i][0], setting_list[i][1]),
  18. setting_list[i][0]
  19. ])
  20. conn.commit()
  21. admin_check(None, 'edit_set (sitemap)')
  22. return redirect('/setting/sitemap_set')
  23. else:
  24. d_list = {}
  25. for i in setting_list:
  26. curs.execute(db_change('select data from other where name = ?'), [setting_list[i][0]])
  27. db_data = curs.fetchall()
  28. if not db_data:
  29. curs.execute(db_change('insert into other (name, data, coverage) values (?, ?, "")'), [
  30. setting_list[i][0],
  31. setting_list[i][1]
  32. ])
  33. d_list[i] = db_data[0][0] if db_data else setting_list[i][1]
  34. else:
  35. conn.commit()
  36. check_box_div = [0, 1, 2, 3, 4, '']
  37. for i in range(0, len(check_box_div)):
  38. acl_num = check_box_div[i]
  39. if acl_num != '' and d_list[acl_num]:
  40. check_box_div[i] = 'checked="checked"'
  41. else:
  42. check_box_div[i] = ''
  43. sitemap_list = ''
  44. if os.path.exists('sitemap.xml'):
  45. sitemap_list += '<a href="/sitemap.xml">(' + load_lang('view') + ')</a>'
  46. for_a = 0
  47. while os.path.exists('sitemap_' + str(for_a) + '.xml'):
  48. sitemap_list += ' <a href="/sitemap_' + str(for_a) + '.xml">(sitemap_' + str(for_a) + '.xml)</a>'
  49. for_a += 1
  50. return easy_minify(flask.render_template(skin_check(),
  51. imp = [load_lang('sitemap_management'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  52. data = '''
  53. ''' + sitemap_list + '''
  54. <hr class="main_hr">
  55. <form method="post">
  56. <a href="/setting/sitemap">(''' + load_lang('sitemap_manual_create') + ''')</a>
  57. <hr class="main_hr">
  58. <input type="checkbox" ''' + check_box_div[4] + ''' name="sitemap_auto_make"> ''' + load_lang('sitemap_auto_make') + '''
  59. <hr class="main_hr">
  60. <input type="checkbox" ''' + check_box_div[0] + ''' name="sitemap_auto_exclude_domain"> ''' + load_lang('stiemap_exclude_domain') + '''
  61. <hr class="main_hr">
  62. <input type="checkbox" ''' + check_box_div[1] + ''' name="sitemap_auto_exclude_user_page"> ''' + load_lang('stiemap_exclude_user_page') + '''
  63. <hr class="main_hr">
  64. <input type="checkbox" ''' + check_box_div[2] + ''' name="sitemap_auto_exclude_file_page"> ''' + load_lang('stiemap_exclude_file_page') + '''
  65. <hr class="main_hr">
  66. <input type="checkbox" ''' + check_box_div[3] + ''' name="sitemap_auto_exclude_category_page"> ''' + load_lang('stiemap_exclude_category_page') + '''
  67. <hr class="main_hr">
  68. <button id="opennamu_save_button" type="submit">''' + load_lang('save') + '''</button>
  69. </form>
  70. ''',
  71. menu = [['setting', load_lang('return')]]
  72. ))