From 3d9b8f3a082ed425176731722e5f8dbfc19f18aa Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand <benjamin.bertrand@esss.se> Date: Thu, 21 Dec 2017 15:29:00 +0100 Subject: [PATCH] Rename ItemComment text field to body text is really generic and could conflict with another variable. body is often used for comments. --- app/api/inventory.py | 2 +- app/inventory/forms.py | 2 +- app/inventory/views.py | 2 +- app/models.py | 6 +++--- app/static/js/items.js | 4 ++-- app/templates/inventory/comment_item.html | 4 ++-- app/templates/inventory/view_item.html | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/api/inventory.py b/app/api/inventory.py index 245ef2f..2a75c36 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 e07a02f..dbac83a 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 fd4b466..c91f8d8 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 eaac006..99e32c9 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 72a71bc..1fcc4eb 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 7454ebb..04e6020 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 d4f3d70..a86750d 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> -- GitLab