From a6a687992bd04faea729db01fffc78b68554bee4 Mon Sep 17 00:00:00 2001
From: Tanner Prestegard <tanner.prestegard@ligo.org>
Date: Tue, 5 Feb 2019 21:09:45 -0600
Subject: [PATCH] Add playground instance changes into master

The settings for gracedb-playground are no longer on a separate
branch and are just included in master. They can be selected
simply by settings the DJANGO_SETTINGS_MODULE environment variable
appropriately.  This should be much easier to maintain than a
completely separate branch.
---
 config/settings/vm/playground.py     | 50 ++++++++++++++++++++++++++++
 gracedb/core/context_processors.py   |  3 +-
 gracedb/events/views.py              |  6 ++++
 gracedb/templates/gracedb/index.html | 36 ++++++++++----------
 4 files changed, 77 insertions(+), 18 deletions(-)
 create mode 100644 config/settings/vm/playground.py

diff --git a/config/settings/vm/playground.py b/config/settings/vm/playground.py
new file mode 100644
index 000000000..b2cf7dc85
--- /dev/null
+++ b/config/settings/vm/playground.py
@@ -0,0 +1,50 @@
+# Settings for a playground GraceDB instance (for user testing) running
+# on a VM with Puppet provisioning. Starts with vm.py settings (which inherits
+# from base.py settings) and overrides or adds to them.
+import textwrap
+from .base import *
+
+CONFIG_NAME = "USER TESTING"
+
+# Debug settings
+DEBUG = False
+
+# Override EMBB email address
+# TP (8 Aug 2017): not sure why?
+EMBB_MAIL_ADDRESS = 'gracedb@{fqdn}'.format(fqdn=SERVER_FQDN)
+
+# Turn on XMPP alerts
+SEND_XMPP_ALERTS = True
+
+# Enforce that phone and email alerts are off
+SEND_PHONE_ALERTS = False
+SEND_EMAIL_ALERTS = False
+
+# Define correct LVAlert settings
+LVALERT_OVERSEER_INSTANCES = [
+    {
+        "lvalert_server": "lvalert-playground.cgca.uwm.edu",
+        "listen_port": 8001,
+    },
+]
+
+# Add testserver to ALLOWED_HOSTS
+ALLOWED_HOSTS += ['testserver']
+
+# Home page stuff
+INSTANCE_TITLE = 'GraceDB Playground'
+INSTANCE_INFO = """
+<p>
+This GraceDB instance is designed for users to develop and test their own
+applications. It mimics the production instance in all but the following ways:
+</p>
+<ul>
+<li>Phone and e-mail alerts are turned off</li>
+<li>Only LIGO logins are provided (no login via InCommon or Google)</li>
+<li>LVAlert messages are sent to lvalert-playground.cgca.uwm.edu</li>
+<li>Events and associated data will <b>not</b> be preserved indefinitely.
+A nightly cron job removes events older than 14 days.</li>
+<li><b>Note:</b> for O3 development, the above number has been updated to
+<b>112</b>.</li>
+</ul>
+"""
diff --git a/gracedb/core/context_processors.py b/gracedb/core/context_processors.py
index afac66599..24341bdeb 100644
--- a/gracedb/core/context_processors.py
+++ b/gracedb/core/context_processors.py
@@ -1,6 +1,7 @@
 from django.conf import settings
 
+
 def LigoDebugContext(request):
-    if settings.DEBUG and hasattr(settings, 'CONFIG_NAME'):
+    if hasattr(settings, 'CONFIG_NAME'):
         return { 'config_name': settings.CONFIG_NAME }
     return {}
diff --git a/gracedb/events/views.py b/gracedb/events/views.py
index a9df57da6..7c7f59d00 100644
--- a/gracedb/events/views.py
+++ b/gracedb/events/views.py
@@ -131,6 +131,12 @@ def index(request):
         except Exception, e:
             pass
     context['recent_events'] = recent_events
+
+    # Main heading
+    context['title'] = getattr(settings, 'INSTANCE_TITLE', None)
+
+    # Informational text
+    context['information'] = getattr(settings, 'INSTANCE_INFO', None)
     
     return render(request, 'gracedb/index.html', context=context)
 
diff --git a/gracedb/templates/gracedb/index.html b/gracedb/templates/gracedb/index.html
index ad01b2e27..f991d63a4 100644
--- a/gracedb/templates/gracedb/index.html
+++ b/gracedb/templates/gracedb/index.html
@@ -67,26 +67,28 @@ body {
 <!-- I find myself needing some more space. -->
 <!-- <br/>  -->
 
-<h2>GraceDB Overview</h2>
+<h2>
+{% if title %}
+    {{ title }}
+{% else %}
+    GraceDB Overview
+{% endif %}
+</h2>
 
 <div class="text">
 
-<p> The gravitational-wave candidate event database (GraceDB) is a
-prototype system to organize candidate events from gravitational-wave
-searches and to provide an environment to record information about
-follow-ups. </p>
-
-<ul>
-
-<!-- <li><a href="https://www.lsc-group.phys.uwm.edu/daswg/wiki/GraceDBER6">Recent changes</a> <font color="red">(IMPORTANT!) </font></li> -->
-<!-- <li><a href="https://gw-astronomy.org/wiki/LV_EM/ElectroMagneticBulletinBoard">Prototype EMBB description</a></li> -->
-<li><a href="https://wiki.ligo.org/Computing/GraceDB">Project page on wiki.ligo.org</a></li>
-<li><a href="{% url "legacy_apiweb:default:root" %}">Browseable REST API</a>
-<li><a href="https://gw-astronomy.org/wiki/LV_EM/TechInfo">LV-EM Technical Info</a></li>
-<li><a href="https://dcc.ligo.org/G1501296">Tutorial for operators and detector engineers</a></li>
-
-</ul>
-
+{# Can customize main informational display on home page or just use default #}
+{% if information %}
+    {{ information|safe }}
+{% else %}
+    <p>The gravitational-wave candidate event database (GraceDB) is a prototype system to organize candidate events from gravitational-wave searches and to provide an environment to record information about follow-ups.</p>
+    <ul>
+    <li><a href="https://wiki.ligo.org/Computing/GraceDB">Project page on wiki.ligo.org</a></li>
+    <li><a href="{% url "legacy_apiweb:default:root" %}">Browseable REST API</a>
+    <li><a href="https://gw-astronomy.org/wiki/LV_EM/TechInfo">LV-EM Technical Info</a></li>
+    <li><a href="https://dcc.ligo.org/G1501296">Tutorial for operators and detector engineers</a></li>
+    </ul>
+{% endif %}
 </div>
 
 <!--XXX Infrastructure for human signoffs. Hopefully this will not be permanent. -->
-- 
GitLab