Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #149 from seamussmith/master
Browse files Browse the repository at this point in the history
Production settings ready
  • Loading branch information
seamussmith committed Apr 6, 2022
2 parents 295b7dd + ec1dc7b commit 98e9b68
Show file tree
Hide file tree
Showing 15 changed files with 1,080 additions and 107 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ GitHub.sublime-settings
.history

# pipenv
Pipfile.lock
# Pipfile.lock

# SCSS/SASS/CSS
*.css
*.css.map

# celery
celerybeat-schedule
celerybeat-schedule
6 changes: 5 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ ipython = "*"
psycopg2 = "*"
python-dotenv = "*"
ratelimit = "*"
gunicorn = "*"
whitenoise = "*"
dj-database-url = "*"
django-compressor = "*"

[dev-packages]

[requires]
python_version = "3.10"
python_version = "3.10.4"
948 changes: 948 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: cd ./ratatoskr; gunicorn ratatoskr.wsgi:application; cd ..
release: ./ratatoskr/manage.py migrate
19 changes: 19 additions & 0 deletions ratatoskr/app/management/commands/initsocialapp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from allauth.socialaccount import providers
from django.contrib.sites.models import Site
from django.core.management.base import BaseCommand, CommandError
Expand All @@ -10,6 +11,24 @@ class Command(BaseCommand):
def handle(self, *args, **options):
override_socialapp = False

# -c get from environment variables
if "-c" in args:
app = SocialApp.objects.create(
provider = "google",
name = "ratatoskr",
client_id = os.environ["GOOGLE_CLIENT_ID"],
secret = os.environ["GOOGLE_CLIENT_SECRET"],
)

site = Site.objects.get(pk=1)

site.domain = os.environ["SITE_URL"]
site.name = os.environ["SITE_URL"]

site.save()

return

# In the case we already have another social app
if SocialApp.objects.count() == 1:
self.stdout.write("SocialApp instance found.")
Expand Down
19 changes: 0 additions & 19 deletions ratatoskr/app/migrations/0010_alter_reservation_id.py

This file was deleted.

28 changes: 28 additions & 0 deletions ratatoskr/app/migrations/0010_auto_20220405_1356.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.12 on 2022-04-05 13:56

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

dependencies = [
('app', '0009_reservation_confirmed'),
]

operations = [
migrations.RemoveField(
model_name='reservation',
name='id',
),
migrations.AddField(
model_name='reservation',
name='uuid',
field=models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False),
),
migrations.AddField(
model_name='schedule',
name='description',
field=models.CharField(default='', max_length=1000),
),
]
18 changes: 0 additions & 18 deletions ratatoskr/app/migrations/0011_alter_reservation_id.py

This file was deleted.

18 changes: 18 additions & 0 deletions ratatoskr/app/migrations/0011_rename_uuid_reservation_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2022-04-05 13:56

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('app', '0010_auto_20220405_1356'),
]

operations = [
migrations.RenameField(
model_name='reservation',
old_name='uuid',
new_name='id',
),
]
18 changes: 0 additions & 18 deletions ratatoskr/app/migrations/0012_alter_reservation_id.py

This file was deleted.

19 changes: 0 additions & 19 deletions ratatoskr/app/migrations/0013_alter_reservation_id.py

This file was deleted.

18 changes: 0 additions & 18 deletions ratatoskr/app/migrations/0014_schedule_description.py

This file was deleted.

9 changes: 8 additions & 1 deletion ratatoskr/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.shortcuts import redirect, render
from django.utils import dateparse
from django.utils.timezone import make_aware
import pytz
from app.calendarutil import build_calendar_client
from django.contrib.auth.models import User
from django.views.decorators.http import require_http_methods
Expand Down Expand Up @@ -103,9 +104,15 @@ def schedule(request, schedule):
response = update_schedule(request, schedule)

limit_days = 30
est = pytz.timezone("America/New_York")

if schedule.owner == request.user:
limit_days = 180
timeslots = schedule.timeslot_set.filter(time_from__range=(datetime.datetime.now(), datetime.datetime.now() + datetime.timedelta(days=limit_days)))
timefrom = datetime.datetime.now(est).replace(tzinfo=pytz.utc)
timeto = (datetime.datetime.now(est) + datetime.timedelta(days=limit_days)).replace(tzinfo=pytz.utc)
timeslots = schedule.timeslot_set.filter(
time_from__range=(datetime.datetime.now(est).replace(tzinfo=pytz.utc), est.localize(datetime.datetime.now() + datetime.timedelta(days=limit_days)))
)

timeslots = dict(
sorted(
Expand Down
60 changes: 49 additions & 11 deletions ratatoskr/ratatoskr/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,48 @@
import os.path
import os
from pathlib import Path
import dj_database_url

from dotenv import load_dotenv, get_key

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

load_dotenv(BASE_DIR / '.env')
# load_dotenv(BASE_DIR / '.env')

LOGIN_REDIRECT_URL = "/"

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-k(@m5gxw=ej*#adl45$%!7h_%@kipss%0k%+@(0r(%6bhv+6z3'
envget = os.environ.get('SECRET_KEY')
SECRET_KEY = envget if envget else 'django-insecure-k(@m5gxw=ej*#adl45$%!7h_%@kipss%0k%+@(0r(%6bhv+6z3'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# If there is a variable called PRODUCTION, debug will be false
DEBUG = not bool(os.environ.get('PRODUCTION'))

# yabe
# secret key needs to be defined in production
# the insecure one is literally public right there above you
if not bool(envget) and not DEBUG:
raise Exception("SECRET_KEY environment variable not defined in production!")

ALLOWED_HOSTS = [
"127.0.0.1:8000",
"https://ratatoskr-meeting-system.herokuapp.com/"
"127.0.0.1",
"localhost",
"ratatoskr-meeting-system.herokuapp.com",
"meetings.techhigh.us"
]

SITE_ID = 1

# CSRF

CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True

# Application definition

INSTALLED_APPS = [
Expand All @@ -60,6 +76,8 @@
"django_celery_results"
]

STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'

STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
Expand All @@ -74,6 +92,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware'
]

ROOT_URLCONF = 'ratatoskr.urls'
Expand All @@ -99,6 +118,7 @@
if not DEBUG:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
# These two should DEFINITELY be defined in production
EMAIL_HOST_USER = os.environ['email']
EMAIL_HOST_PASSWORD = os.environ['email_password']
EMAIL_PORT = 587
Expand All @@ -110,12 +130,24 @@
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
if DEBUG:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
else:
DATABASES = {
'default': dj_database_url.config(conn_max_age=600, ssl_require=True)
}
}

# Do not enable this in a development environment. Chrome will cache the redirect and force HTTPS redirects even when this is disabled.
# If you are a poor soul who is being harassed by Chrome and HSTS SSL,
# go to chrome://net-internals/#hsts and delete 127.0.0.1:8000, open the inspector on the website, and right click on the reload icon
# and select the Empty Cache and Hard Reload option.
SECURE_SSL_REDIRECT = not DEBUG
SECURE_HSTS_SECONDS = 0 if DEBUG else 60 ** 2

# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
Expand Down Expand Up @@ -149,12 +181,18 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = 'static/'
STATIC_URL = '/static/'

STATIC_ROOT = BASE_DIR / 'static'

SASS_PROCESSOR_ROOT = STATIC_ROOT

SASS_PROCESSOR_STORAGE = 'django.contrib.staticfiles.storage.FileSystemStorage'
SASS_PROCESSOR_STORAGE_OPTIONS = {
'location': STATIC_ROOT,
'base_url': STATIC_URL,
}

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

Expand Down
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.10.4

0 comments on commit 98e9b68

Please sign in to comment.