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 url_for 

21from typing import Optional, List, Tuple, Dict, Any 

22from otaku_info_web.utils.enums import ListService, MediaType 

23from otaku_info_web.utils.db_model_helper import build_service_url 

24 

25 

26class MangaUpdate: 

27 """ 

28 Class that encapsulates important data to display for manga updates 

29 """ 

30 

31 def __init__( 

32 self, 

33 media_item_id: int, 

34 title: str, 

35 cover_url: str, 

36 latest_release: int, 

37 progress: int, 

38 score: int, 

39 chapter_guess: Optional[int], 

40 related_ids: List[Tuple[ListService, str]] 

41 ): 

42 """ 

43 Initializes the MangaUpdate object 

44 :param media_item_id: The media item ID 

45 :param title: The title of the update 

46 :param cover_url: The URL for the media item's cover 

47 :param latest_release: The latest known released chapter 

48 :param progress: The user's current progress 

49 :param score: The user's score for this entry 

50 :param chapter_guess: The current chapter guess 

51 :param related_ids: Related service IDs 

52 """ 

53 self.media_item_id = media_item_id 

54 self.title = title 

55 self.cover_url = cover_url 

56 self.score = score 

57 self.progress = progress 

58 self.related_ids = [RelatedMangaId(*args) for args in related_ids] 

59 self.url = url_for("media.media", media_item_id=media_item_id) 

60 

61 if chapter_guess is None: 

62 self.latest = latest_release 

63 else: 

64 self.latest = chapter_guess 

65 

66 if self.latest is None: 

67 self.latest = 0 

68 if self.progress is None: 

69 self.progress = 0 

70 

71 if self.latest < self.progress: 

72 self.latest = self.progress 

73 

74 self.diff = self.latest - self.progress 

75 

76 def __json__(self) -> Dict[str, Any]: 

77 """ 

78 Converts the object into a JSON-compatible dictionary 

79 :return: The JSON-compatible dictionary 

80 """ 

81 return { 

82 "title": self.title, 

83 "cover_url": self.cover_url, 

84 "score": self.score, 

85 "progress": self.progress, 

86 "related_ids": [ 

87 { 

88 "service": x.service.value, 

89 "id": x.service_id, 

90 "url": x.url, 

91 "icon": x.icon 

92 } 

93 for x in self.related_ids 

94 ], 

95 "latest": self.latest, 

96 "diff": self.diff 

97 } 

98 

99 

100class RelatedMangaId: 

101 """ 

102 Class that encapslates attributes for a related manga ID 

103 """ 

104 

105 def __init__(self, service: ListService, service_id: str): 

106 """ 

107 Intializes the RelatedMangaId object 

108 :param service: The service of the related manga ID 

109 :param service_id: The ID on that service 

110 """ 

111 self.service = service 

112 self.service_id = service_id 

113 self.url = build_service_url(MediaType.MANGA, service, service_id) 

114 self.icon = url_for( 

115 "static", filename="service_logos/" + service.value + ".png" 

116 )