137 lines
4.4 KiB
Python
137 lines
4.4 KiB
Python
from flask import Flask, \
|
|
render_template as Render,\
|
|
redirect as Redirect, \
|
|
url_for as MethodUri, \
|
|
abort as Abort
|
|
|
|
from flask_sqlalchemy import SQLAlchemy as DBM
|
|
from enum import Enum
|
|
from time import sleep
|
|
|
|
# Init
|
|
app=Flask(__name__)
|
|
app.config['SQLALCHEMY_DATABASE_URI']="sqlite:///app.db"
|
|
DB=DBM(app)
|
|
|
|
#Enums
|
|
class WorkState(Enum):
|
|
OTHER = 0
|
|
IDEA = 1
|
|
CONFIRMED = 2
|
|
PAID = 3
|
|
INPROGRESS = 4
|
|
FINISHED = 5
|
|
class TxProcessor(Enum):
|
|
OTHER = 0
|
|
PAYPAL = 1
|
|
class TxType(Enum):
|
|
OTHER = 0
|
|
NORMAL = 1
|
|
YCH = 2
|
|
YCHAUCTION = 3
|
|
class Currency(Enum):
|
|
OTHER = 0
|
|
GBP = 1
|
|
USD = 2
|
|
EUR = 3
|
|
CAD = 4
|
|
class LinkType(Enum):
|
|
OTHER = 0
|
|
WIPSKETCH = 1
|
|
WIPLINES = 2
|
|
WIPCOLOUR = 3
|
|
WIPSHADING = 4
|
|
WIPOTHER = 5
|
|
DELIVERABLE = 6
|
|
FINAL = 7
|
|
|
|
#Database stuff
|
|
class Artist(DB.Model):
|
|
artist_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True)
|
|
name = DB.Column(DB.String, nullable=False)
|
|
social_twitter = DB.Column(DB.String)
|
|
social_telegram = DB.Column(DB.String)
|
|
social_mastodon = DB.Column(DB.String)
|
|
social_furaffinity = DB.Column(DB.String)
|
|
social_weasyl = DB.Column(DB.String)
|
|
social_inkbunny = DB.Column(DB.String)
|
|
social_sofurry = DB.Column(DB.String)
|
|
social_furrynetwork = DB.Column(DB.String)
|
|
class Work(DB.Model):
|
|
work_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True)
|
|
artist_id = DB.Column(DB.Integer, DB.ForeignKey('artist.artist_id'), nullable=False)
|
|
state = DB.Column(DB.Enum(WorkState), nullable=False)
|
|
purchase_type = DB.Column(DB.Enum(TxType),nullable=False)
|
|
work_desc = DB.Column(DB.String)
|
|
date_proposed = DB.Column(DB.DateTime)
|
|
date_accepted = DB.Column(DB.DateTime)
|
|
date_paid = DB.Column(DB.DateTime)
|
|
date_inprogress = DB.Column(DB.DateTime)
|
|
date_completed = DB.Column(DB.DateTime)
|
|
class WorkLink(DB.Model):
|
|
link_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True)
|
|
work_id = DB.Column(DB.Integer, DB.ForeignKey('work.work_id'), nullable=False)
|
|
linktype = DB.Column(DB.Enum(LinkType), nullable=False)
|
|
descr = DB.Column(DB.String, nullable=False)
|
|
uri = DB.Column(DB.String, nullable=False)
|
|
datetime = DB.Column(DB.DateTime, nullable=False)
|
|
class Transaction(DB.Model):
|
|
transaction_id = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True)
|
|
artist_id = DB.Column(DB.Integer, DB.ForeignKey('artist.artist_id'), nullable=False)
|
|
work_id = DB.Column(DB.Integer, DB.ForeignKey('work.work_id'), nullable=False)
|
|
processor = DB.Column(DB.Enum(TxProcessor), nullable=False)
|
|
processor_txid = DB.Column(DB.String, unique=True, nullable=False)
|
|
currency = DB.Column(DB.Enum(Currency), nullable=False)
|
|
amount = DB.Column(DB.Float, nullable=False)
|
|
datetime = DB.Column(DB.DateTime, nullable=False)
|
|
|
|
|
|
#Debugging stuff
|
|
def RecreateDB():
|
|
DB.drop_all()
|
|
DB.create_all()
|
|
def PopulateTestData():
|
|
RecreateDB()
|
|
tArtist=Artist(name="test artist 1")
|
|
DB.session.add(tArtist)
|
|
DB.session.commit()
|
|
tWork=Work(artist_id=tArtist.artist_id,
|
|
state=WorkState.FINISHED, purchase_type=TxType.NORMAL)
|
|
tWorkTwo=Work(artist_id=tArtist.artist_id,
|
|
state=WorkState.INPROGRESS, purchase_type=TxType.YCHAUCTION)
|
|
DB.session.add_all((tWork, tWorkTwo))
|
|
DB.session.commit()
|
|
|
|
#Routes
|
|
@app.route('/')
|
|
def index():
|
|
_idea=Work.query.filter_by(state=WorkState.IDEA).join(Artist)
|
|
_conf=Work.query.filter(
|
|
(Work.state==WorkState.CONFIRMED) |
|
|
(Work.state==WorkState.PAID)).join(Artist)
|
|
_inp=Work.query.filter_by(state=WorkState.INPROGRESS).join(Artist)
|
|
_cmp=Work.query.filter_by(state=WorkState.FINISHED).join(Artist)
|
|
|
|
return Render("index.html.j2", ideas=_idea, cnfpaid=_conf, inprog=_inp, done=_cmp)
|
|
|
|
@app.route('/list/<listname>')
|
|
def list(listname=None):
|
|
_p=Work.query.filter_by(state=WorkState.FINISHED)
|
|
return Render("list.html.j2", workslist=listname, works=_p.all())
|
|
|
|
@app.route('/add')
|
|
def add(): return Render("add.html.j2")
|
|
|
|
@app.route('/update', methods=['POST'])
|
|
def update(): return Redirect(MethodUri('index'))
|
|
|
|
@app.route('/work/<id>')
|
|
def view_work(id=None): return True
|
|
|
|
@app.route('/artist/<id>')
|
|
def view_artist(id=None):
|
|
_a=Artist.query.filter_by(artist_id=id).first()
|
|
_w=Work.query.filter_by(artist_id=id).all()
|
|
_t=Transaction.query.filter_by(artist_id=id).all()
|
|
return Render("artist.html.j2", ainfo=_a, works=_w, txes=_t)
|