summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar cel <cel@blos.sm>2022-05-04 12:18:16 +0100
committerLibravatar cel <cel@blos.sm>2022-05-04 12:18:16 +0100
commit4acc56516657fab7608f77e2d19867e1d9e7ce8b (patch)
treedcdc6fed0d043d46c9bdc0c6ebe6801b4b4804c6
downloadvictoria-4acc56516657fab7608f77e2d19867e1d9e7ce8b.tar.gz
victoria-4acc56516657fab7608f77e2d19867e1d9e7ce8b.tar.bz2
victoria-4acc56516657fab7608f77e2d19867e1d9e7ce8b.zip
initial commit - created database models
-rw-r--r--victoria/__init__.py32
-rw-r--r--victoria/admin/__init__.py0
-rw-r--r--victoria/config.py12
-rw-r--r--victoria/errors/__init__.py0
-rw-r--r--victoria/models.py88
-rw-r--r--victoria/portfolio/__init__.py0
-rw-r--r--victoria/static/style.css0
7 files changed, 132 insertions, 0 deletions
diff --git a/victoria/__init__.py b/victoria/__init__.py
new file mode 100644
index 0000000..439c217
--- /dev/null
+++ b/victoria/__init__.py
@@ -0,0 +1,32 @@
+from flask import Flask
+from flask_sqlalchemy import SQLAlchemy
+from flask_bcrypt import Bcrypt
+from flask_login import LoginManager
+from flask_mail import Mail
+from victoria.config import Config
+
+db = SQLAlchemy()
+bcrypt = Bcrypt()
+login_manager = LoginManager()
+login_manager.login_view = 'admin.login'
+login_manager.login_message_category = 'info'
+mail = Mail()
+
+def create_app(config_class=Config):
+ app = Flask(__name__)
+ app.config.from_object(config_class)
+
+ db.init_app(app)
+ bcrypt.init_app(app)
+ login_manager.init_app(app)
+ mail.init_app(app)
+
+ from victoria.portfolio.routes import portfolio
+ from victoria.admin.routes import admin
+ from victoria.errors.handlers import errors
+ app.register_blueprint(portfolio)
+ app.register_blueprint(admin)
+ app.register_blueprint(errors)
+
+ return app
+
diff --git a/victoria/admin/__init__.py b/victoria/admin/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/victoria/admin/__init__.py
diff --git a/victoria/config.py b/victoria/config.py
new file mode 100644
index 0000000..7ec4a78
--- /dev/null
+++ b/victoria/config.py
@@ -0,0 +1,12 @@
+import os
+
+class Config:
+ SECRET_KEY = '5791628bb0b13ce0c676dfde280ba245'
+ SQLALCHEMY_DATABASE_URI = 'sqlite:///site.db'
+ MAIL_SERVER = 'mail.blos.sm'
+ MAIL_PORT = '587'
+ MAIL_USE_TLS = True
+ MAIL_USERNAME = os.environ.get('EMAIL_USER')
+ MAIL_PASSWORD = os.environ.get('EMAIL_PASS')
+ ADMIN_EMAIL = 'victoria@kennaugh.com'
+
diff --git a/victoria/errors/__init__.py b/victoria/errors/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/victoria/errors/__init__.py
diff --git a/victoria/models.py b/victoria/models.py
new file mode 100644
index 0000000..85bf40e
--- /dev/null
+++ b/victoria/models.py
@@ -0,0 +1,88 @@
+from victoria import db, login_manager
+from flask_login import UserMixin
+from datetime import datetime
+
+@login_manager.user_loader
+def load_user(artist_id):
+ return Artist.query.get(int(artist_id))
+
+# helper tables
+artist_work = db.Table('artist_work',
+ db.Column('artist_id', db.Integer, db.ForeignKey('artist.id'), primary_key=True),
+ db.Column('work_id', db.Integer, db.ForeignKey('work.id'), primary_key=True)
+)
+artist_series = db.Table('artist_series',
+ db.Column('artist_id', db.Integer, db.ForeignKey('artist.id'), primary_key=True),
+ db.Column('series_id', db.Integer, db.ForeignKey('series.id'), primary_key=True)
+)
+series_work = db.Table('series_work',
+ db.Column('series_id', db.Integer, db.ForeignKey('series.id'), primary_key=True),
+ db.Column('work_id', db.Integer, db.ForeignKey('work.id'), primary_key=True)
+)
+tags = db.Table('tags',
+ db.Column('tag', db.String(20), db.ForeignKey('tag.tag'), primary_key=True),
+ db.Column('work_id', db.Integer, db.ForeignKey('work.id'), primary_key=True)
+)
+
+# models
+class Artist(db.Model, UserMixin):
+ id = db.Column(db.Integer, primary_key=True)
+ username = db.Column(db.String(20), unique=True, nullable=False)
+ email = db.Column(db.String(120), unique=True, nullable=False)
+ name = db.Column(db.String(120))
+ profile_picture = db.Column(db.String(20))
+ bio = db.Column(db.Text)
+
+ works = db.relationship('Work', secondary=tags, lazy='subquery',
+ backref=db.backref('artist', lazy=True))
+ series = db.relationship('Series', secondary=tags, lazy='subquery',
+ backref=db.backref('artist', lazy=True))
+
+ def __repr__(self):
+ return f"Artist('{self.username}', '{self.email}', '{self.name}')"
+
+class Work(db.Model):
+ id = db.Column(db.Integer, primary_key=True)
+ image_file = db.Column(db.String(20), unique=True, nullable=False)
+ image_dimensions = db.Column(db.String(15), nullable=False) # pass in 'widthxheight'
+ title = db.Column(db.String(120), nullable=False, default='Untitled')
+ date = db.Column(db.DateTime),
+ date_added = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
+ description = db.Column(db.Text)
+ alt_text = db.Column(db.Text)
+
+ # tags
+ tags = db.relationship('Tag', secondary=tags, lazy='subquery',
+ backref=db.backref('works', lazy=True))
+ # license
+ license = db.Column(db.String(20), db.ForeignKey('license.license'))
+
+ def __repr__(self):
+ return f"Work('{self.title}', '{self.image_file}', '{self.alt_text}')"
+
+class Series(db.Model):
+ id = db.Column(db.Integer, primary_key=True)
+ title = db.Column(db.String(120), nullable=False, default='Untitled')
+ date = db.Column(db.DateTime),
+ date_added = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
+ location = db.Column(db.String(120))
+ description = db.Column(db.Text)
+
+ # tree self-relationship
+ children = db.relationship('Series', backref='parent', lazy=True)
+ parent_id = db.Column(db.Integer, db.ForeignKey('parent.id'), nullable=False)
+
+ # many-to-many relationships
+ # works
+ works = db.relationship('Work', secondary=tags, lazy='subquery',
+ backref=db.backref('series', lazy=True))
+
+
+class Tag(db.Model):
+ tag = db.Column(db.String(20), primary_key=True)
+
+class License(db.Model):
+ license = db.Column(db.String(20), primary_key=True)
+ text = db.Column(db.Text)
+ works = db.relationship('Work', backref='license', lazy=True)
+
diff --git a/victoria/portfolio/__init__.py b/victoria/portfolio/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/victoria/portfolio/__init__.py
diff --git a/victoria/static/style.css b/victoria/static/style.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/victoria/static/style.css