From 96b1e20ab35e7e79b5ec2b4859264cf9cb468bcd Mon Sep 17 00:00:00 2001
From: "J.-S. Caux" <J.S.Caux@uva.nl>
Date: Sat, 26 Mar 2016 23:05:34 +0100
Subject: [PATCH] Invitation token useable once only; beautify invitation form
 with crispy

---
 scipost/forms.py                                | 17 ++++++++++++++++-
 .../scipost/registration_invitations.html       |  6 ++----
 scipost/utils.py                                |  6 +++---
 scipost/views.py                                |  2 ++
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/scipost/forms.py b/scipost/forms.py
index 99d66613e..082dc0bda 100644
--- a/scipost/forms.py
+++ b/scipost/forms.py
@@ -5,6 +5,9 @@ from django_countries.widgets import CountrySelectWidget
 from django_countries.fields import LazyTypedChoiceField
 from captcha.fields import CaptchaField
 
+from crispy_forms.helper import FormHelper
+from crispy_forms.layout import Layout, Div, Field, Fieldset, HTML, Submit
+
 from .models import *
 
 
@@ -43,7 +46,19 @@ class RegistrationInvitationForm(forms.ModelForm):
     def __init__(self, *args, **kwargs):
         super(RegistrationInvitationForm, self).__init__(*args, **kwargs)
         self.fields['personal_message'].widget.attrs.update({'placeholder': 'NOTE: a personal phrase or two. The bulk of the text will be auto-generated.'})
- 
+        self.helper = FormHelper()
+        self.helper.layout = Layout(
+            Div(
+                Div(
+                    Field('title'), Field('first_name'), Field('last_name'), Field('email_address'), Field('invitation_type'),
+                    css_class="col-6"),
+                Div(
+                    Field('message_style'),
+                    Field('personal_message'), 
+                    Submit('submit', 'Send invitation'),
+                    css_class="col-6"),
+                css_class="row"),
+            )
 
 class UpdateUserDataForm(forms.ModelForm):
     class Meta:
diff --git a/scipost/templates/scipost/registration_invitations.html b/scipost/templates/scipost/registration_invitations.html
index c4445ff75..53eb88e6c 100644
--- a/scipost/templates/scipost/registration_invitations.html
+++ b/scipost/templates/scipost/registration_invitations.html
@@ -16,10 +16,8 @@
   </div>
     <form action="{% url 'scipost:registration_invitations' %}" method="post">
       {% csrf_token %}
-      <table>
-	{{ reg_inv_form.as_table }}
-      </table>
-      <input type="submit" value="Submit" />
+      {% load crispy_forms_tags %}
+      {% crispy reg_inv_form %}
     </form>
 </section>
 <hr class="hr12"/>
diff --git a/scipost/utils.py b/scipost/utils.py
index 016f43f8c..cafdf91df 100644
--- a/scipost/utils.py
+++ b/scipost/utils.py
@@ -117,10 +117,10 @@ class Utils(object):
         cls.invitation.save()
         email_text = 'Dear '
         if cls.invitation.message_style == 'F':
-            email_text += title_dict[cls.invitation.title] + ' ' + cls.invitation.last_name + ',\n\n'
+            email_text += title_dict[cls.invitation.title] + ' ' + cls.invitation.last_name
         else:
-            email_text += cls.invitation.first_name + ',\n\n' + cls.invitation.personal_message + '\n\n'
-
+            email_text += cls.invitation.first_name
+        email_text +=  ',\n\n' + cls.invitation.personal_message + '\n\n'
         email_text += ('You will have noticed that the world of scientific publishing is currently undergoing many changes, but you will ll perhaps agree that it is not completely clear that the best interests of science and scientists are being served. In recent times, and after much thinking of how best to address this issue, I have decided to forge ahead and implement a new online publication portal by and for scientists.\n\nThe initiative, called SciPost, can in a sense be viewed as an extra layer on arXiv.org. To summarize, SciPost will be a complete scientific publication platform, run by and for professional scientists, providing:\n\n' +
                        '- a means to comment on all existing literature\n\n' +
                        '- a repository of links to theses (Habilitation, PhD, Master’s)\n\n' +
diff --git a/scipost/views.py b/scipost/views.py
index ad1f667a3..3b6717125 100644
--- a/scipost/views.py
+++ b/scipost/views.py
@@ -207,6 +207,8 @@ def accept_invitation(request, key):
     elif invitation.responded:
         errormessage = 'This invitation token has already been used.'
     else:
+        invitation.reponded = True
+        invitation.save()
         form = RegistrationForm()
         form.fields['last_name'].initial = invitation.last_name
         form.fields['first_name'].initial = invitation.first_name
-- 
GitLab