Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""LICENSE 

2Copyright 2020 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of otaku-info-web. 

5 

6otaku-info-web is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11otaku-info-web is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with otaku-info-web. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20from flask import request, render_template, redirect, url_for 

21from flask.blueprints import Blueprint 

22from flask_login import login_required, current_user 

23from otaku_info_web.utils.enums import MediaType, ListService 

24from otaku_info_web.utils.manga_updates.generator import prepare_manga_updates 

25from otaku_info_web.db.MediaList import MediaList 

26 

27 

28def define_blueprint(blueprint_name: str) -> Blueprint: 

29 """ 

30 Defines the blueprint for this route 

31 :param blueprint_name: The name of the blueprint 

32 :return: The blueprint 

33 """ 

34 blueprint = Blueprint(blueprint_name, __name__) 

35 

36 @blueprint.route("/manga/updates", methods=["POST"]) 

37 @login_required 

38 def redirect_manga_updates(): 

39 """ 

40 Redirects a POST requests to the appropriate GET request for 

41 the /manga/updates route 

42 :return: The response 

43 """ 

44 service, list_name = request.form["list_ident"].split(":", 1) 

45 mincount = request.form.get("mincount", "0") 

46 include_complete = request.form.get("include_complete", "off") == "on" 

47 

48 get_url = url_for("manga.show_manga_updates") 

49 get_url += f"?service={service}" \ 

50 f"&list_name={list_name}" \ 

51 f"&mincount={mincount}" \ 

52 f"&include_complete={1 if include_complete else 0}" 

53 

54 return redirect(get_url) 

55 

56 @blueprint.route("/manga/updates", methods=["GET"]) 

57 @login_required 

58 def show_manga_updates(): 

59 """ 

60 Shows the user's manga updates for a specified service and list 

61 :return: The response 

62 """ 

63 service = request.args.get("service") 

64 list_name = request.args.get("list_name") 

65 mincount = int(request.args.get("mincount", "0")) 

66 include_complete = request.args.get("include_complete", "0") == "1" 

67 

68 if service is None or list_name is None: 

69 media_lists = [ 

70 x for x in MediaList.query.filter_by( 

71 user=current_user, media_type=MediaType.MANGA 

72 ) 

73 ] 

74 return render_template( 

75 "manga/manga_updates.html", 

76 media_lists=media_lists 

77 ) 

78 else: 

79 list_entries = \ 

80 prepare_manga_updates( 

81 current_user, 

82 ListService(service), 

83 list_name, 

84 include_complete, 

85 mincount 

86 ) 

87 list_entries.sort(key=lambda x: x.score, reverse=True) 

88 return render_template( 

89 "manga/manga_updates.html", 

90 entries=list_entries, 

91 list_name=list_name, 

92 service=service 

93 ) 

94 

95 return blueprint