Skip to content

Commit

Permalink
add select_related to cert table
Browse files Browse the repository at this point in the history
  • Loading branch information
Russ Marshall committed Jun 27, 2019
1 parent 2618dbb commit ffaae87
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions requirements.txt
@@ -1,5 +1,6 @@
Django==2.1.*
django-crispy-forms
django-debug-toolbar
django-recaptcha
django-s3-storage
django-tables2
Expand Down
Binary file removed sail_lanier/phrf/static/phrf/PHRFApplication.docx
Binary file not shown.
8 changes: 4 additions & 4 deletions sail_lanier/phrf/templates/phrf/documents.html
@@ -1,9 +1,9 @@
{% extends "phrf/base.html" %}
{% load static %}
{% block content %}
<p>
PHRF Application (PDF): <a href="http://phrf-lakelanier.com/Docs/PHRFApplication.pdf">PDF File</a><br/>
PHRF Application (Word): <a href="http://phrf-lakelanier.com/Docs/PHRFApplication.docx">Word File</a><br/>
PHRF Adjustments Document: <a href="http://phrf-lakelanier.com/Docs/LLPHRFadjustments.pdf">PDF File</a><br/>
PHRF Definitions Document: <a href="http://phrf-lakelanier.com/Docs/LLPHRF_Definitions.pdf">PDF File</a>
<a href="{% static "phrf/PHRFApplication.pdf" %}">PHRF Application</a><br/>
<a href="{% static "phrf/LLPHRFadjustments.pdf" %}">PHRF Adjustments Document</a><br/>
<a href="{% static "phrf/LLPHRF_Definitions.pdf" %}">PHRF Definitions Document</a>
</p>
{% endblock %}
12 changes: 6 additions & 6 deletions sail_lanier/phrf/views.py
@@ -1,4 +1,3 @@
from django.conf import settings
from django.core.mail import EmailMessage, BadHeaderError
from django.http import HttpResponse
from django.shortcuts import render, redirect
Expand All @@ -11,7 +10,8 @@


def index(request):
table = CertTable(Cert.valid.all().order_by("boat__owner__last_name", "boat__boat_name"))
table = CertTable(
Cert.valid.select_related("boat", "boat__owner").all().order_by("boat__owner__last_name", "boat__boat_name"))
RequestConfig(request, paginate=False).configure(table)
context = {"table": table, "nav_bar": "home"}
return render(request, "phrf/table.html", context=context)
Expand All @@ -28,17 +28,17 @@ def downloads(request):


def officers(request):
table = OfficerTable(Profile.officers.all())
table = OfficerTable(Profile.officers.select_related("user").all())
RequestConfig(request).configure(table)
context = {"table": table, "nav_bar": "officers"}
return render(request, "phrf/table.html", context=context)


def contact(request, user_id=app_settings.DEFAULT_USER_ID):
# the contact form should only allow contact with officers, not other users
user = Profile.officers.filter(user_id=user_id).first()
user = Profile.officers.filter(pk=user_id).first()
if user is None:
user = Profile.objects.get(user_id=app_settings.DEFAULT_USER_ID)
user = Profile.objects.get(pk=app_settings.DEFAULT_USER_ID)

if request.method == "GET":
form = ContactForm()
Expand All @@ -52,7 +52,7 @@ def contact(request, user_id=app_settings.DEFAULT_USER_ID):
try:
email = EmailMessage(subject, message,
"{name} <{email}>".format(name=name, email=app_settings.EMAIL_FROM),
[User.objects.get(id=user.user_id).email], reply_to=[from_email])
[User.objects.get(pk=user.user_id).email], reply_to=[from_email])
email.send()
except BadHeaderError:
return HttpResponse("Invalid header found.")
Expand Down
9 changes: 9 additions & 0 deletions sail_lanier/sail_lanier/settings/base.py
Expand Up @@ -37,13 +37,15 @@
'django.contrib.staticfiles',
'django_s3_storage', # for static file storage on s3
'django_tables2', # fancy auto-tables
'debug_toolbar', # django-debug-toolbar
'captcha', # reCAPTCHA
'crispy_forms', # django-crispy-forms
'zappa_django_utils', # for sqlite s3 database
'phrf', # the phrf app
]

MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
Expand All @@ -52,6 +54,7 @@
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.common.BrokenLinkEmailsMiddleware',

]

ROOT_URLCONF = 'sail_lanier.urls'
Expand Down Expand Up @@ -132,3 +135,9 @@

# To use test keys for reCAPTCHA in development, do not use in production!
SILENCED_SYSTEM_CHECKS = ['captcha.recaptcha_test_key_error']

# for django-debug-toolbar
INTERNAL_IPS = [
'127.0.0.1',
'64.100.113.9',
]
8 changes: 8 additions & 0 deletions sail_lanier/sail_lanier/urls.py
@@ -1,3 +1,4 @@
from django.conf import settings
from django.contrib import admin
from django.urls import path, include
from django.views.generic.base import RedirectView
Expand All @@ -7,3 +8,10 @@
path('admin/', admin.site.urls),
path('phrf/', include("phrf.urls")),
]

if settings.DEBUG:
import debug_toolbar

urlpatterns = [
path('__debug__/', include(debug_toolbar.urls)),
] + urlpatterns

0 comments on commit ffaae87

Please sign in to comment.