diff options
| author | Ilya Tetin | 2019-04-23 10:59:42 +0700 |
|---|---|---|
| committer | Ilya Tetin | 2019-04-23 10:59:42 +0700 |
| commit | 218f153a2c6cfd43da7770f1ce3b9a4d314f3295 (patch) | |
| tree | a667078bb05e2c7774ad3a891e5be152f5e7f067 /server/szurubooru/func/metrics.py | |
| parent | a70efa5bb1270b3fe9f1f4efcf2d88529fa64756 (diff) | |
server: fix AND condition in post metric queries
Diffstat (limited to 'server/szurubooru/func/metrics.py')
| -rw-r--r-- | server/szurubooru/func/metrics.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/server/szurubooru/func/metrics.py b/server/szurubooru/func/metrics.py index 93fb973..7545b65 100644 --- a/server/szurubooru/func/metrics.py +++ b/server/szurubooru/func/metrics.py @@ -118,8 +118,8 @@ def try_get_post_metric( return ( db.session .query(model.PostMetric) - .filter(model.PostMetric.metric == metric and - model.PostMetric.post == post) + .filter(model.PostMetric.metric == metric) + .filter(model.PostMetric.post == post) .one_or_none()) @@ -129,8 +129,8 @@ def try_get_post_metric_range( return ( db.session .query(model.PostMetricRange) - .filter(model.PostMetricRange.metric == metric and - model.PostMetricRange.post == post) + .filter(model.PostMetricRange.metric == metric) + .filter(model.PostMetricRange.post == post) .one_or_none()) @@ -139,7 +139,7 @@ def create_metric( min: float, max: float) -> model.Metric: assert tag - if tag.metric is not None: + if tag.metric: raise MetricAlreadyExistsError('Tag already has a metric.') if min >= max: raise InvalidMetricError('Metric min(%r) >= max(%r)' % (min, max)) @@ -159,7 +159,7 @@ def update_or_create_metric( min, max = metric_data['min'], metric_data['max'] if min >= max: raise InvalidMetricError('Metric min(%r) >= max(%r)' % (min, max)) - if tag.metric is not None: + if tag.metric: tag.metric.min = min tag.metric.max = max versions.bump_version(tag.metric) @@ -203,7 +203,7 @@ def update_or_create_post_metrics(post: model.Post, metrics_data: Any) -> None: value = float(metric_data['value']) tag_name = metric_data['tag_name'] tag = tags.get_tag_by_name(tag_name) - if tag.metric is None: + if not tag.metric: raise MetricDoesNotExistsError( 'Tag %r has no metric.' % tag_name) post_metric = update_or_create_post_metric(post, tag.metric, value) @@ -256,7 +256,7 @@ def update_or_create_post_metric_ranges( high = float(metric_data['high']) tag_name = metric_data['tag_name'] tag = tags.get_tag_by_name(tag_name) - if tag.metric is None: + if not tag.metric: raise MetricDoesNotExistsError( 'Tag %r has no metric.' % tag_name) post_metric_range = update_or_create_post_metric_range( |