Skip to content

Commit

Permalink
Fixes release (#301)
Browse files Browse the repository at this point in the history
* Updated build env

* Updated build env

* Added static and media storage classes (#289)

* Added static and media storage classes

* Removed unused default

* Use -T for exec

* Fixed github actions

* Bump django from 3.2.7 to 3.2.8 (#295)

Bumps [django](https://github.com/django/django) from 3.2.7 to 3.2.8.
- [Release notes](https://github.com/django/django/releases)
- [Commits](django/django@3.2.7...3.2.8)

---
updated-dependencies:
- dependency-name: django
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump xlsxwriter from 1.4.5 to 3.0.1 (#290)

Bumps [xlsxwriter](https://github.com/jmcnamara/XlsxWriter) from 1.4.5 to 3.0.1.
- [Release notes](https://github.com/jmcnamara/XlsxWriter/releases)
- [Changelog](https://github.com/jmcnamara/XlsxWriter/blob/main/Changes)
- [Commits](jmcnamara/XlsxWriter@RELEASE_1.4.5...RELEASE_3.0.1)

---
updated-dependencies:
- dependency-name: xlsxwriter
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump pytz from 2021.1 to 2021.3 (#291)

Bumps [pytz](https://github.com/stub42/pytz) from 2021.1 to 2021.3.
- [Release notes](https://github.com/stub42/pytz/releases)
- [Commits](stub42/pytz@release_2021.1...release_2021.3)

---
updated-dependencies:
- dependency-name: pytz
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump faker from 8.14.1 to 8.16.0 (#292)

Bumps [faker](https://github.com/joke2k/faker) from 8.14.1 to 8.16.0.
- [Release notes](https://github.com/joke2k/faker/releases)
- [Changelog](https://github.com/joke2k/faker/blob/master/CHANGELOG.md)
- [Commits](joke2k/faker@v8.14.1...v8.16.0)

---
updated-dependencies:
- dependency-name: faker
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump django-cors-headers from 3.9.0 to 3.10.0 (#294)

Bumps [django-cors-headers](https://github.com/adamchainz/django-cors-headers) from 3.9.0 to 3.10.0.
- [Release notes](https://github.com/adamchainz/django-cors-headers/releases)
- [Changelog](https://github.com/adamchainz/django-cors-headers/blob/main/HISTORY.rst)
- [Commits](adamchainz/django-cors-headers@3.9.0...3.10.0)

---
updated-dependencies:
- dependency-name: django-cors-headers
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Added static dir to static files

* Updated static config

* Update static config

* Added extra permission checks (#296)

* Added extra permission checks

* Nasty hack to fix tests

* Bump faker from 8.16.0 to 9.0.0 (#297)

Bumps [faker](https://github.com/joke2k/faker) from 8.16.0 to 9.0.0.
- [Release notes](https://github.com/joke2k/faker/releases)
- [Changelog](https://github.com/joke2k/faker/blob/master/CHANGELOG.md)
- [Commits](joke2k/faker@v8.16.0...v9.0.0)

---
updated-dependencies:
- dependency-name: faker
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Ignore order of search results

* Build dev container on push to dev

* fix: Update booking target user (#298)

* update total to a property, and "fix" slow load times on booking index in admin

* check for draft booking when changing target user

* Update test_mutations.py

* Update test_mutations.py

* repo: Fix Single Seed & Implement .env (#300)

* Fix single seed e2e command

* Allow for a .env file in root

* Update local.yml

* Fix lint thing

* Appease the man

* Dont include .env in docker images

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alex Toff <[email protected]>
  • Loading branch information
3 people authored Oct 7, 2021
1 parent fecf5f5 commit b05ab77
Show file tree
Hide file tree
Showing 35 changed files with 316 additions and 122 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ omit = *migrations*,
./uobtheatre-api/wsgi.py,
*__init__*
./uobtheatre/management/*
./uobtheatre/storages.py

[report]
exclude_lines =
Expand Down
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.*
!.coveragerc
!.env
18 changes: 0 additions & 18 deletions .env-example

This file was deleted.

5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Use this file to add environment variables into the image environment
# Rename it to ".env" and it should be automatically read

# Square
SQUARE_ACCESS_TOKEN=
4 changes: 2 additions & 2 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Deploy new image
uses: appleboy/ssh-action@master
env:
SERVICE_NAME: $SERVICE_NAME
SERVICE_NAME: ${{ env.SERVICE_NAME }}
with:
host: ${{ secrets.SERVER_SSH_HOST }}
username: ${{ secrets.SERVER_SSH_USER }}
Expand All @@ -48,4 +48,4 @@ jobs:
cd /var/sta
docker-compose pull $SERVICE_NAME
docker-compose up -d $SERVICE_NAME
docker-compose exec $SERVICE_NAME python manage.py migrate
docker-compose exec -T $SERVICE_NAME python manage.py migrate
6 changes: 3 additions & 3 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

env:
DEV_IMAGE_NAME: api-dev
IMAGE_NAME: api-dev
IMAGE_OWNER: bristolsta

jobs:
Expand All @@ -22,11 +22,11 @@ jobs:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file compose/local/django/Dockerfile --tag ghcr.io/$IMAGE_OWNER/$DEV_IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
run: docker build . --file compose/local/django/Dockerfile --tag ghcr.io/$IMAGE_OWNER/$IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Log into registry
# This is where you will update the PAT to GITHUB_TOKEN
run: echo "${{ secrets.BRISTOLSTA_REGISTRY_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: docker push ghcr.io/$IMAGE_OWNER/$DEV_IMAGE_NAME:latest
run: docker push ghcr.io/$IMAGE_OWNER/$IMAGE_NAME:latest
File renamed without changes.
6 changes: 3 additions & 3 deletions .github/workflows/python-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ jobs:
run: |
pylint uobtheatre
- name: mypy - static type checking
run: |
mypy uobtheatre
# - name: mypy - static type checking
# run: |
# mypy uobtheatre
schema:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ coverage.xml
.static_storage/
.media/
local_settings.py
staticfiles/

# Flask stuff:
instance/
Expand Down
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
line_length = 88
multi_line_output = 3
include_trailing_comma = True
known_third_party = autoslug,dateutil,django,django_filters,django_tiptap,environ,factory,graphene,graphene_django,graphql,graphql_auth,graphql_relay,guardian,pytest,rest_framework,shortuuid,square,xlsxwriter
known_third_party = autoslug,dateutil,django,django_filters,django_tiptap,environ,factory,graphene,graphene_django,graphql,graphql_auth,graphql_relay,guardian,pytest,rest_framework,shortuuid,square,storages,xlsxwriter
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ migrations-without-user: ## Make the migrations without setting the user (the us
docker-compose run --rm api python manage.py makemigrations

migrate: ## Do the migrations
docker-compose run api python manage.py migrate
docker-compose run --rm api python manage.py migrate

collect-static:
docker-compose run --rm api python manage.py collectstatic

check-users: ## Do the migrations
docker-compose run api `python manage.py number_of_users | tail -n 1` | grep 0
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ Install precommit with (make sure you are in venv):

If this case every commit should trigger the precommit hook. You will always need to be commit from within the venv for this to work.

## Visual studio dev container
## Visual Studio Dev Container

TODO if people care
This repository has support for users of VS Code. If you use VS Code and have Docker and the "Remote Containers" extension installed, you can get started in under 5 minutes:
* Clone this repository somewhere on your computer (If using WSL, this should be inside your WSL environment)
* Either: a) open the folder through VS Code or b) navgiate to the folder in a CLI and type `code .`
* If you have the correct extensions installed, you will see a popup on the bottom right asking if you would like to open in a remote container. Click this, and sit back!

# Local Development :computer:

Expand All @@ -53,6 +56,8 @@ To start the dev server for local development:
make up
```

If you would like to set some environment variables, you can copy the `.env.example` in the root of the project to `.env`.

## Migrations :twisted_rightwards_arrows:

A migration explains how a database changes between releases. It contains sql
Expand Down
3 changes: 2 additions & 1 deletion compose/local/django/start
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ fi
# Seed the db if not already seeded
if [[ $* == *--single-seed-e2e ]]
then
if python manage.py number_of_users | tail -n 1 | grep 0
if [[ $(python manage.py number_of_users) != 1 ]] # This is one because django seems to auto seed an anonymous user
then
echo "Skipping seeding as users in db"
else
echo "Seeding DB"
python manage.py loaddata db.json
fi
fi
Expand Down
64 changes: 34 additions & 30 deletions config/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

env = environ.Env()

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_URL = os.getenv(
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# Take environment variables from .env file
environ.Env.read_env(os.path.join(BASE_DIR, ".env"))

BASE_URL = env(
"BASE_URL",
default="http://localhost:8000",
)
Expand Down Expand Up @@ -65,41 +69,38 @@

ALLOWED_HOSTS = ["*"]
ROOT_URLCONF = "uobtheatre.urls"
SECRET_KEY = os.getenv(
SECRET_KEY = env(
"DJANGO_SECRET_KEY",
default="Ha57AUXmBdFS48TKYPMhauspK7BhwpveyvM9PGsCwwcT7RfwUN2rVkYnbuXkWhcU",
)
WSGI_APPLICATION = "config.wsgi.application"

# Email
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = os.getenv("EMAIL_HOST", "localhost")
EMAIL_PORT = os.getenv("EMAIL_PORT") or 1025
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD")
EMAIL_HOST = env("EMAIL_HOST", default="localhost")
EMAIL_PORT = env("EMAIL_PORT", default=1025)
EMAIL_HOST_USER = env("EMAIL_HOST_USER", default=None)
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD", default=None)
DEFAULT_FROM_EMAIL = "UOB Theatre <[email protected]>"

ADMINS = (("Author", "[email protected]"),)


# Postgres
DATABASES = {
"default": env.db(
"DATABASE_URL", "postgresql://postgres:postgres@postgres:5432/uobtheatre_api"
)
}
if env("DATABASE_URL", default=None): # ignore:
DATABASES = {"default": env.db("DATABASE_URL", default="")}
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": env("POSTGRES_DB", default="postgres"),
"USER": env("POSTGRES_USER", default="postgres"),
"PASSWORD": env("POSTGRES_PASSWORD", default="postgres"),
"HOST": env("POSTGRES_HOST", default="postgres"),
"PORT": env("POSTGRES_PORT", default="5432"),
}
}
DATABASES["default"]["ATOMIC_REQUESTS"] = True
# DATABASES = {
# "default"
# "default": {
# "ENGINE": "django.db.backends.postgresql_psycopg2",
# "NAME": os.getenv("DATABASE_NAME", default="postgres"),
# "USER": os.getenv("DATABASE_USER", default="postgres"),
# "PASSWORD": os.getenv("DATABASE_PASSWORD", default="postgres"),
# "HOST": os.getenv("DATABASE_HOST", default="postgres"),
# "PORT": os.getenv("DATABASE_PORT", default=5432),
# }
# }

# General
APPEND_SLASH = False
Expand All @@ -114,8 +115,10 @@

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_ROOT = os.path.normpath(join(os.path.dirname(BASE_DIR), "static"))
STATICFILES_DIRS: List[str] = []
STATIC_ROOT = os.path.normpath(join(os.path.dirname(BASE_DIR), "staticfiles"))
STATICFILES_DIRS: List[str] = [
os.path.normpath(join(os.path.dirname(BASE_DIR), "static"))
]
STATIC_URL = "/static/"
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
Expand Down Expand Up @@ -144,7 +147,7 @@

# Set DEBUG to False as a default for safety
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = strtobool(os.getenv("DJANGO_DEBUG", "no"))
DEBUG = strtobool(env("DJANGO_DEBUG", default="no"))

# Password Validation
# https://docs.djangoproject.com/en/2.0/topics/auth/passwords/#module-django.contrib.auth.password_validation
Expand Down Expand Up @@ -293,24 +296,25 @@
"SCHEMA": "uobtheatre.schema.schema",
"MIDDLEWARE": [
"graphql_jwt.middleware.JSONWebTokenMiddleware",
"uobtheatre.utils.exceptions.ExceptionMiddleware",
],
}

# Square payments
SQUARE_SETTINGS = {
"SQUARE_ACCESS_TOKEN": os.getenv(
"SQUARE_ACCESS_TOKEN": env(
"SQUARE_ACCESS_TOKEN",
default="",
),
"SQUARE_ENVIRONMENT": os.getenv(
"SQUARE_ENVIRONMENT": env(
"SQUARE_ENVIRONMENT",
default="sandbox",
),
"SQUARE_LOCATION": os.getenv(
"SQUARE_LOCATION": env(
"SQUARE_LOCATION",
default="",
),
"SQUARE_WEBHOOK_SIGNATURE_KEY": os.getenv(
"SQUARE_WEBHOOK_SIGNATURE_KEY": env(
"SQUARE_WEBHOOK_SIGNATURE_KEY",
default="",
),
Expand Down
6 changes: 6 additions & 0 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
AWS_QUERYSTRING_AUTH = False
MEDIA_URL = f"https://s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/"

STATICFILES_LOCATION = "static"
STATICFILES_STORAGE = "uobtheatre.storages.StaticStorage"

MEDIAFILES_LOCATION = "media"
DEFAULT_FILE_STORAGE = "uobtheatre.storages.MediaStorage"

SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

if sentry_dns := os.getenv("SENTRY_DNS"):
Expand Down
5 changes: 5 additions & 0 deletions config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# GENERAL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
DEBUG = True
TEST_RUNNER = "django.test.runner.DiscoverRunner"
BASE_URL = "https://api.example.com"

Expand Down Expand Up @@ -46,3 +47,7 @@
# MEDIA
# ------------------------------------------------------------------------------
MEDIA_ROOT = tempfile.mkdtemp()

# This is a very nasty hack. We should find out how to correctly handle
# static_root in tests without having to run collectstatic before.
STATIC_ROOT = os.path.normpath(join(os.path.dirname(BASE_DIR), "static"))
4 changes: 2 additions & 2 deletions local.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3"
version: '3'

volumes:
uobtheatre_local_postgres_data: {}
Expand All @@ -19,7 +19,7 @@ services:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
ports:
- "8000:8000"
- '8000:8000'
command: /start

postgres:
Expand Down
8 changes: 4 additions & 4 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ django-filter==21.1
Pillow>=8.1.2

# timezone package
pytz==2021.1
pytz==2021.3

# Cors
django-cors-headers==3.9.0
django-cors-headers==3.10.0

# TODO check if required
django-configurations==2.2
Expand All @@ -25,15 +25,15 @@ django-configurations==2.2
django-environ==0.7.0 # https://github.com/joke2k/django-environ

# Spreadsheet generation
xlsxwriter==1.4.5
xlsxwriter==3.0.1

#=== Database ===#

psycopg2==2.9.1 # https://github.com/psycopg/psycopg2

#=== Django core ===#

django==3.2.7
django==3.2.8

#=== Django Extras ===#

Expand Down
2 changes: 1 addition & 1 deletion requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pytest-django >= 0.2.0
pytest-factoryboy >= 2.1.0
coveralls >= 3.0.1
factory-boy==3.2.0
faker==8.14.1; python_version >= '3.6'
faker==9.0.0; python_version >= '3.6'

# Unsure
jedi==0.18.0; python_version >= '3.6'
6 changes: 0 additions & 6 deletions test.sh

This file was deleted.

14 changes: 2 additions & 12 deletions uobtheatre/bookings/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib import admin
from django.utils.html import format_html

from uobtheatre.bookings.models import Booking, MiscCost, Ticket

Expand All @@ -21,14 +20,5 @@ class BookingAdmin(admin.ModelAdmin):
"""

inlines = [SeatBookingInline]
list_display = ("reference", "view_price", "view_price_with_discount")

def view_price(self, booking):
return format_html("<p> {} </p>", booking.get_price())

def view_price_with_discount(self, booking):
return format_html("<p> {} </p>", booking.subtotal)

view_price.short_description = "Price" # type: ignore

view_price_with_discount.short_description = "Discounted Price" # type: ignore
readonly_fields = ("subtotal", "total")
list_display = ("reference",)
Loading

0 comments on commit b05ab77

Please sign in to comment.