2
0

user_watch_list_name.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from .tool.func import *
  2. def user_watch_list_name(tool, name = 'Test'):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. ip = ip_check()
  6. if ip_or_user(ip) != 0:
  7. return redirect('/login')
  8. name_from = 0
  9. if tool == 'watch_list_from':
  10. name_from = 1
  11. tool = 'watch_list'
  12. elif tool == 'star_doc_from':
  13. name_from = 1
  14. tool = 'star_doc'
  15. if tool == 'watch_list':
  16. type_data = 'watchlist'
  17. else:
  18. type_data = 'star_doc'
  19. curs.execute(db_change("select data from user_set where name = ? and id = ? and data = ?"), [type_data, ip, name])
  20. if curs.fetchall():
  21. curs.execute(db_change("delete from user_set where name = ? and id = ? and data = ?"), [type_data, ip, name])
  22. else:
  23. if tool == 'watch_list':
  24. curs.execute(db_change("select count(*) from user_set where id = ? and name = ?"), [ip, type_data])
  25. count = curs.fetchall()
  26. if count and count[0][0] > 10:
  27. return re_error('/error/28')
  28. curs.execute(db_change("insert into user_set (id, name, data) values (?, ?, ?)"), [ip, type_data, name])
  29. conn.commit()
  30. if name_from == 1:
  31. return redirect('/w/' + url_pas(name))
  32. else:
  33. if tool == 'watch_list':
  34. return redirect('/watch_list')
  35. else:
  36. return redirect('/star_doc')