Bugfixes, refactoring
This commit is contained in:
parent
54465725af
commit
ca48a0f0ed
|
@ -1,12 +1,11 @@
|
||||||
import requests
|
import requests
|
||||||
from flask import jsonify, send_from_directory, Response, request
|
from flask import jsonify, send_from_directory, Response
|
||||||
from flask_yoloapi import endpoint, parameter
|
from flask_yoloapi import endpoint, parameter
|
||||||
|
|
||||||
import settings
|
|
||||||
from funding.bin.utils import get_ip
|
from funding.bin.utils import get_ip
|
||||||
from funding.bin.qr import QrCodeGenerator
|
from funding.bin.qr import QrCodeGenerator
|
||||||
from funding.factory import app, db
|
from funding.factory import app
|
||||||
from funding.orm.orm import Proposal, User
|
from funding.orm import Proposal
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/1/proposals')
|
@app.route('/api/1/proposals')
|
||||||
|
|
|
@ -4,7 +4,6 @@ import requests
|
||||||
from requests.auth import HTTPDigestAuth
|
from requests.auth import HTTPDigestAuth
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
from funding.orm.orm import User
|
|
||||||
|
|
||||||
|
|
||||||
class Daemon:
|
class Daemon:
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
import os
|
|
||||||
import json
|
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
|
|
||||||
import pyqrcode
|
|
||||||
import requests
|
import requests
|
||||||
from flask import g, request
|
from flask import request
|
||||||
from flask.json import JSONEncoder
|
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
from funding.factory import cache
|
from funding.factory import cache
|
||||||
|
@ -14,7 +10,7 @@ from funding.factory import cache
|
||||||
def json_encoder(obj):
|
def json_encoder(obj):
|
||||||
if isinstance(obj, (datetime, date)):
|
if isinstance(obj, (datetime, date)):
|
||||||
return obj.isoformat()
|
return obj.isoformat()
|
||||||
raise TypeError ("Type %s not serializable" % type(obj))
|
raise TypeError("Type %s not serializable" % type(obj))
|
||||||
|
|
||||||
|
|
||||||
class Summary:
|
class Summary:
|
||||||
|
@ -30,7 +26,7 @@ class Summary:
|
||||||
@cache.cached(timeout=600, key_prefix="funding_stats")
|
@cache.cached(timeout=600, key_prefix="funding_stats")
|
||||||
def fetch_stats():
|
def fetch_stats():
|
||||||
from funding.factory import db
|
from funding.factory import db
|
||||||
from funding.orm.orm import Proposal, User, Comment
|
from funding.orm import Proposal, User
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
categories = settings.FUNDING_CATEGORIES
|
categories = settings.FUNDING_CATEGORIES
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
from datetime import datetime
|
from flask import request
|
||||||
from flask import session, g, request
|
|
||||||
import settings
|
import settings
|
||||||
from funding.bin.utils import Summary
|
from funding.bin.utils import Summary
|
||||||
from funding.factory import app, db
|
from funding.factory import app, db
|
||||||
from funding.orm.orm import Proposal, User, Comment
|
from funding.orm import User, Comment
|
||||||
|
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
|
@ -41,11 +40,6 @@ def after_request(res):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
@app.teardown_appcontext
|
|
||||||
def shutdown_session(**kwargs):
|
|
||||||
db.session.remove()
|
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def error(err):
|
def error(err):
|
||||||
return 'Error', 404
|
return 'Error', 404
|
||||||
|
|
|
@ -39,20 +39,15 @@ def _setup_session(app: Flask):
|
||||||
|
|
||||||
def _setup_db(app: Flask):
|
def _setup_db(app: Flask):
|
||||||
global db
|
global db
|
||||||
|
uri = 'postgresql+psycopg2://{user}:{pw}@{url}/{db}'.format(
|
||||||
DB_URL = 'postgresql+psycopg2://{user}:{pw}@{url}/{db}'.format(
|
|
||||||
user=settings.PSQL_USER,
|
user=settings.PSQL_USER,
|
||||||
pw=settings.PSQL_PASS,
|
pw=settings.PSQL_PASS,
|
||||||
url=settings.PSQL_HOST,
|
url=settings.PSQL_HOST,
|
||||||
db=settings.PSQL_DB)
|
db=settings.PSQL_DB)
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = DB_URL
|
app.config['SQLALCHEMY_DATABASE_URI'] = uri
|
||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app)
|
||||||
|
|
||||||
import funding.orm
|
import funding.orm
|
||||||
|
db.create_all()
|
||||||
with app.app_context():
|
|
||||||
db.create_all()
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
|
@ -87,7 +82,7 @@ def create_app():
|
||||||
|
|
||||||
@login_manager.user_loader
|
@login_manager.user_loader
|
||||||
def load_user(_id):
|
def load_user(_id):
|
||||||
from funding.orm.orm import User
|
from funding.orm import User
|
||||||
return User.query.get(int(_id))
|
return User.query.get(int(_id))
|
||||||
|
|
||||||
# import routes
|
# import routes
|
||||||
|
|
|
@ -191,14 +191,14 @@ class Proposal(db.Model):
|
||||||
return {"amount": amount, "pct": pct}
|
return {"amount": amount, "pct": pct}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@cache.cached(timeout=60, key_prefix="fetch_prices")
|
@cache.cached(timeout=60, make_cache_key=lambda p: f"proposal_balance_{p.id}")
|
||||||
def balance(self):
|
def balance(self):
|
||||||
"""This property retrieves the current funding status
|
"""This property retrieves the current funding status
|
||||||
of this proposal. It uses Redis cache to not spam the
|
of this proposal. It uses Redis cache to not spam the
|
||||||
daemon too much. Returns a nice dictionary containing
|
daemon too much. Returns a nice dictionary containing
|
||||||
all relevant proposal funding info"""
|
all relevant proposal funding info"""
|
||||||
from funding.bin.utils import Summary, coin_to_usd
|
from funding.bin.utils import Summary, coin_to_usd
|
||||||
from funding.factory import cache, db
|
from funding.factory import db
|
||||||
rtn = {'sum': 0.0, 'txs': [], 'pct': 0.0, 'available': 0}
|
rtn = {'sum': 0.0, 'txs': [], 'pct': 0.0, 'available': 0}
|
||||||
|
|
||||||
if self.archived:
|
if self.archived:
|
||||||
|
@ -263,7 +263,6 @@ class Proposal(db.Model):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def find_by_args(cls, status: int = None, cat: str = None, limit: int = 20, offset=0):
|
def find_by_args(cls, status: int = None, cat: str = None, limit: int = 20, offset=0):
|
||||||
from funding.factory import db
|
|
||||||
if isinstance(status, int) and status not in settings.FUNDING_STATUSES.keys():
|
if isinstance(status, int) and status not in settings.FUNDING_STATUSES.keys():
|
||||||
raise NotImplementedError('invalid status')
|
raise NotImplementedError('invalid status')
|
||||||
if isinstance(cat, str) and cat not in settings.FUNDING_CATEGORIES:
|
if isinstance(cat, str) and cat not in settings.FUNDING_CATEGORIES:
|
|
@ -1,15 +1,14 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from flask import request, redirect, Response, abort, render_template, url_for, flash, make_response, send_from_directory, jsonify
|
from flask import request, redirect, render_template, url_for, flash, make_response, send_from_directory, jsonify
|
||||||
from flask_login import login_user , logout_user , current_user, login_required, current_user
|
from flask_login import login_user , logout_user , current_user
|
||||||
from dateutil.parser import parse as dateutil_parse
|
from dateutil.parser import parse as dateutil_parse
|
||||||
from flask_yoloapi import endpoint, parameter
|
from flask_yoloapi import endpoint, parameter
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
from funding.bin.utils import Summary
|
|
||||||
from funding.factory import app, db, cache
|
from funding.factory import app, db, cache
|
||||||
from funding.orm.orm import Proposal, User, Comment
|
from funding.orm import Proposal, User, Comment
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
|
@ -65,7 +64,7 @@ def proposal_comment(pid, text, cid):
|
||||||
|
|
||||||
@app.route('/proposal/<int:pid>/comment/<int:cid>')
|
@app.route('/proposal/<int:pid>/comment/<int:cid>')
|
||||||
def propsal_comment_reply(cid, pid):
|
def propsal_comment_reply(cid, pid):
|
||||||
from funding.orm.orm import Comment
|
from funding.orm import Comment
|
||||||
c = Comment.find_by_id(cid)
|
c = Comment.find_by_id(cid)
|
||||||
if not c or c.replied_to:
|
if not c or c.replied_to:
|
||||||
return redirect(url_for('proposal', pid=pid))
|
return redirect(url_for('proposal', pid=pid))
|
||||||
|
@ -256,9 +255,6 @@ def proposals(status, page, cat):
|
||||||
|
|
||||||
@app.route('/donate')
|
@app.route('/donate')
|
||||||
def donate():
|
def donate():
|
||||||
from funding.bin.daemon import Daemon
|
|
||||||
from funding.factory import cache, db
|
|
||||||
|
|
||||||
return "devfund page currently not working :D"
|
return "devfund page currently not working :D"
|
||||||
|
|
||||||
data_default = {'sum': 0, 'txs': []}
|
data_default = {'sum': 0, 'txs': []}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
from flask_login import login_required
|
|
||||||
from funding.factory import app, db
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/admin/index')
|
|
||||||
@login_required
|
|
||||||
def admin_home():
|
|
||||||
return 'yep'
|
|
Loading…
Reference in New Issue