From 2c9926c70e0248067d153c8bda9d45c477641d83 Mon Sep 17 00:00:00 2001
From: "J.-S. Caux" <J.S.Caux@uva.nl>
Date: Fri, 29 Jan 2016 16:08:08 +0100
Subject: [PATCH] Introduce django-crispy-forms for Comments

---
 SciPost_v1/settings.py                        |  1 +
 .../commentaries/commentary_detail.html       | 10 +++++++
 comments/forms.py                             | 27 +++++++++++++++++++
 scipost/static/scipost/SciPost.css            |  4 +++
 4 files changed, 42 insertions(+)

diff --git a/SciPost_v1/settings.py b/SciPost_v1/settings.py
index 44ee499c1..1fecf7eb0 100644
--- a/SciPost_v1/settings.py
+++ b/SciPost_v1/settings.py
@@ -54,6 +54,7 @@ INSTALLED_APPS = (
     'django_countries',
     'django_mathjax',
     'captcha',
+    'crispy_forms',
     'commentaries',
     'comments',
     'journals',
diff --git a/commentaries/templates/commentaries/commentary_detail.html b/commentaries/templates/commentaries/commentary_detail.html
index 8055676bb..2166208dd 100644
--- a/commentaries/templates/commentaries/commentary_detail.html
+++ b/commentaries/templates/commentaries/commentary_detail.html
@@ -16,6 +16,7 @@
   });
 </script>
 
+{% load crispy_forms_tags %}
 
 {% endblock headsup %}
 
@@ -240,11 +241,13 @@
 <section>
   <hr class="hr12">
   <div class="row">
+<!--
     <div class="col-3">
       <h1>Contribute a Comment</h1>
       <p>Specify which category your comment belongs to (you can choose more than one).</p>
       <p>In your comment, you can use LaTeX \$...\$ for in-text equations or \ [ ... \ ] for on-line equations.</p>
     </div>
+
     <div class="col-9">
       <form action="{% url 'commentaries:commentary' commentary.id %}" method="post">
 	{% csrf_token %}
@@ -272,6 +275,13 @@
 	  </div>
 	</div>
       </form>
+-->
+
+    <form action="{% url 'commentaries:commentary' commentary.id %}" method="post">
+      {% csrf_token %}
+      {% crispy form %}
+    </form>
+
     </div>
   </div>
 </section>
diff --git a/comments/forms.py b/comments/forms.py
index c6c133dc6..e20631a27 100644
--- a/comments/forms.py
+++ b/comments/forms.py
@@ -2,6 +2,10 @@ from django import *
 
 from .models import *
 
+from crispy_forms.helper import FormHelper
+from crispy_forms.layout import Layout, Div, Field, Fieldset, HTML, Submit
+
+
 COMMENT_ACTION_CHOICES = (
 #    (0, 'modify'), 
     (1, 'accept'), 
@@ -49,6 +53,29 @@ class CommentForm(forms.ModelForm):
     def __init__(self, *args, **kwargs):
         super(CommentForm, self).__init__(*args, **kwargs)
         self.fields['comment_text'].widget.attrs.update({'placeholder': 'NOTE: only serious and meaningful Comments will be accepted.'})
+        self.helper = FormHelper()
+        self.helper.layout = Layout(
+            HTML('<h1>Contribute a Comment</h1>'),
+            Div(
+                Div(
+                    Fieldset(
+                        'Specify categorization',
+                        'is_rem', 'is_que', 'is_ans', 'is_obj', 'is_rep', 'is_val', 'is_lit', 'is_sug',
+                        style="border: 0px"),
+                    css_class="col-4"),
+                Div(
+                    Field('comment_text'), 
+                    Field('anonymous'),
+                    HTML('<p>In your comment, you can use LaTeX \$...\$ for in-text equations or \ [ ... \ ] for on-line equations.</p>'),
+                    HTML('<p id="goodCommenter"><i>Be professional. Only serious and meaningful comments will be vetted through.</i></p>'),
+                    HTML('<p id="goodCommenter"><i> By clicking on Submit, the commenter certifies that all sources used are duly referenced and cited. Failure to do so will lead to exclusion from the portal.</i></p>'),
+                    Submit('submit', 'Submit', css_class="submitComment"),
+                    css_class="col-8"),
+                css_class="row"),
+            )
+        
+                
+    
 
 class VetCommentForm(forms.Form):
     action_option = forms.ChoiceField(widget=forms.RadioSelect, choices=COMMENT_ACTION_CHOICES, required=True, label='Action')
diff --git a/scipost/static/scipost/SciPost.css b/scipost/static/scipost/SciPost.css
index 852af381f..b10f96676 100644
--- a/scipost/static/scipost/SciPost.css
+++ b/scipost/static/scipost/SciPost.css
@@ -192,6 +192,10 @@ a:hover {
   text-decoration: underline;
 }
 
+.submitComment {
+  background-color: #002B49;
+  color: #FFA300;
+}
 
 header {
   background-color: #002B49;
-- 
GitLab