server/scores: voting for <1 removes favorite
This commit is contained in:
parent
b28f689077
commit
053d1889e0
1 changed files with 10 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
from szurubooru import db, errors
|
from szurubooru import db, errors
|
||||||
|
from szurubooru.func import favorites
|
||||||
|
|
||||||
class InvalidScoreTargetError(errors.ValidationError): pass
|
class InvalidScoreTargetError(errors.ValidationError): pass
|
||||||
class InvalidScoreValueError(errors.ValidationError): pass
|
class InvalidScoreValueError(errors.ValidationError): pass
|
||||||
|
@ -32,6 +33,10 @@ def get_score(entity, user):
|
||||||
def set_score(entity, user, score):
|
def set_score(entity, user, score):
|
||||||
if not score:
|
if not score:
|
||||||
delete_score(entity, user)
|
delete_score(entity, user)
|
||||||
|
try:
|
||||||
|
favorites.unset_favorite(entity, user)
|
||||||
|
except favorites.InvalidFavoriteTargetError:
|
||||||
|
pass
|
||||||
return
|
return
|
||||||
if score not in (-1, 1):
|
if score not in (-1, 1):
|
||||||
raise InvalidScoreValueError(
|
raise InvalidScoreValueError(
|
||||||
|
@ -39,6 +44,11 @@ def set_score(entity, user, score):
|
||||||
score_entity = _get_score_entity(entity, user)
|
score_entity = _get_score_entity(entity, user)
|
||||||
if score_entity:
|
if score_entity:
|
||||||
score_entity.score = score
|
score_entity.score = score
|
||||||
|
if score < 1:
|
||||||
|
try:
|
||||||
|
favorites.unset_favorite(entity, user)
|
||||||
|
except favorites.InvalidFavoriteTargetError:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
table, get_column = _get_table_info(entity)
|
table, get_column = _get_table_info(entity)
|
||||||
score_entity = table()
|
score_entity = table()
|
||||||
|
|
Loading…
Reference in a new issue