From 48d8b7517ede5144d7fb0ccbf8befc0e9ca89f3d Mon Sep 17 00:00:00 2001
From: Tanner Prestegard <tanner.prestegard@ligo.org>
Date: Tue, 29 Nov 2016 11:00:01 -0600
Subject: [PATCH] Updating web interface for creating contacts and
 notifications.

---
 templates/profile/createNotification.html | 11 ---------
 templates/profile/notifications.html      | 29 ++++++++++++-----------
 userprofile/forms.py                      | 18 ++++++++++----
 userprofile/models.py                     |  2 +-
 4 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/templates/profile/createNotification.html b/templates/profile/createNotification.html
index 47dd161b2..2f6d11898 100644
--- a/templates/profile/createNotification.html
+++ b/templates/profile/createNotification.html
@@ -13,15 +13,4 @@
     <input type="submit" value="Submit"/>
 </form>
 
-{% if creating == 'Notification' %}
-<p> <b>NOTE:</b> 
-For the label query, label names can be combined with binary AND: '&amp;' or ','; or binary OR: '|'.
-For N labels, there must be exactly N-1 binary operators. (Parentheses are not
-allowed.) Additionally, any of the labels in a query string can be negated with
-'~' or '-'. Labels can either be selected with the select box at the top, or a query
-can be specified, <i>but not both</i>. 
-</p>
-
-{% endif %}
-
 {% endblock %}
diff --git a/templates/profile/notifications.html b/templates/profile/notifications.html
index 0b52410bd..00a86fbe2 100644
--- a/templates/profile/notifications.html
+++ b/templates/profile/notifications.html
@@ -1,24 +1,11 @@
 {% extends "base.html" %}
 
 {% block title %}Options | Notifications{% endblock %}
-{% block heading %}Notifications (LVC Users){% endblock %}
+{% block heading %}<!-- leave heading blank -->{% endblock %}
 {% block pageid %}userprofile{% endblock %}
 
 {% block content %}
 
-{% for trigger in triggers %}
-   <ul>
-     <li> 
-        <!-- <a href="{% url "userprofile-edit" trigger.id  %}">Edit</a> -->
-        <a href="{% url "userprofile-delete" trigger.id %}">Delete</a>
-        {{ trigger.userlessDisplay }}
-     </li>
-   </ul>
-{% endfor %}
-
-<a href="{% url "userprofile-create" %}">Create New Notification (LVC users)</a>
-<br/><br/>
-
 <h2>Contacts (LVC Users)</h2>
 {% for contact in contacts %}
     <ul>
@@ -33,6 +20,20 @@
 <a href="{% url "userprofile-create-contact" %}">Create New Contact</a>
 <br/><br/>
 
+<h2>Notifications (LVC Users)</h2>
+{% for trigger in triggers %}
+   <ul>
+     <li> 
+        <!-- <a href="{% url "userprofile-edit" trigger.id  %}">Edit</a> -->
+        <a href="{% url "userprofile-delete" trigger.id %}">Delete</a>
+        {{ trigger.userlessDisplay }}
+     </li>
+   </ul>
+{% endfor %}
+
+<a href="{% url "userprofile-create" %}">Create New Notification (LVC users)</a>
+<br/><br/>
+
 <h2>Passwords for Scripted Access (LV-EM users)</h2>
 
 <a href="{% url "userprofile-manage-password" %}">Manage Password</a>
diff --git a/userprofile/forms.py b/userprofile/forms.py
index 9d092e5f8..121e53c36 100644
--- a/userprofile/forms.py
+++ b/userprofile/forms.py
@@ -7,17 +7,21 @@ from gracedb.pyparsing import ParseException
 def triggerFormFactory(postdata=None, user=None):
     class TF(forms.ModelForm):
         farThresh = forms.FloatField(label='FAR Threshold (Hz)', required=False,
-                help_text="Leave blank to recieve all events, regardless of FAR.")
+                help_text="Leave blank to receive all events, regardless of FAR.")
         class Meta:
             model = Trigger
-            exclude = ['user', 'triggerType']
+            fields = ['contacts', 'pipelines', 'farThresh', 'labels', 'label_query']
             widgets = {'label_query': forms.TextInput(attrs={'size': 50})} 
 
+            help_texts = {
+               'label_query': 'Label names can be combined with binary AND: \'&amp;\' or \',\'; or binary OR: \'|\'. For N labels, there must be exactly N-1 binary operators. Parentheses are not allowed. Additionally, any of the labels in a query string can be negated with \'~\' or \'-\'. Labels can either be selected with the select box at the top, or a query can be specified, <i>but not both</i>.'
+            }
+
         contacts = forms.ModelMultipleChoiceField(
                         queryset=Contact.objects.filter(user=user),
-                        required=False
-                        )
-
+                        required=False,
+                        help_text="If blank, go back and create a Contact first.")
+    
         # XXX should probably override is_valid and check for
         # truth of (atypes or labels)
         # and set field error attributes appropriately.
@@ -38,12 +42,16 @@ def triggerFormFactory(postdata=None, user=None):
     else:
         return TF()
 
+
+# 11/29/2016 (TP): pretty sure this is deprecated in favor of
+# triggerFormFactory; may remove at a later date.
 class TriggerForm(forms.ModelForm):
     class Meta:
         model = Trigger
         exclude = ['user', 'triggerType']
 
 class ContactForm(forms.ModelForm):
+    desc = forms.CharField(label='Description')
     class Meta:
         model = Contact
         fields = ['desc','email','phone']
diff --git a/userprofile/models.py b/userprofile/models.py
index f1c817ecf..015576b51 100644
--- a/userprofile/models.py
+++ b/userprofile/models.py
@@ -85,6 +85,6 @@ class Trigger(models.Model):
             "|".join([a.name for a in self.pipelines.all()]) or "any pipeline",
             label_disp,
             thresh,
-            ",".join([x.desc for x in self.contacts.all()])
+            ", ".join([x.desc for x in self.contacts.all()])
         )
 
-- 
GitLab