Commit e09d69ef authored by David Haynes's avatar David Haynes 🙆

Merge branch '2.2-dev' into 78-alert-overhaul

parents db62a200 ea24b5f4
Pipeline #3721 passed with stage
in 1 minute and 4 seconds
......@@ -13,5 +13,4 @@ whats_open/secret_key.py
whats_open/assets/
static/admin/
data
whats-open/api/migrations
.vscode
......@@ -12,8 +12,9 @@ before_script:
- apt-get update -qy
- apt-get install -y mysql-client default-libmysqlclient-dev python-mysqldb
gdal-bin libproj-dev proj-data proj-bin binutils
- pip install -r requirements/test.txt
- cd whats-open/
- pip install pipenv
- pipenv install --system --deploy
- export WOPEN_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9"
| fold -w 60 | head -n1 2>/dev/null)
- export WOPEN_EMAIL_DOMAIN="@masonlive.gmu.edu"
......@@ -23,6 +24,7 @@ before_script:
- export WOPEN_DB_HOST="mysql"
- export WOPEN_DB_PORT=3306
- export WOPEN_SUPERUSER=admin
- export WOPEN_ENV=dev
- python manage.py makemigrations
- python manage.py makemigrations api
- python manage.py migrate
......@@ -30,18 +32,8 @@ before_script:
get_user_model(); User.objects.create_superuser('root',
'root@srct.gmu.edu', 'root') " | python manage.py shell
whats-open-py3.5:
image: library/python:3.5
whats-open-py3.7:
image: library/python:3.7
type: test
script:
- python manage.py test
whats-open-py3.6:
image: library/python:3.6
type: test
script:
# - if pip list --outdated --format=legacy | grep "Latest" | wc -l > 0; then echo "Please update your dependecies!" && pip list --outdated --format=legacy && exit 1; else exit 0; fi
- coverage run --source=api
--omit=*migrations/*,*admin.py,*__init__.py,*.pyc manage.py test
- coverage html -i && grep pc_cov htmlcov/index.html | egrep -o "[0-9]+\%"
| awk '{ print "covered " $1;}'
- echo "Done 😄"
......@@ -31,4 +31,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Special Schedules can start at a specific time on a date
[2.1.0]: https://git.gmu.edu/srct/whats-open/compare/2.0...2.1
[2.1.1]: https://git.gmu.edu/srct/whats-open/compare/2.1...2.1.1
\ No newline at end of file
[2.1.1]: https://git.gmu.edu/srct/whats-open/compare/2.1...2.1.1
This diff is collapsed.
......@@ -3,7 +3,7 @@
############################################################
# Set the base image to Ubuntu
FROM python:3.6
FROM python:3.7
ENV PYTHONUNBUFFERED 1
# Update the sources list and install all packages
......@@ -23,4 +23,5 @@ WORKDIR /whats-open/
ADD . /whats-open/
# Pip install all required dependecies
RUN pip install -r /whats-open/requirements/base.txt
RUN pip install pipenv
RUN pipenv install --system --deploy
\ No newline at end of file
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
black = "*"
pylint = "*"
pylint-django = "*"
[packages]
django-autoslug-iplweb = "*"
django-cas-client = "==1.3.0"
djangorestframework = "==3.7.7"
django-model-utils = "==3.0.0"
mysqlclient = "==1.3.12"
django-taggit = "==0.22.2"
django-taggit-serializer = "==0.1.5"
djangorestframework-gis = "==0.12.0"
django-filter = "==1.0.4"
django-crispy-forms = "==1.7.0"
coreapi = "==2.3.3"
urllib3 = "==1.22"
docutils = "==0.13.1"
gunicorn = "*"
Django = "<2.1,>=2.0"
Markdown = "==2.6.10"
[requires]
python_version = "3.7"
[pipenv]
allow_prereleases = true
This diff is collapsed.
......@@ -23,10 +23,11 @@ contribute, so if you are struggling, or just want to learn, then we are
willing to help.
Check out some of the other What's Open projects!
- https://git.gmu.edu/srct/whats-open-android
- https://git.gmu.edu/srct/whats-open-ios
- https://git.gmu.edu/srct/whats-open-web
- https://git.gmu.edu/srct/whats-open-alexa
- https://git.gmu.edu/srct/whats-open-android
- https://git.gmu.edu/srct/whats-open-ios
- https://git.gmu.edu/srct/whats-open-web
- https://git.gmu.edu/srct/whats-open-alexa
# Setup instructions for local development
......@@ -113,9 +114,9 @@ environments across machines.
Installing Docker on your system:
- For macOS: https://docs.docker.com/docker-for-mac/
- For Windows: https://docs.docker.com/docker-for-windows/
- For your specific \*nix distro: https://docs.docker.com/engine/installation/
- For macOS: https://docs.docker.com/docker-for-mac/
- For Windows: https://docs.docker.com/docker-for-windows/
- For your specific \*nix distro: https://docs.docker.com/engine/installation/
Additionally, you will need to install docker-compose: https://docs.docker.com/compose/install/
......@@ -148,9 +149,10 @@ pass: admin
Manual Setup involves all of the same steps as Docker, but just done manually.
First, install python, pip, and virtualenv on your system.
* `python` is the programming language used for Django, the web framework used by whats-open.
* `pip` is the python package manager.
* `virtualenv` allows you to isolate pip packages within virtual environments
- `python` is the programming language used for Django, the web framework used by whats-open.
- `pip` is the python package manager.
- `virtualenv` allows you to isolate pip packages within virtual environments
Open a terminal and run the following command:
......@@ -167,10 +169,10 @@ You will also need the following `gdal` packages for GeoDjango support:
```
sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
sudo apt update
sudo apt upgrade # if you already have gdal 1.11 installed
sudo apt install gdal-bin python-gdal python3-gdal # if you don't have gdal 1.11 already installed
```
sudo apt update
sudo apt upgrade # if you already have gdal 1.11 installed
sudo apt install gdal-bin python-gdal python3-gdal # if you don't have gdal 1.11 already installed
```
#### Database Setup
......@@ -216,18 +218,17 @@ Run:
GRANT ALL ON test_wopen.* TO 'wopen'@'localhost'; FLUSH PRIVILEGES;
When running test cases, django creates a test database so your 'real' database
doesn't get screwed up. This database is called 'test_' + whatever your normal
doesn't get screwed up. This database is called 'test\_' + whatever your normal
database is named. Note that for permissions it doesn't matter that this database
hasn't yet been created.
The .* is to grant access all tables in the database, and 'flush privileges'
The .\* is to grant access all tables in the database, and 'flush privileges'
reloads privileges to ensure that your user is ready to go.
Exit the mysql shell by typing:
exit
At this point we will need to set some environment variables.
If you are using bash then just copy paste the following into your terminal:
......
......@@ -3,17 +3,10 @@ version: "3"
services:
db:
image: mysql:5.7
deploy:
replicas: 1
restart_policy:
condition: on-failure
command:
mysqld --character-set-server=utf8mb4
command: mysqld --character-set-server=utf8mb4
--collation-server=utf8mb4_unicode_ci
ports:
- 3306
networks:
- wopen_net
- "3306:3306"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: wopen
......@@ -22,17 +15,9 @@ services:
api:
build: .
deploy:
replicas: 1
restart_policy:
condition: on-failure
ports:
- "8000:8000"
networks:
- wopen_net
command: /bin/bash ./startup.sh
volumes:
- .:/whats-open
command: ./docker-startup.sh
depends_on:
- db
environment:
......@@ -43,6 +28,4 @@ services:
- WOPEN_DB_HOST=db
- WOPEN_DB_PORT=3306
- WOPEN_SUPERUSER=admin
networks:
wopen_net:
- WOPEN_ENV="dev"
......@@ -6,7 +6,6 @@ done
export WOPEN_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null)
python whats-open/manage.py flush --no-input
python whats-open/manage.py makemigrations
python whats-open/manage.py makemigrations api
python whats-open/manage.py migrate
......
# This file is here because many Platforms as a Service look for
# requirements.txt in the root directory of a project.
-r requirements/production.txt
Django >= 2.0, < 2.1
django-autoslug-iplweb
django-cas-client==1.3.0
djangorestframework==3.7.7
django-model-utils==3.0.0
mysqlclient==1.3.12
setuptools==36.2.0
django-taggit==0.22.2
django-taggit-serializer==0.1.5
djangorestframework-gis==0.12.0
django-filter==1.0.4
django-crispy-forms==1.7.0
markdown==2.6.10
coreapi==2.3.3
urllib3==1.22
docutils==0.13.1
\ No newline at end of file
# Local development dependencies go here
-r test.txt
# Pro-tip: Try not to put anything here. There should be no dependency in
# production that isn't in development.
-r base.txt
gunicorn
\ No newline at end of file
# Test dependencies go here.
-r base.txt
coverage==4.4.1
This diff is collapsed.
This diff is collapsed.
......@@ -15,47 +15,63 @@ from .models import Category, Facility, Schedule, OpenTime, Location, Alert
from rest_framework import serializers
from taggit_serializer.serializers import TagListSerializerField
class AlertSerializer(serializers.ModelSerializer):
"""
"""
class Meta:
model = Alert
fields = '__all__'
fields = "__all__"
class CategorySerializer(serializers.ModelSerializer):
"""
"""
class Meta:
# Choose the model to be serialized
model = Category
# Serialize all of the fields
fields = '__all__'
fields = "__all__"
class LocationSerializer(serializers.ModelSerializer):
"""
Serializer for the Location model.
"""
class Meta:
# Choose the model to be serialized
model = Location
# Serialize all of the fields
fields = '__all__'
fields = "__all__"
class OpenTimeSerializer(serializers.ModelSerializer):
"""
Serializer for the OpenTime model.
"""
class Meta:
# Choose the model to be serialized
model = OpenTime
# Serialize all of the fields
fields = ('schedule', 'modified',
'start_day', 'end_day', 'start_time', 'end_time')
fields = (
"schedule",
"modified",
"start_day",
"end_day",
"start_time",
"end_time",
)
class ScheduleSerializer(serializers.ModelSerializer):
"""
Serializer for the Schedule model.
"""
# Append a serialized OpenTime object
open_times = OpenTimeSerializer(many=True, read_only=True)
......@@ -63,8 +79,18 @@ class ScheduleSerializer(serializers.ModelSerializer):
# Choose the model to be serialized
model = Schedule
# List the fields that we are serializing
fields = ('id', 'open_times', 'modified', 'name', 'valid_start',
'valid_end', 'twenty_four_hours', 'schedule_for_removal', 'promote_to_main')
fields = (
"id",
"open_times",
"modified",
"name",
"valid_start",
"valid_end",
"twenty_four_hours",
"schedule_for_removal",
"promote_to_main",
)
class FacilitySerializer(serializers.HyperlinkedModelSerializer):
"""
......@@ -76,6 +102,7 @@ class FacilitySerializer(serializers.HyperlinkedModelSerializer):
than primary keys.
http://www.django-rest-framework.org/api-guide/serializers/#hyperlinkedmodelserializer
"""
# Append serialized objects
facility_category = CategorySerializer(many=False, read_only=True)
facility_location = LocationSerializer(many=False, read_only=True)
......@@ -89,7 +116,19 @@ class FacilitySerializer(serializers.HyperlinkedModelSerializer):
# Choose the model to be serialized
model = Facility
# List the fields that we are serializing
fields = ('slug', 'facility_name', 'logo', 'facility_location',
'facility_category', 'phone_number', 'facility_product_tags',
'facility_labels', 'facility_classifier', 'tapingo_url',
'note', 'main_schedule', 'special_schedules', 'modified', )
fields = (
"slug",
"facility_name",
"logo",
"facility_location",
"facility_category",
"phone_number",
"facility_product_tags",
"facility_labels",
"facility_classifier",
"tapingo_url",
"note",
"main_schedule",
"special_schedules",
"modified",
)
......@@ -11,27 +11,32 @@ http://www.django-rest-framework.org/api-guide/routers/
from django.urls import include, path
from django.views.generic.base import RedirectView
# App Imports
from .views import (CategoryViewSet, FacilityViewSet, ScheduleViewSet,
LocationViewSet, AlertViewSet)
# Other Imports
from rest_framework.routers import DefaultRouter
# App Imports
from .views import (
CategoryViewSet,
FacilityViewSet,
ScheduleViewSet,
LocationViewSet,
AlertViewSet,
)
# Instantiate our DefaultRouter
ROUTER = DefaultRouter()
# Register views to the API router
ROUTER.register(r'alerts', AlertViewSet, 'alert')
ROUTER.register(r'categories', CategoryViewSet, 'category')
ROUTER.register(r'facilities', FacilityViewSet, 'facility')
ROUTER.register(r'locations', LocationViewSet, 'location')
ROUTER.register(r'schedules', ScheduleViewSet, 'schedule')
ROUTER.register(r"alerts", AlertViewSet, "alert")
ROUTER.register(r"categories", CategoryViewSet, "category")
ROUTER.register(r"facilities", FacilityViewSet, "facility")
ROUTER.register(r"locations", LocationViewSet, "location")
ROUTER.register(r"schedules", ScheduleViewSet, "schedule")
urlpatterns = [
# / - Default route
# We redirect to /api since this is in reality the default page for the API
path('', RedirectView.as_view(url='/api')),
path("", RedirectView.as_view(url="/api")),
# /api - Root API URL
path('api/', include(ROUTER.urls)),
path("api/", include(ROUTER.urls)),
]
This diff is collapsed.
......@@ -8,8 +8,8 @@ Do not touch at all. This is the main entry point for interacting with Django.
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.local")
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.settings")
from django.core.management import execute_from_command_line
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
settings/local.py
Development settings and globals.
"""
# Import the base settings and override where necessary
from .base import *
"""
DEBUG CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = True
"""
CACHE CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
}
}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
settings/production.py
Production settings and globals.
"""
# Python std. lib imports
from os import environ
# Django Imports
from django.core.exceptions import ImproperlyConfigured
# Import the base settings and override where necessary
from .base import *
def get_env_setting(setting):
"""
Get the environment setting or return exception
"""
try:
return environ[setting]
except KeyError as ex:
print(str(ex))
error_msg = "Set the %s env variable" % setting
raise ImproperlyConfigured(error_msg)
"""
HOST CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/1.5/releases/1.5/#allowed-hosts-required-in-production
ALLOWED_HOSTS = ['*']
"""
DEBUG CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = False
"""
CACHE CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
}
}
"""
SECRET CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = get_env_setting('WOPEN_SECRET_KEY')
########## END SECRET CONFIGURATION
......@@ -16,17 +16,13 @@ admin.autodiscover()
# Define all the top level url patterns in a list
urlpatterns = [
# / - Load in all urls from the `api` app
path('', include('api.urls')),
path("", include("api.urls")),
# /admin/docs - Documentation for admin
path('admin/doc/', include('django.contrib.admindocs.urls')),
path("admin/doc/", include("django.contrib.admindocs.urls")),
# /admin - The admin panels
path('admin/', admin.site.urls),
# /api-auth - API Auth page
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
path("admin/", admin.site.urls),
# /auth - API Auth page
path("auth/", include("rest_framework.urls", namespace="rest_framework")),
# /logout - Redirect to the homepage on logout
path('logout/', django.contrib.auth.views.logout, {'next_page': '/'}),
path("logout/", django.contrib.auth.views.logout, {"next_page": "/"}),
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment