recent_app_submit.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. from .tool.func import *
  2. def recent_app_submit_2():
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. div = ''
  6. curs.execute(db_change('select data from other where name = "requires_approval"'))
  7. requires_approval = curs.fetchall()
  8. if requires_approval and requires_approval[0][0] != 'on':
  9. div += get_lang(conn, 'approval_requirement_disabled')
  10. if flask.request.method == 'GET':
  11. curs.execute(db_change('select data from user_set where name = "application"'))
  12. db_data = curs.fetchall()
  13. if db_data:
  14. div += '' + \
  15. get_lang(conn, 'all_register_num') + ' : ' + str(len(db_data)) + \
  16. '<hr class="main_hr">' + \
  17. ''
  18. div += '''
  19. <table id="main_table_set">
  20. <tr id="main_table_top_tr">
  21. <td id="main_table_width_half">''' + get_lang(conn, 'id') + '''</td>
  22. <td id="main_table_width_half">''' + get_lang(conn, 'email') + '''</td>
  23. </tr>
  24. <tr id="main_table_top_tr">
  25. <td>''' + get_lang(conn, 'approval_question') + '''</td>
  26. <td>''' + get_lang(conn, 'answer') + '''</td>
  27. </tr>
  28. '''
  29. for application in db_data:
  30. application = json.loads(application[0])
  31. if 'question' in application:
  32. question = html.escape(application['question'])
  33. question = question if question != '' else '<br>'
  34. else:
  35. question = '<br>'
  36. if 'answer' in application:
  37. answer = html.escape(application['answer'])
  38. answer = answer if answer != '' else '<br>'
  39. else:
  40. answer = '<br>'
  41. if 'email' in application:
  42. email = html.escape(application['email'])
  43. email = email if email != '' else '<br>'
  44. else:
  45. email = '<br>'
  46. div += '''
  47. <form method="post">
  48. <tr>
  49. <td>''' + application['id'] + '''</td>
  50. <td>''' + email + '''</td>
  51. </tr>
  52. <tr>
  53. <td>''' + question + '''</td>
  54. <td>''' + answer + '''</td>
  55. </tr>
  56. <tr>
  57. <td colspan="3">
  58. <button type="submit"
  59. id="opennamu_save_button"
  60. name="approve"
  61. value="''' + application['id'] + '''">
  62. ''' + get_lang(conn, 'approve') + '''
  63. </button>
  64. <button type="submit"
  65. name="decline"
  66. value="''' + application['id'] + '''">
  67. ''' + get_lang(conn, 'decline') + '''
  68. </button>
  69. </td>
  70. </tr>
  71. </form>
  72. '''
  73. div += '</table>'
  74. else:
  75. div += get_lang(conn, 'no_applications_now')
  76. return easy_minify(conn, flask.render_template(skin_check(conn),
  77. imp = [get_lang(conn, 'application_list'), wiki_set(conn), wiki_custom(conn), wiki_css([0, 0])],
  78. data = div,
  79. menu = [['other', get_lang(conn, 'return')]]
  80. ))
  81. else:
  82. if admin_check(conn, None, 'app submit') != 1:
  83. return re_error(conn, '/ban')
  84. if flask.request.form.get('approve', '') != '':
  85. curs.execute(db_change('select data from user_set where id = ? and name = "application"'), [flask.request.form.get('approve', '')])
  86. application = curs.fetchall()
  87. if not application:
  88. return re_error(conn, '/error/26')
  89. else:
  90. application = json.loads(application[0][0])
  91. add_user(conn, application['id'], application['pw'], application['email'], application['encode'])
  92. curs.execute(db_change("insert into user_set (name, id, data) values ('approval_question', ?, ?)"), [application['id'], application['question']])
  93. curs.execute(db_change("insert into user_set (name, id, data) values ('approval_question_answer', ?, ?)"), [application['id'], application['answer']])
  94. curs.execute(db_change('delete from user_set where id = ? and name = "application"'), [application['id']])
  95. elif flask.request.form.get('decline', '') != '':
  96. curs.execute(db_change('delete from user_set where id = ? and name = "application"'), [flask.request.form.get('decline', '')])
  97. return redirect(conn, '/app_submit')