diff options
| author | Hunternif | 2019-04-17 00:48:01 +0700 |
|---|---|---|
| committer | Hunternif | 2019-04-17 01:03:15 +0700 |
| commit | 84e95aa6b64c66bd8081133601796340cf4896b7 (patch) | |
| tree | 6d53a4f427bd75f600abd694bc22ae01fcfe3a78 | |
| parent | 284e4f75f5033c7b13cd5fccdd43120bfdfb8aec (diff) | |
server: correctly parse metric in request, save it and disable snapshots
| -rw-r--r-- | server/szurubooru/api/metric_api.py | 2 | ||||
| -rw-r--r-- | server/szurubooru/api/tag_api.py | 4 | ||||
| -rw-r--r-- | server/szurubooru/func/metrics.py | 4 | ||||
| -rw-r--r-- | server/szurubooru/rest/context.py | 3 |
4 files changed, 9 insertions, 4 deletions
diff --git a/server/szurubooru/api/metric_api.py b/server/szurubooru/api/metric_api.py index 092d9e5..1d6d82b 100644 --- a/server/szurubooru/api/metric_api.py +++ b/server/szurubooru/api/metric_api.py @@ -20,6 +20,6 @@ def create_tag(ctx: rest.Context, params: Dict[str, str] = {}) -> rest.Response: metric = metrics.create_metric(tag, min, max) ctx.session.add(metric) ctx.session.flush() - snapshots.create(metric, ctx.user) + # snapshots.create(metric, ctx.user) ctx.session.commit() return _serialize(ctx, metric) diff --git a/server/szurubooru/api/tag_api.py b/server/szurubooru/api/tag_api.py index 6fb5af5..342afb7 100644 --- a/server/szurubooru/api/tag_api.py +++ b/server/szurubooru/api/tag_api.py @@ -92,11 +92,11 @@ def update_tag(ctx: rest.Context, params: Dict[str, str]) -> rest.Response: tags.update_tag_implications(tag, implications) if ctx.has_param('metric'): auth.verify_privilege(ctx.user, 'metrics:edit:bounds') - new_metric = metrics.update_metric(tag, ctx.get_param_as_list('metric')[0]) + new_metric = metrics.update_metric(tag, ctx.get_param('metric')) if new_metric is not None: auth.verify_privilege(ctx.user, 'metrics:create') db.session.flush() - snapshots.create(new_metric, ctx.user) + # snapshots.create(new_metric, ctx.user) tag.last_edit_time = datetime.utcnow() ctx.session.flush() diff --git a/server/szurubooru/func/metrics.py b/server/szurubooru/func/metrics.py index bdf73ff..d2af7c8 100644 --- a/server/szurubooru/func/metrics.py +++ b/server/szurubooru/func/metrics.py @@ -51,10 +51,12 @@ def update_metric(tag: model.Tag, metric_data) -> Optional[model.Metric]: raise InvalidMetricError('Metric is missing %r field.' % field) min, max = metric_data['min'], metric_data['max'] - if tag.metric is None: + if tag.metric is not None: tag.metric.min = min tag.metric.max = max + db.session.add(tag.metric) return None else: metric = model.Metric(tag=tag, min=min, max=max) + db.session.add(metric) return metric diff --git a/server/szurubooru/rest/context.py b/server/szurubooru/rest/context.py index 647e2e3..0d4535a 100644 --- a/server/szurubooru/rest/context.py +++ b/server/szurubooru/rest/context.py @@ -69,6 +69,9 @@ class Context: def has_param(self, name: str) -> bool: return name in self._params + def get_param(self, name: str) -> Any: + return self._params[name] + def get_param_as_list( self, name: str, |