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