Skip to content

Commit

Permalink
Merge branch 'master' into python3
Browse files Browse the repository at this point in the history
  • Loading branch information
rloomans committed Jan 30, 2017
2 parents e3dce23 + dfbb970 commit 6a7f002
Show file tree
Hide file tree
Showing 27 changed files with 489 additions and 236 deletions.
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ gunicorn==19.6.0
py-bcrypt==0.4
psycopg2==2.6.2
pytz==2016.10
requests==2.12.5
requests==2.13.0
static==1.1.1
whitenoise==3.2.3
whitenoise==3.3.0
urllib3[secure]==1.20
future==0.16.0
9 changes: 9 additions & 0 deletions teamtemp/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ def inner(request, *args, **kwargs):

def x_ua_compatible(ie):
return header('X-UA-Compatible', ie)

def ie_edge():
return x_ua_compatible('IE=edge')

def cache_control(control):
return header('Cache-Control', control)

def no_cache():
return cache_control('no-cache')
42 changes: 27 additions & 15 deletions teamtemp/responses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,50 @@


def get_userid(request):
if USER_ID_KEY in request.session:
return request.session[USER_ID_KEY]
session = request.session
if USER_ID_KEY not in session:
session[USER_ID_KEY] = None
session.save()

return None
return session[USER_ID_KEY]


def set_userid(request, value):
request.session[USER_ID_KEY] = value
return request.session[USER_ID_KEY]
session = request.session
session[USER_ID_KEY] = value

return session[USER_ID_KEY]


def create_userid(request):
request.session[USER_ID_KEY] = utils.random_string(32)
return request.session[USER_ID_KEY]
session = request.session
session[USER_ID_KEY] = utils.random_string(32)

session.save()

return session[USER_ID_KEY]


def get_admin_for_surveys(request):
if ADMIN_KEY in request.session:
return set(request.session[ADMIN_KEY])
session = request.session
if ADMIN_KEY not in session:
session[ADMIN_KEY] = []
session.save()

return set()
return session[ADMIN_KEY]


def add_admin_for_survey(request, survey_id):
admin_for_surveys_set = get_admin_for_surveys(request)
admin_for_surveys_set = set(get_admin_for_surveys(request))

admin_for_surveys_set.add(survey_id)

request.session[ADMIN_KEY] = list(admin_for_surveys_set)
session = request.session
session[ADMIN_KEY] = list(admin_for_surveys_set)
session.save()

return admin_for_surveys_set
return session[ADMIN_KEY]


def is_admin_for_survey(request, survey_id):
admin_for_surveys_set = get_admin_for_surveys(request) or set()
return survey_id in admin_for_surveys_set
return survey_id in get_admin_for_surveys(request)
2 changes: 1 addition & 1 deletion teamtemp/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
CSP_CONNECT_SRC = ("'self'",)
CSP_STYLE_SRC = (
'*.google.com', '*.googleapis.com', 'code.jquery.com', 'maxcdn.bootstrapcdn.com', "'unsafe-inline'", "'self'",)
CSP_IMG_SRC = ("'self'", 'data:', 'blob:',)
CSP_IMG_SRC = ("'self'", 'data:', 'blob:', 'gg.google.com',)
CSP_FONT_SRC = ('maxcdn.bootstrapcdn.com', "'self'",)

REST_FRAMEWORK = {
Expand Down
13 changes: 2 additions & 11 deletions teamtemp/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ ul {
display: none;
}

.google-visualization-tooltip {
top: -125px !important;
left: 200px !important;
margin: 500px 0 0 0 !important;
text-align: center !important;
padding: 2px !important;
font: 12px sans-serif !important;
border: 0 !important;
border-radius: 0 !important;
pointer-events: none !important;
box-shadow: none !important;
.google-visualization-tooltip-item {
white-space: nowrap;
}
2 changes: 1 addition & 1 deletion teamtemp/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

{% block bootstrap3_content %}
{# Display django.contrib.messages as Bootstrap alerts #}
{% autoescape off %}{% bootstrap_messages %}{% endautoescape %}
{% autoescape off %}<div class="container">{% bootstrap_messages %}</div>{% endautoescape %}
{% block body %}{% endblock %}
{% block footer %}
<div class="footer no-print"><p><br><br><a href="{% url "about" %}">About this site</a></p></div>{% endblock %}
Expand Down
55 changes: 25 additions & 30 deletions teamtemp/templates/bvc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

{% load bootstrap3 %}

{% block title %}Results {{ bvc_data.survey_id }} {{ bvc_data.team_name }}{% endblock %}
{% block title %}Results {{ survey.id }} {{ bvc_data.team_name }}{% endblock %}

{% block bootstrap3_extra_script %}
<script type='text/javascript' src="//www.google.com/jsapi"></script>
<script type='text/javascript'>

google.load('visualization', '1', {packages: ['gauge', 'annotationchart', 'corechart']});
google.setOnLoadCallback(drawGaugeChart);

function drawGaugeChart() {

<!-- Team Temp Gauge -->
Expand Down Expand Up @@ -70,14 +71,14 @@
<div class="no-print">
<BR>
<div class="btn-group" role="group" aria-label="nav">
<a href="{% url 'admin' survey_id=bvc_data.survey_id %}" class="btn btn-info"
<a href="{% url 'admin' survey_id=survey.id %}" class="btn btn-info"
role="button">ADMIN</a>
{% if bvc_data.team_name != '' or bvc_data.dept_names != '' or bvc_data.region_names != '' or bvc_data.site_names != '' %}
{% if bvc_data.archive_id == '' %}
<a href="{% url 'bvc' survey_id=bvc_data.survey_id %}" class="btn btn-primary" role="button">ALL
<a href="{% url 'bvc' survey_id=survey.id %}" class="btn btn-primary" role="button">ALL
TEAMS</a>
{% else %}
<a href="{% url 'bvc' survey_id=bvc_data.survey_id archive_id=bvc_data.archive_id %}" class="btn btn-primary" role="button">ALL
<a href="{% url 'bvc' survey_id=survey.id archive_id=bvc_data.archive_id %}" class="btn btn-primary" role="button">ALL
TEAMS</a>
{% endif %}
{% endif %}
Expand All @@ -98,7 +99,7 @@
</div>
</div>

{% if bvc_data.team_name == '' and bvc_data.archive_id == '' and bvc_data.survey_type == 'DEPT-REGION-SITE' %}
{% if bvc_data.team_name == '' and bvc_data.archive_id == '' and survey.survey_type == 'DEPT-REGION-SITE' %}

<!-- Filter BVC by Dept, Region, Site -->

Expand Down Expand Up @@ -157,48 +158,42 @@

<select class="btn btn-default" id="ArchivedBVCSelector">
{% if bvc_data.team_name != '' %}
<option value="{% url 'bvc' survey_id=bvc_data.survey_id team_name=bvc_data.team_name %}">
<option value="{% url 'bvc' survey_id=survey.id team_name=bvc_data.team_name %}" {% if bvc_data.archive_id == '' %}selected{% endif %}>
Current Survey
</option>
{% else %}
{% if bvc_data.dept_names != '' or bvc_data.region_names != '' or bvc_data.site_names != '' %}
<option
value="{% url 'bvc' survey_id=bvc_data.survey_id dept_names=bvc_data.dept_names region_names=bvc_data.region_names site_names=bvc_data.site_names %}">
value="{% url 'bvc' survey_id=survey.id dept_names=bvc_data.dept_names region_names=bvc_data.region_names site_names=bvc_data.site_names %}"
{% if bvc_data.archive_id == '' %}selected{% endif %}>
Current Survey
</option>
{% else %}
<option value="{% url 'bvc' survey_id=bvc_data.survey_id %}">Current Survey</option>
<option value="{% url 'bvc' survey_id=survey.id %}" {% if bvc_data.archive_id == '' %}selected{% endif %}>
Current Survey
</option>
{% endif %}
{% endif %}

<script>
document.getElementById("ArchivedBVCSelector").selectedIndex = document.getElementById("ArchivedBVCSelector").length - 1;
</script>

{% for date in bvc_data.archived_dates %}
{% if bvc_data.team_name == '' %}
{% if bvc_data.dept_names != '' or bvc_data.region_names != '' or bvc_data.site_names != '' %}
<option
value="{% url 'bvc' survey_id=bvc_data.survey_id archive_id=date.id dept_names=bvc_data.dept_names region_names=bvc_data.region_names site_names=bvc_data.site_names %}">
value="{% url 'bvc' survey_id=survey.id archive_id=date.id dept_names=bvc_data.dept_names region_names=bvc_data.region_names site_names=bvc_data.site_names %}"
{% if date.id|slugify == bvc_data.archive_id %}selected{% endif %}>
{{ date.archive_date|date:"M. d, Y" }}</option>
{% else %}
<option value="{% url 'bvc' survey_id=bvc_data.survey_id archive_id=date.id %}">
<option value="{% url 'bvc' survey_id=survey.id archive_id=date.id %}"
{% if date.id|slugify == bvc_data.archive_id %}selected{% endif %}>
{{ date.archive_date|date:"M. d, Y" }}</option>
{% endif %}
{% else %}
<option
value="{% url 'bvc' survey_id=bvc_data.survey_id team_name=bvc_data.team_name archive_id=date.id %}">
value="{% url 'bvc' survey_id=survey.id team_name=bvc_data.team_name archive_id=date.id %}"
{% if date.id|slugify == bvc_data.archive_id %}selected{% endif %}>
{{ date.archive_date|date:"M. d, Y" }}</option>
{% endif %}

{% if date.id|slugify == bvc_data.archive_id %}
<script>
document.getElementById("ArchivedBVCSelector").selectedIndex = document.getElementById("ArchivedBVCSelector").length - 1;
</script>
{% endif %}

{% endfor %}

</select>

<script>
Expand All @@ -207,7 +202,6 @@
};
</script>
</div>

{% endif %}
</div>
<div class="row">
Expand All @@ -222,21 +216,20 @@ <h2 align="center">{% now () %}</h2>
<div class="no-print">
{% if num_iterations != '0' %}
{% if bvc_data.team_name == '' %}
<h6 align="center"><a href="{% url 'bvc' survey_id=bvc_data.survey_id %}">Current Results
<h6 align="center"><a href="{% url 'bvc' survey_id=survey.id %}">Current Results
+ {{ num_iterations }} Previous Iterations</a></h6>
{% else %}
<h6 align="center"><a
href="{% url 'bvc' survey_id=bvc_data.survey_id team_name=bvc_data.team_name %}">Current
<h6 align="center"><a href="{% url 'bvc' survey_id=survey.id team_name=bvc_data.team_name %}">Current
Results + {{ num_iterations }} Previous Iterations</a></h6>
{% endif %}
{% else %}
{% if bvc_data.team_name == '' %}
<h6 align="center"><a
href="{% url 'bvc' survey_id=bvc_data.survey_id num_iterations='2' %}">Current
href="{% url 'bvc' survey_id=survey.id num_iterations='2' %}">Current
Results</a></h6>
{% else %}
<h6 align="center"><a
href="{% url 'bvc' survey_id=bvc_data.survey_id team_name=bvc_data.team_name num_iterations='2' %}">Current
href="{% url 'bvc' survey_id=survey.id team_name=bvc_data.team_name num_iterations='2' %}">Current
Results</a></h6>
{% endif %}
{% endif %}
Expand All @@ -256,6 +249,7 @@ <h3 align="center">{{ bvc_data.stats.count }} Responses:</h3>
</div>
</div>
</div>
{% if bvc_data.num_rows > 0 %}
<div class="row">
<!-- History Trend Graphs -->
<h1 align="center">{{ bvc_data.pretty_team_name }}</h1>
Expand All @@ -264,8 +258,9 @@ <h1 align="center">Historical {{ bvc_data.survey_type_title }}</h1>
<h2 align="center">{% now () %}</h2>
<p>
<div class="centregauge" id="table_div_jscode" style="width: 100%"></div>
<BR><BR><BR><BR><BR><BR><BR>
<BR><BR>
<div class="centregauge" id="table_div_json" style="width: 100%"></div>
</div>
{% endif %}
</div>
{% endblock %}
3 changes: 0 additions & 3 deletions teamtemp/templates/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ <h2>Submit your {{ survey_type_title }}</h2>
{% bootstrap_button "Submit" button_type="submit" button_class="btn-primary" %}
{% endbuttons %}
</form>
{% if thanks %}
<div class="info box">{{ thanks }}</div>
{% endif %}
</div>
</div>
</div>
Expand Down
5 changes: 0 additions & 5 deletions teamtemp/templates/set.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

<div class="container">

{% if thanks %}
<div class="info box">{{ thanks }}</div>
<BR><BR>
{% endif %}

<div class="row">
<div class="col-md-12"><br>
<BR>
Expand Down
9 changes: 3 additions & 6 deletions teamtemp/tests/models/test_team_temperature.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from builtins import str
import re

from django.forms import ValidationError
from django.test import TestCase

Expand Down Expand Up @@ -31,9 +30,7 @@ def test_customer_feedback(self):
self.assertEqual(teamtemp.survey_type, 'CUSTOMERFEEDBACK')

def test_uniq_teamtemp_ids(self):
teamtemp1 = TeamTemperatureFactory()
teamtemp2 = TeamTemperatureFactory()
self.assertNotEqual(teamtemp1.id, teamtemp2.id)
self.assertNotEqual(TeamTemperatureFactory().id, TeamTemperatureFactory().id)

def test_multiple_surveys_for_user(self):
user = UserFactory()
Expand All @@ -45,5 +42,5 @@ def test_multiple_surveys_for_user(self):

def test_duplicate_teamtemp_ids(self):
with self.assertRaises(ValidationError):
_ = TeamTemperatureFactory(id='bob')
_ = TeamTemperatureFactory(id='bob')
TeamTemperatureFactory(id='bob')
TeamTemperatureFactory(id='bob')
9 changes: 4 additions & 5 deletions teamtemp/tests/models/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def test_pretty_team_name(self):
self.assertEqual(team.pretty_team_name(), 'bob and his friends')

def test_uniq_team_names(self):
team1 = TeamFactory()
team2 = TeamFactory()
self.assertNotEqual(team1.team_name, team2.team_name)
self.assertNotEqual(TeamFactory().team_name, TeamFactory().team_name)

def test_multiple_surveys_for_user(self):
teamtemp = TeamTemperatureFactory()
Expand All @@ -33,10 +31,11 @@ def test_multiple_surveys_for_user(self):
def test_duplicate_team_names(self):
teamtemp = TeamTemperatureFactory()
with self.assertRaises(ValidationError):
_ = TeamFactory(team_name='bob', request=teamtemp)
_ = TeamFactory(team_name='bob', request=teamtemp)
TeamFactory(team_name='bob', request=teamtemp)
TeamFactory(team_name='bob', request=teamtemp)

def test_duplicate_team_names_for_different_requests(self):
team1 = TeamFactory(team_name='bob')
team2 = TeamFactory(team_name='bob')
self.assertNotEqual(team1.request.id, team2.request.id)
self.assertEqual(team1.team_name, team2.team_name)

0 comments on commit 6a7f002

Please sign in to comment.