Fix community rating

The user rating control is replaced with critical rating which is now
represented as a float.
utils.xlate has been updated to have an is_float parameter
Metadata is reloaded on save so that changes can be seen
e.g. for CBL tags the critical rating field only stores integers
This commit is contained in:
Timmy Welch 2022-06-23 13:08:09 -07:00
parent 6c65c2ad56
commit 95643fdace
8 changed files with 28 additions and 60 deletions

View File

@ -95,7 +95,7 @@ class ComicBookInfo:
metadata.volume_count = utils.xlate(cbi["numberOfVolumes"], True)
metadata.language = utils.xlate(cbi["language"])
metadata.country = utils.xlate(cbi["country"])
metadata.critical_rating = utils.xlate(cbi["rating"])
metadata.critical_rating = utils.xlate(cbi["rating"], True)
metadata.credits = cbi["credits"]
metadata.tags = cbi["tags"]
@ -157,7 +157,7 @@ class ComicBookInfo:
assign("numberOfVolumes", utils.xlate(metadata.volume_count, True))
assign("language", utils.xlate(utils.get_language_from_iso(metadata.language)))
assign("country", utils.xlate(metadata.country))
assign("rating", utils.xlate(metadata.critical_rating))
assign("rating", utils.xlate(metadata.critical_rating, True))
assign("credits", metadata.credits)
assign("tags", metadata.tags)

View File

@ -160,7 +160,7 @@ class ComicInfoXml:
assign("LanguageISO", md.language)
assign("Format", md.format)
assign("AgeRating", md.maturity_rating)
assign("CommunityRating", md.community_rating)
assign("CommunityRating", md.critical_rating)
assign("BlackAndWhite", "Yes" if md.black_and_white else None)
assign("Manga", md.manga)
assign("Characters", md.characters)
@ -228,7 +228,7 @@ class ComicInfoXml:
md.story_arc = utils.xlate(get("StoryArc"))
md.series_group = utils.xlate(get("SeriesGroup"))
md.maturity_rating = utils.xlate(get("AgeRating"))
md.community_rating = utils.xlate(get("CommunityRating"))
md.critical_rating = utils.xlate(get("CommunityRating"), is_float=True)
tmp = utils.xlate(get("BlackAndWhite"))
if tmp is not None and tmp.lower() in ["yes", "true", "1"]:

View File

@ -92,7 +92,7 @@ class GenericMetadata:
self.comments: str | None = None # use same way as Summary in CIX
self.volume_count: int | None = None
self.critical_rating: str | None = None
self.critical_rating: float | None = None # rating in cbl; CommunityRating in CIX
self.country: str | None = None
self.alternate_series: str | None = None
@ -106,7 +106,6 @@ class GenericMetadata:
self.black_and_white: bool | None = None
self.page_count: int | None = None
self.maturity_rating: str | None = None
self.community_rating: str | None = None
self.story_arc: str | None = None
self.series_group: str | None = None
@ -168,7 +167,6 @@ class GenericMetadata:
assign("manga", new_md.manga)
assign("black_and_white", new_md.black_and_white)
assign("maturity_rating", new_md.maturity_rating)
assign("community_rating", new_md.community_rating)
assign("story_arc", new_md.story_arc)
assign("series_group", new_md.series_group)
assign("scan_info", new_md.scan_info)
@ -306,7 +304,6 @@ class GenericMetadata:
if self.black_and_white:
add_attr_string("black_and_white")
add_attr_string("maturity_rating")
add_attr_string("community_rating")
add_attr_string("story_arc")
add_attr_string("series_group")
add_attr_string("scan_info")
@ -378,7 +375,7 @@ md_test.comments = (
" and what those characters meant to the livelihood of children around the world."
)
md_test.volume_count = None
md_test.critical_rating = None
md_test.critical_rating = 3.0
md_test.country = None
md_test.alternate_series = "Tales"
md_test.alternate_number = "2"
@ -391,7 +388,6 @@ md_test.manga = "No"
md_test.black_and_white = None
md_test.page_count = 24
md_test.maturity_rating = "Everyone 10+"
md_test.community_rating = "3.0"
md_test.story_arc = "Here and Now"
md_test.series_group = "Futuristic Tales"
md_test.scan_info = "(CC BY-NC-SA 3.0)"

View File

@ -78,16 +78,20 @@ def add_to_path(dirname: str) -> None:
os.environ["PATH"] = dirname + os.pathsep + os.environ["PATH"]
def xlate(data: Any, is_int: bool = False) -> Any:
def xlate(data: Any, is_int: bool = False, is_float: bool = False) -> Any:
if data is None or data == "":
return None
if is_int:
i = str(data).translate(defaultdict(lambda: None, zip((ord(c) for c in "1234567890"), "1234567890")))
if i == "0":
return "0"
if is_int or is_float:
i: str | int | float
if isinstance(data, (int, float)):
i = data
else:
i = str(data).translate(defaultdict(lambda: None, zip((ord(c) for c in "1234567890."), "1234567890.")))
if i == "":
return None
return int(i)
if is_float:
return float(i)
return int(float(i))
return str(data)

View File

@ -77,7 +77,7 @@ Accepts the following variables:
{language} (string)
{comments} (string)
{volume_count} (integer)
{critical_rating} (string)
{critical_rating} (float)
{country} (string)
{alternate_series} (string)
{alternate_number} (string)
@ -90,7 +90,6 @@ Accepts the following variables:
{black_and_white} (boolean)
{page_count} (integer)
{maturity_rating} (string)
{community_rating} (string)
{story_arc} (string)
{series_group} (string)
{scan_info} (string)

View File

@ -796,7 +796,6 @@ Have fun!
assign_text(self.leImprint, md.imprint)
assign_text(self.teComments, md.comments)
assign_text(self.teNotes, md.notes)
assign_text(self.leCriticalRating, md.critical_rating)
assign_text(self.leStoryArc, md.story_arc)
assign_text(self.leScanInfo, md.scan_info)
assign_text(self.leSeriesGroup, md.series_group)
@ -808,10 +807,7 @@ Have fun!
assign_text(self.teTeams, md.teams)
assign_text(self.teLocations, md.locations)
try:
self.dsbCommunityRating.setValue(md.community_rating or 0.0)
except ValueError:
self.dsbCommunityRating.setValue(0.0)
self.dsbCriticalRating.setValue(md.critical_rating or 0.0)
if md.format is not None and md.format != "":
i = self.cbFormat.findText(md.format)
@ -913,7 +909,6 @@ Have fun!
md.month = utils.xlate(self.lePubMonth.text(), True)
md.year = utils.xlate(self.lePubYear.text(), True)
md.day = utils.xlate(self.lePubDay.text(), True)
md.critical_rating = utils.xlate(self.leCriticalRating.text(), True)
md.alternate_count = utils.xlate(self.leAltIssueCount.text(), True)
md.series = self.leSeries.text()
@ -925,9 +920,9 @@ Have fun!
md.notes = self.teNotes.toPlainText()
md.maturity_rating = self.cbMaturityRating.currentText()
md.community_rating = utils.xlate(self.dsbCommunityRating.cleanText())
if md.community_rating == "0.0":
md.community_rating = None
md.critical_rating = utils.xlate(self.dsbCriticalRating.cleanText(), is_float=True)
if md.critical_rating == 0.0:
md.critical_rating = None
md.story_arc = self.leStoryArc.text()
md.scan_info = self.leScanInfo.text()
@ -1122,6 +1117,8 @@ Have fun!
self.update_menus()
self.fileSelectionList.update_current_row()
self.metadata = self.comic_archive.read_metadata(self.load_data_style)
self.actual_load_current_archive()
else:
QtWidgets.QMessageBox.information(self, "Whoops!", "No data to commit!")
@ -1217,7 +1214,7 @@ Have fun!
widget.setReadOnly(True)
widget.setPalette(inactive_palette1)
cbi_only = [self.leVolumeCount, self.cbCountry, self.leCriticalRating, self.teTags]
cbi_only = [self.leVolumeCount, self.cbCountry, self.teTags]
cix_only = [
self.leImprint,
self.teNotes,
@ -1235,7 +1232,6 @@ Have fun!
self.teLocations,
self.cbMaturityRating,
self.cbFormat,
self.dsbCommunityRating,
]
if self.save_data_style == MetaDataStyle.CIX:

View File

@ -78,7 +78,7 @@ tr:nth-child(even) {
<tr><td>{language}</td><td>string</td></tr>
<tr><td>{comments}</td><td>string</td></tr>
<tr><td>{volume_count}</td><td>integer</td></tr>
<tr><td>{critical_rating}</td><td>string</td></tr>
<tr><td>{critical_rating}</td><td>float</td></tr>
<tr><td>{country}</td><td>string</td></tr>
<tr><td>{alternate_series}</td><td>string</td></tr>
<tr><td>{alternate_number}</td><td>string</td></tr>
@ -91,7 +91,6 @@ tr:nth-child(even) {
<tr><td>{black_and_white}</td><td>boolean</td></tr>
<tr><td>{page_count}</td><td>integer</td></tr>
<tr><td>{maturity_rating}</td><td>string</td></tr>
<tr><td>{community_rating}</td><td>string</td></tr>
<tr><td>{story_arc}</td><td>string</td></tr>
<tr><td>{series_group}</td><td>string</td></tr>
<tr><td>{scan_info}</td><td>string</td></tr>

View File

@ -964,41 +964,15 @@
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="userRatingLabel">
<property name="text">
<string>User Rating</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="leCriticalRating">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lblCommunityRating">
<widget class="QLabel" name="lblCriticalRating">
<property name="text">
<string>Community Rating</string>
<string>Critical Rating</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="dsbCommunityRating">
<widget class="QDoubleSpinBox" name="dsbCriticalRating">
<property name="minimumSize">
<size>
<width>80</width>