-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marin Capan
committed
Mar 26, 2020
1 parent
874d43e
commit 7dccb9c
Showing
26 changed files
with
1,380 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
FLASK_APP=comp.py | ||
FLASK_APP=cujes.py | ||
DB_USER=cujes | ||
DB_PASSWORD=cujes | ||
DB_HOST=172.17.0.2 | ||
DB_PORT=5432 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM ubuntu:16.04 | ||
|
||
# Add the PostgreSQL PGP key to verify their Debian packages. | ||
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 | ||
# Add PostgreSQL's repository. It contains the most recent stable release of PostgreSQL | ||
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list | ||
|
||
# Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.5 | ||
RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.5 postgresql-client-9.5 postgresql-contrib-9.5 | ||
RUN apt-get install -y vim # just so there is a text editor I'm familiar with in the container | ||
# Run the rest of the commands as the "postgres" user created by the `postgres-9.5` package during installation | ||
USER postgres | ||
# Create the psql role (DB term for user) `cujes` | ||
# Specify the role's password and make it valid forever | ||
# Create the database `cujes` and specify the role `cujes` as its owner | ||
# these are selected to conform to the "real" database (except for the password, for security reasons) | ||
RUN /etc/init.d/postgresql start &&\ | ||
createuser cujes &&\ | ||
psql --command "ALTER USER \"cujes\" WITH PASSWORD 'pimpekpenis' VALID UNTIL 'infinity';" &&\ | ||
createdb --owner cujes cujes | ||
#createdb cujes | ||
|
||
# Adjust PostgreSQL configuration so that remote connections to the database are possible. | ||
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.5/main/pg_hba.conf | ||
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.5/main/postgresql.conf | ||
|
||
# Expose the PostgreSQL port | ||
EXPOSE 5432 | ||
|
||
# Start the postgres service | ||
CMD ["/usr/lib/postgresql/9.5/bin/postgres", "-D", "/var/lib/postgresql/9.5/main", "-c", "config_file=/etc/postgresql/9.5/main/postgresql.conf"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
|
||
|
||
class Config: | ||
SECRET_KEY = os.environ.get("SECRET_KEY") or 'mali-_i_-veliki-pimpeki' | ||
# URI format: dialect+driver://username:password@host:port/database | ||
DB_USER = os.environ.get("DB_USER") or "cujes" | ||
DB_PASSWORD = os.environ.get("DB_PASSWORD") | ||
DB_HOST = os.environ.get("DB_HOST") | ||
DB_PORT = os.environ.get("DB_PORT") or "5432" | ||
DB_NAME = os.environ.get("DB_NAME") | ||
SQLALCHEMY_DATABASE_URI = "postgresql://{}:{}@{}:{}/{}".format(DB_USER, | ||
DB_PASSWORD, | ||
DB_HOST, | ||
DB_PORT, | ||
DB_NAME) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from cujes import cujes_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from flask import Flask | ||
from flask_sqlalchemy import SQLAlchemy | ||
from flask_migrate import Migrate | ||
from config import Config | ||
|
||
cujes_app = Flask(__name__) | ||
cujes_app.config.from_object(Config) | ||
# disable fsqla's event system - unused, but if wastes resources if enabled | ||
# more info: https://stackoverflow.com/questions/33738467/how-do-i-know-if-i-can-disable-sqlalchemy-track-modifications | ||
cujes_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | ||
db = SQLAlchemy(cujes_app) | ||
migrate = Migrate(cujes_app, db) | ||
|
||
from cujes import routes # noqa | ||
# noqa makes flake8 ignore the PEP-8-non-compliant import |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
from cujes import db | ||
from enum import Enum, auto | ||
from slugify import slugify | ||
from datetime import datetime | ||
|
||
|
||
# association table which models a many-to-many relationship between | ||
# artists and seasons | ||
seasons_artists = db.Table( | ||
'seasonsArtists', | ||
db.Column('season_id', db.Integer, db.ForeignKey('seasons.id'), primary_key=True), | ||
db.Column('artist_id', db.Integer, db.ForeignKey('artists.id'), primary_key=True) | ||
) | ||
|
||
|
||
class SeasonStatus(Enum): | ||
""" | ||
This class is an enumeration of possible statuses of each season | ||
""" | ||
|
||
upcoming = auto() | ||
applications_open = auto() | ||
applications_closed = auto() | ||
in_progress = auto() | ||
finished = auto() | ||
|
||
|
||
class ApplicationStatus(Enum): | ||
""" | ||
This class is an enumeration of possible statuses of each artist application | ||
""" | ||
|
||
received = auto() | ||
approved = auto() | ||
declined = auto() | ||
|
||
|
||
class Season(db.Model): | ||
""" | ||
This class models the season instances, to be used with SQLAlchemy, which | ||
will map the class to an SQL table. | ||
""" | ||
|
||
__tablename__ = "seasons" | ||
id = db.Column(db.Integer, primary_key=True) | ||
year = db.Column(db.String(64), unique=True, nullable=False) | ||
slug = db.Column(db.String(64), unique=True) | ||
status = db.Column(db.Enum(SeasonStatus), nullable=False) | ||
# note: "artists" is the name of the Postgres table, not the Python class | ||
winner_id = db.Column(db.Integer, db.ForeignKey("artists.id"), nullable=True) | ||
participants = db.relationship("Artist", | ||
secondary=seasons_artists, | ||
lazy='subquery', | ||
backref=db.backref('seasons', lazy=True)) | ||
|
||
def __init__(self, *args, **kwargs): | ||
""" | ||
Override the default constructor to autopopulate the slug field | ||
""" | ||
if 'slug' not in kwargs: | ||
kwargs['slug'] = slugify(kwargs.get('year', '')) | ||
super().__init__(*args, **kwargs) | ||
|
||
def __repr__(self): | ||
""" | ||
Override the default string representation method | ||
""" | ||
return '<Season: {}; Status: {}>'.format(self.year, self.status) | ||
|
||
|
||
class Artist(db.Model): | ||
""" | ||
This class models the artist instances, to be used with SQLAlchemy, which | ||
will map the class to an SQL table. | ||
""" | ||
|
||
__tablename__ = "artists" | ||
id = db.Column(db.Integer, primary_key=True) | ||
name = db.Column(db.String(127), unique=True, nullable=False) | ||
slug = db.Column(db.String(127), unique=True) | ||
town = db.Column(db.String(127), unique=True, nullable=False) | ||
form_year = db.Column(db.DateTime, nullable=False) | ||
bio = db.Column(db.Text, nullable=False) | ||
|
||
# path storage needs to be changed once the form is implemented | ||
demo_path = db.Column(db.String(255)) | ||
image_path = db.Column(db.String(255)) | ||
|
||
# note: "Season" is the name of the Python class, not the Postgres table | ||
won_seasons = db.relationship("Season", backref="winner", lazy="dynamic") | ||
applications = db.relationship("Application", backref="artist", lazy="dynamic") | ||
|
||
def __init__(self, *args, **kwargs): | ||
""" | ||
Override the default constructor to autopopulate the slug field | ||
""" | ||
if 'slug' not in kwargs: | ||
kwargs['slug'] = slugify(kwargs.get('name', '')) | ||
super().__init__(*args, **kwargs) | ||
|
||
def __repr__(self): | ||
""" | ||
Override the default string representation method | ||
""" | ||
return '<Artist: {}>'.format(self.name) | ||
|
||
|
||
class Post(db.Model): | ||
""" | ||
This class models the news post instances, to be used with SQLAlchemy, which | ||
will map the class to an SQL table. | ||
""" | ||
|
||
__tablename__ = "posts" | ||
id = db.Column(db.Integer, primary_key=True) | ||
title = db.Column(db.String(255), unique=True, nullable=False) | ||
slug = db.Column(db.String(255), unique=True) | ||
abstract = db.Column(db.Text, nullable=False) | ||
text = db.Column(db.Text, nullable=False) | ||
# path storage needs to be changed after admin page is done | ||
image_path = db.Column(db.String(255)) | ||
author = db.Column(db.String(255), nullable=False) | ||
date = db.Column(db.DateTime, nullable=False) | ||
|
||
def __init__(self, *args, **kwargs): | ||
""" | ||
Override the default constructor to autopopulate the slug field | ||
""" | ||
if 'slug' not in kwargs: | ||
kwargs['slug'] = slugify(kwargs.get('title', '')) | ||
if 'date' not in kwargs: | ||
kwargs['date'] = datetime.today() | ||
super().__init__(*args, **kwargs) | ||
|
||
def __repr__(self): | ||
""" | ||
Override the default string representation method | ||
""" | ||
return '<Post: {}>'.format(self.title) | ||
|
||
|
||
class Application(db.Model): | ||
""" | ||
This class models the artists' application instances, to be used with SQLAlchemy, which | ||
will map the class to an SQL table. | ||
""" | ||
|
||
__tablename__ = "applications" | ||
id = db.Column(db.Integer, primary_key=True) | ||
artist_id = db.Column(db.Integer, db.ForeignKey("artists.id"), nullable=False) | ||
status = db.Column(db.Enum(ApplicationStatus), nullable=False) | ||
email = db.Column(db.String(255), nullable=False) | ||
telephone = db.Column(db.String(15), nullable=False) | ||
date = db.Column(db.DateTime, nullable=False) | ||
|
||
def __init__(self, *args, **kwargs): | ||
""" | ||
Override the default constructor to autopopulate several fields | ||
""" | ||
kwargs['slug'] = slugify(kwargs.get('title', '')) | ||
kwargs['date'] = datetime.today() | ||
kwargs['status'] = ApplicationStatus.received | ||
super().__init__(*args, **kwargs) | ||
|
||
def __repr__(self): | ||
""" | ||
Override the default string representation method | ||
""" | ||
return '<Application - ArtistID: {}; E-mail: {}>'.format(self.artist_id, self.email) |
Oops, something went wrong.