Skip to content

Commit 471be5a

Browse files
author
wongband
committed
Added schema to update tags correctly
1 parent 00d803b commit 471be5a

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

backend/conduit/tags/serializers.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ def dump_Tag(self, data, **kwargs):
2626
return {'tag': data}
2727

2828

29+
class TagFormSchema(Schema):
30+
tagname = fields.Str()
31+
description = fields.Str()
32+
slug = fields.Str()
33+
old_slug = fields.Str()
34+
icon = fields.Str()
35+
modSetting = fields.Int()
36+
tag = fields.Nested('self', exclude=('tag',), default=True, load_only=True)
37+
38+
@pre_load
39+
def make_Tag(self, data, **kwargs):
40+
return data['tag']
41+
42+
@post_dump
43+
def dump_Tag(self, data, **kwargs):
44+
return {'tag': data}
45+
46+
2947
class TagsSchema(TagSchema):
3048
class Meta:
3149
exclude = ('tagFollowers', 'moderators',)
@@ -49,5 +67,6 @@ def dump_Tag(self, data, **kwargs):
4967

5068

5169
tag_schema = TagSchema()
70+
tag_form_schema = TagFormSchema()
5271
tags_schemas = TagsSchema(many=True)
5372
tag_mebership_schema = TagMembershipSchema()

backend/conduit/tags/views.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .models import Tags
2-
from .serializers import tag_schema, tag_mebership_schema
2+
from .serializers import tag_schema, tag_form_schema, tag_mebership_schema
33

44
from conduit.decorators import isAdmin
55
from conduit.exceptions import InvalidUsage
@@ -46,10 +46,10 @@ def get_tag(slug, **kwargs):
4646

4747
@blueprint.route('/api/tags/<slug>', methods=('PUT',))
4848
@jwt_required
49-
@use_kwargs(tag_schema)
50-
@marshal_with(tag_schema)
51-
def update_tag(slug, **kwargs):
52-
tag = Tags.query.filter_by(slug=slug).first()
49+
@use_kwargs(tag_form_schema)
50+
@marshal_with(tag_form_schema)
51+
def update_tag(old_slug, **kwargs):
52+
tag = Tags.query.filter_by(slug=old_slug).first()
5353
if not tag:
5454
raise InvalidUsage.tag_not_found()
5555
tag.update(**kwargs)

0 commit comments

Comments
 (0)