diff --git a/app/api/inventory.py b/app/api/inventory.py index 245ef2fae4833d5b17f8a603b5f71e0d8b9cf490..2a75c36edddf0831429dcb5cb23b6700b03cdeb8 100644 --- a/app/api/inventory.py +++ b/app/api/inventory.py @@ -126,7 +126,7 @@ def get_item_comments(id_): def create_item_comment(id_): item = get_item_by_id_or_ics_id(id_) return create_generic_model(models.ItemComment, - mandatory_fields=('text',), + mandatory_fields=('body',), item_id=item.id) diff --git a/app/inventory/forms.py b/app/inventory/forms.py index e07a02f04496f0af926736272c1eb4f2bbb65242..dbac83a802bb2792f608eaccb452a7cced48bb0d 100644 --- a/app/inventory/forms.py +++ b/app/inventory/forms.py @@ -47,5 +47,5 @@ class ItemForm(CSEntryForm): class CommentForm(CSEntryForm): - text = TextAreaField('Enter your comment:', + body = TextAreaField('Enter your comment:', validators=[validators.DataRequired()]) diff --git a/app/inventory/views.py b/app/inventory/views.py index fd4b4663cc71c160a4515835df8fd7fb1c82c2f2..c91f8d883d196dbf3d6b38cc466be8e53a12add3 100644 --- a/app/inventory/views.py +++ b/app/inventory/views.py @@ -91,7 +91,7 @@ def comment_item(ics_id): item = models.Item.query.filter_by(ics_id=ics_id).first_or_404() form = CommentForm() if form.validate_on_submit(): - comment = models.ItemComment(text=form.text.data, + comment = models.ItemComment(body=form.body.data, item_id=item.id) db.session.add(comment) db.session.commit() diff --git a/app/models.py b/app/models.py index eaac0066b7982fb219a9c070f892bc7a1a72067d..99e32c9a59605d3032883a0d00e78d990dcc355c 100644 --- a/app/models.py +++ b/app/models.py @@ -358,16 +358,16 @@ class Item(CreatedMixin, db.Model): class ItemComment(CreatedMixin, db.Model): - text = db.Column(db.Text, nullable=False) + body = db.Column(db.Text, nullable=False) item_id = db.Column(db.Integer, db.ForeignKey('item.id'), nullable=False) def __str__(self): - return self.text + return self.body def to_dict(self): d = super().to_dict() d.update({ - 'text': self.text, + 'body': self.body, 'item': str(self.item), }) return d diff --git a/app/static/js/items.js b/app/static/js/items.js index 72a71bc46d2adda264beb069738c04e504d6320c..1fcc4ebb0bb66a320c552faf15beb2079ba2577d 100644 --- a/app/static/js/items.js +++ b/app/static/js/items.js @@ -2,7 +2,7 @@ $(document).ready(function() { // scroll up to avoid having the form input // hidden under the navbar - if (location.hash == "#text") { + if (location.hash == "#body") { scrollBy(0, -100); } @@ -11,7 +11,7 @@ $(document).ready(function() { }); // Live rendering of markdown comment to HTML - $("#text").keyup(function(event) { + $("#body").keyup(function(event) { var comment = $(this).val(); $("#commentLivePreview").html(converter.makeHtml(comment)); }); diff --git a/app/templates/inventory/comment_item.html b/app/templates/inventory/comment_item.html index 7454ebb98e35f7ad794976262607d136d73f3ed8..04e602088b058cc5c42fbbc5b5e2c1cfc61addc1 100644 --- a/app/templates/inventory/comment_item.html +++ b/app/templates/inventory/comment_item.html @@ -4,8 +4,8 @@ <form id="CommentForm" method="POST"> {{ form.hidden_tag() }} <div class="form-group"> - {{ form.text.label() }} - {{ form.text(class_="form-control", rows=5, required=True) }} + {{ form.body.label() }} + {{ form.body(class_="form-control", rows=5, required=True) }} <small class="form-text text-muted">Styling with Markdown is supported using <a href="https://github.com/showdownjs/showdown/wiki/Showdown's-Markdown-syntax" target="_blank">Showdown</a>. A preview is visible below. diff --git a/app/templates/inventory/view_item.html b/app/templates/inventory/view_item.html index d4f3d70e150ce7820e2a57551e501c168e3f3c29..a86750da144b3595f83d63ad994a451958cf14b6 100644 --- a/app/templates/inventory/view_item.html +++ b/app/templates/inventory/view_item.html @@ -53,11 +53,11 @@ <div class="card-header"> {{ comment.user }} commented on {{ format_datetime(comment.created_at) }} </div> - <div class="card-body item-comment">{{ comment.text }}</div> + <div class="card-body item-comment">{{ comment.body }}</div> </div> {% endfor %} {% block comment_item %} - <a class="btn btn-primary" href="{{ url_for('inventory.comment_item', ics_id=item.ics_id) }}#text">Comment</a> + <a class="btn btn-primary" href="{{ url_for('inventory.comment_item', ics_id=item.ics_id) }}#body">Comment</a> {% endblock %} <hr>