Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
flibbertigibbet committed Dec 5, 2017
2 parents 9089559 + 27f3660 commit 3fd70bb
Show file tree
Hide file tree
Showing 27 changed files with 669 additions and 317 deletions.
29 changes: 21 additions & 8 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,28 @@
Vagrant.require_version ">= 1.5"
require "yaml"

CAC_SHARED_FOLDER_TYPE = ENV.fetch("CAC_SHARED_FOLDER_TYPE", "nfs")
CAC_NFS_VERSION = ENV.fetch("CAC_NFS_VERSION_3", true) ? 'vers=3': 'vers=4'

if CAC_SHARED_FOLDER_TYPE == "nfs"
if Vagrant::Util::Platform.linux? then
CAC_MOUNT_OPTIONS = ['rw', CAC_NFS_VERSION, 'tcp', 'nolock']
else
CAC_MOUNT_OPTIONS = [CAC_NFS_VERSION, 'udp']
end
else
if ENV.has_key?("CAC_MOUNT_OPTIONS")
CAC_MOUNT_OPTIONS = ENV.fetch("CAC_MOUNT_OPTIONS").split
else
CAC_MOUNT_OPTIONS = ["rw"]
end
end

if ENV['CAC_TRIPPLANNER_MEMORY'].nil?
# OpenTripPlanner needs > 1GB to build and run
OTP_MEMORY_MB = "4096"
CAC_MEMORY_MB = "4096"
else
OTP_MEMORY_MB = ENV['CAC_TRIPPLANNER_MEMORY']
CAC_MEMORY_MB = ENV['CAC_TRIPPLANNER_MEMORY']
end

if ENV['CAC_TRIPPLANNER_CPU'].nil?
Expand Down Expand Up @@ -118,11 +135,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if testing?
app.vm.synced_folder ".", "/opt/app"
else
app.vm.synced_folder ".", "/opt/app", :nfs => true, :mount_options => [
("nfsvers=3" if ENV.fetch("CAC_NFS_VERSION_3", false)),
"noatime",
"actimeo=1",
]
app.vm.synced_folder ".", "/opt/app", type: CAC_SHARED_FOLDER_TYPE, mount_options: CAC_MOUNT_OPTIONS
end

# Web
Expand Down Expand Up @@ -170,7 +183,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
end

otp.vm.provider :virtualbox do |v|
v.memory = OTP_MEMORY_MB
v.memory = CAC_MEMORY_MB
v.cpus = CPUS
end
end
Expand Down
11 changes: 4 additions & 7 deletions deployment/ansible/roles/cac-tripplanner.app/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,24 @@ production: False
app_sass_version: "3.4.22"

app_log: "/var/log/cac-tripplanner-app.log"
app_cron_event_feed_log: "/var/log/event-feed.log"

root_app_dir: "/opt/app/python/cac_tripplanner"
root_conf_dir: "/etc/cac_tripplanner.d"
root_src_dir: "/opt/app/src"
root_static_dir: "/srv/cac"
root_media_dir: "/media/cac"

app_cron_event_feed: "cd {{ root_app_dir }} && python manage.py load_events >> {{ app_cron_event_feed_log }} 2>&1"

cac_python_dependencies:
- { name: 'base58', version: '0.2.5' }
- { name: 'boto', version: '2.48.0' }
- { name: 'django', version: '1.8.18' }
- { name: 'django-ckeditor', version: '5.3.0' }
- { name: 'django-extensions', version: '1.9.1' }
- { name: 'django', version: '1.11.7' }
- { name: 'django-ckeditor', version: '5.3.1' }
- { name: 'django-extensions', version: '1.9.7' }
- { name: 'django-storages', version: '1.6.5' }
- { name: 'gunicorn', version: '19.7.1' }
- { name: 'pillow', version: '4.3.0' }
- { name: 'psycopg2', version: '2.7.3' }
- { name: 'pytz', version: '2017.2' }
- { name: 'pytz', version: '2017.3' }
- { name: 'pyyaml', version: '3.12' }
- { name: 'troposphere', version: '0.7.2'}
# Note: django-wpadmin is installed manually to work around the fact that ansible-pip
Expand Down
14 changes: 2 additions & 12 deletions deployment/ansible/roles/cac-tripplanner.app/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
# Putting 'editable: false' in the entry in cac_python_dependencies should make it install
# non-editable, but it's getting ignored
- name: Install django-wpadmin manually to work around ansible bug
command: pip install 'git+https://github.com/azavea/django-wpadmin@v1.8.13#egg=django-wpadmin'
command: pip install --upgrade 'git+https://github.com/azavea/django-wpadmin@v1.11#egg=django-wpadmin'

# TODO: #914 replace major kirby
# TODO: peg this to a version, rather than a commit, when released
# ansible pip module installs this in /tmp/src for some reason, so we use the
# command instead
Expand Down Expand Up @@ -77,17 +78,6 @@
template: src=nginx-default.j2 dest=/etc/nginx/sites-available/default
notify: Restart nginx

- name: Touch cron job log file if it does not exist
copy: content="" dest="{{ app_cron_event_feed_log }}" force=no

- name: Touch cron job log file if it does not exist, and set permissions
file: path={{ app_cron_event_feed_log}} state=touch
owner={{ app_username }} group={{ app_username }} mode=0664

# TODO: Add logic in production to only run on a single webserver
- name: Add cron job for RSS events feed
cron: name="Load event feed" minute="45" user="{{ app_username }}" job="{{ app_cron_event_feed }}"

- { include: jslibs.yml }

- { include: dev-test-dependencies.yml, when: develop or test }
14 changes: 10 additions & 4 deletions python/cac_tripplanner/cac_tripplanner/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
import django

from boto.utils import get_instance_metadata
from django.core.exceptions import ImproperlyConfigured
Expand Down Expand Up @@ -223,12 +224,20 @@
}

# TEMPLATE CONFIGURATION
# See https://docs.djangoproject.com/en/1.8/ref/settings/#templates
# See https://docs.djangoproject.com/en/1.11/ref/settings/#templates

# set renderer
# https://docs.djangoproject.com/en/1.11/ref/forms/renderers/#django.forms.renderers.TemplatesSetting
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.normpath(os.path.join(BASE_DIR, 'templates')),
'django/forms/templates',
'templates',
os.path.normpath(os.path.join(django.__path__[0] + '/forms/templates'))
],
'APP_DIRS': True,
'OPTIONS': {
Expand All @@ -250,9 +259,6 @@
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_IMAGE_BACKEND = 'pillow'

# TODO: delete later.
CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'

CKEDITOR_CONFIGS = {
'default': {
'toolbar': [
Expand Down
4 changes: 2 additions & 2 deletions python/cac_tripplanner/cac_tripplanner/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUp(self):
address='123 Test ln.',
city='Gotham',
state='Euphoria',
zip='12345',
zipcode='12345',
published=True
)
Destination.objects.create(
Expand All @@ -40,7 +40,7 @@ def setUp(self):
address='123 Test ln.',
city='Thangorodrim',
state='Angband',
zip='12349',
zipcode='12349',
published=True
)

Expand Down
4 changes: 0 additions & 4 deletions python/cac_tripplanner/cac_tripplanner/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@
# Map
url(r'^api/destinations/search$', dest_views.SearchDestinations.as_view(),
name='api_destinations_search'),
url(r'^api/feedevents$', dest_views.FeedEvents.as_view(), name='api_feedevents'),
url(r'^map/reachable$', dest_views.FindReachableDestinations.as_view(), name='reachable'),

# print directions view. TODO: update or delete
# url(r'^directions/', dest_views.directions, name='directions'),

# Handle pre-redesign URLs by redirecting
url(r'^(?:map/)?directions/', RedirectView.as_view(pattern_name='home', query_string=True,
permanent=True)),
Expand Down
1 change: 1 addition & 0 deletions python/cac_tripplanner/destinations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'destinations.apps.DestinationsConfig'
33 changes: 23 additions & 10 deletions python/cac_tripplanner/destinations/admin.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from django.conf import settings
from django.contrib.gis import admin
from django.contrib import admin, gis

from .forms import DestinationForm
from .models import Destination
from .forms import DestinationForm, EventForm
from .models import Destination, Event


class DestinationAdmin(admin.OSMGeoAdmin):
class DestinationAdmin(gis.admin.OSMGeoAdmin):
form = DestinationForm

list_display = ('name', 'published', 'priority', 'address', 'city', 'state', 'zip')
list_display = ('name', 'published', 'priority', 'address', 'city', 'state', 'zipcode')
actions = ('make_published', 'make_unpublished')
ordering = ('name', )

Expand All @@ -18,12 +18,8 @@ class DestinationAdmin(admin.OSMGeoAdmin):
# Override map_template for custom address geocoding behavior
map_template = 'admin/cac-geocoding-map.html'

# Override configurable URL for openlayers.js to support SSL
# default is: 'http://openlayers.org/api/2.13.1/OpenLayers.js'
openlayers_url = 'https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.js'

# Include geocoder dependencies
jquery = 'https://code.jquery.com/jquery-2.1.3.min.js'
jquery = 'https://code.jquery.com/jquery-3.2.1.min.js'
if settings.DEBUG:
extra_js = [
jquery,
Expand All @@ -48,4 +44,21 @@ def make_unpublished(self, request, queryset):
make_unpublished.short_description = 'Unpublish selected destinations'


class EventAdmin(admin.ModelAdmin):
form = EventForm

list_display = ('name', 'published', 'priority', )
actions = ('make_published', 'make_unpublished', )
ordering = ('name', )

def make_published(self, request, queryset):
queryset.update(published=True)
make_published.short_description = 'Publish selected events'

def make_unpublished(self, request, queryset):
queryset.update(published=False)
make_unpublished.short_description = 'Unpublish selected events'


admin.site.register(Destination, DestinationAdmin)
admin.site.register(Event, EventAdmin)
5 changes: 5 additions & 0 deletions python/cac_tripplanner/destinations/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig

class DestinationsConfig(AppConfig):
name = 'destinations'
verbose_name = 'Destinations and Events'
33 changes: 31 additions & 2 deletions python/cac_tripplanner/destinations/forms.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.forms import ModelForm
from django.forms import ModelForm, ValidationError

from .models import Destination
from .models import Destination, Event
from cac_tripplanner.image_utils import validate_image


class DestinationForm(ModelForm):
"""Validate image dimensions"""

class Meta:
model = Destination
exclude = []
Expand All @@ -17,3 +18,31 @@ def clean_image(self):
def clean_wide_image(self):
"""Custom validator for wide_image field"""
return validate_image(self.cleaned_data.get('wide_image', False), 680, 400)


class EventForm(DestinationForm):
"""Admin form for editing events
Subclasses destination form for image validation.
"""

class Meta:
model = Event
exclude = []

def __init__(self, *args, **kwargs):
super(EventForm, self).__init__(*args, **kwargs)
self.fields['destination'].widget.can_delete_related = False
self.fields['destination'].widget.can_add_related = False
self.fields['destination'].widget.can_change_related = False

def clean(self):
"""Validate start date is less than end date"""
cleaned_data = super(EventForm, self).clean()
start = self.cleaned_data.get('start_date')
end = self.cleaned_data.get('end_date')

if start and end and start >= end:
self.add_error('start_date', ValidationError('Start date must be before end date.'))

return cleaned_data
Loading

0 comments on commit 3fd70bb

Please sign in to comment.