topic_list.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from .tool.func import *
  2. def topic_list(name = 'Test'):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. div = ''
  6. tool = flask.request.args.get('tool', '')
  7. plus = ''
  8. menu = [['topic/' + url_pas(name), load_lang('return')]]
  9. if tool == 'close':
  10. curs.execute(db_change("select code, sub from rd where title = ? and stop = 'O' order by sub asc"), [name])
  11. sub = load_lang('closed_discussion')
  12. elif tool == 'agree':
  13. curs.execute(db_change("select code, sub from rd where title = ? and agree = 'O' order by sub asc"), [name])
  14. sub = load_lang('agreed_discussion')
  15. else:
  16. sub = load_lang('discussion_list')
  17. menu = [['w/' + url_pas(name), load_lang('document')]]
  18. plus = '''
  19. <a href="/topic/''' + url_pas(name) + '?tool=close">(' + load_lang('closed_discussion') + ''')</a>
  20. <a href="/topic/''' + url_pas(name) + '?tool=agree">(' + load_lang('agreed_discussion') + ''')</a>
  21. <hr class="main_hr">
  22. <a href="/thread/0">(''' + load_lang('make_new_topic') + ''')</a>
  23. '''
  24. curs.execute(db_change("select code, sub from rd where title = ? and stop != 'O' order by date desc"), [name])
  25. for data in curs.fetchall():
  26. curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [data[0]])
  27. t_data = curs.fetchall()
  28. div += '''
  29. <h2><a href="/thread/''' + data[0] + '">' + data[0] + '. ' + data[1] + '''</a></h2>
  30. <div id="topic_pre_''' + data[0] + '''"></div>
  31. <div id="topic_back_pre_''' + data[0] + '''"></div>
  32. <script>
  33. opennamu_do_thread_make(''' + data[0] + ', "list", "/normal/1", "topic_pre_' + data[0] + '''");
  34. if(''' + t_data[0][0] + ''' !== 1) {
  35. opennamu_do_thread_make(''' + data[0] + ', "list", "/normal/' + t_data[0][0] + '", "topic_back_pre_' + data[0] + '''");
  36. }
  37. </script>
  38. '''
  39. if div == '':
  40. plus = re.sub(r'^<br>', '', plus)
  41. return easy_minify(flask.render_template(skin_check(),
  42. imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + sub + ')', 0])],
  43. data = div + plus,
  44. menu = menu
  45. ))