refactor: housekeeping tasks

legacy
Steve Nyemba 3 years ago
parent 25b10e53a7
commit 601d4ab625

@ -13,8 +13,10 @@ from __future__ import division
from flask import Flask, request, session, render_template, Response,redirect
from flask_session import Session
from flask_cors import CORS
from flask_pymongo import PyMongo
from flask_mongo_sessions import MongoDBSessionInterface
# from flask_pymongo import PyMongo
# from flask_mongo_sessions import MongoDBSessionInterface
# # from flask.ext.mongoengine import MongoEngine
import transport
import stripe
import json
@ -25,6 +27,7 @@ from utils.params import PARAMS
from transport import factory
# from store import Store
import store
import transport
from datetime import datetime
import numpy as np
import requests
@ -60,7 +63,7 @@ LOGGER = transport.factory.instance(**SYS_STORE['logger'])
# amount = float(request.args['amount']) if 'amount' in request.args else 5.0
# args = {'amount':amount,'context':CONTEXT}
# return render_template('donate.html',**args)
def get_id(id):
def get_id(id=None):
return CONFIG['default']['id'] if not id else id
@app.route("/")
def index():
@ -69,7 +72,7 @@ def index():
return get_plans_ui(id)
headers = {"content-type":"application/json"}
mystore = store.factory.instance(name='music')
mystore = store.factory.instance(name=CONFIG['default']['id'])
products = mystore.get.products()
args = {"context":CONTEXT,"products":products}
return json.dumps(products),headers
@ -112,6 +115,7 @@ def signup():
The assumption here is one product - one plan
:request.form stripeToken (optional)
"""
if request.method == 'GET' :
if 'auth' not in session :
return "0",403
@ -252,8 +256,9 @@ def get_plans_ui(id):
args = {"product":id,"label":label,"description":description,"context":CONTEXT,"plans":mystore.get.plans(),"now":datetime.now().year}
args['product'] = mystore.product
args['theme'] = 'theme-clouds'
session['cloud-view'] = CONFIG['cloud-view'].replace(':id',id)
session['product'] = mystore.product
args['cloud_view'] = CONFIG['cloud-view'].replace(':id',id)
args['product'] = mystore.product
return render_template('plans.html',**args)
@app.route("/goto/<id>",methods=['POST','GET'])
def redirect(id ) :
@ -275,6 +280,11 @@ def redirect(id ) :
return "0",403
pass
@app.route("/donate")
def _donate():
_id = get_id()
return donate(_id)
@app.route("/<id>/donate")
def donate (id) :
"""
@ -429,45 +439,37 @@ def get_plans(product) :
return []
# @app.route('/features/<product>')
@app.route('/<product>/features')
def features(product):
@app.route("/features")
def _features():
_id = get_id()
return features(_id)
@app.route('/<id>/features')
def features(id):
"""
This function returns the plan/features of a user for a given application if provided a uid (email)
if no uid are provided then the function will return all the plans/features associated with the given product
@header uid user's email
"""
plans = []
if 'uid' in request.headers :
uid = request.headers['uid']
couchdb = CouchdbReader(uri=CONFIG['couchdb']['uri'],dbname=product,uid=uid,create=False)
key = couchdb.view("users/uid_map",key=uid)
if key :
key = key[0]['value']
plans = couchdb.view('users/active_plan',key=key)
plans = [plan['value'] for plan in plans if 'value' in plan]
else:
plans = []
else:
plans = get_plans(product)
#
# formatting plans for the output
#
plans = get_plans(id)
return json.dumps(plans),{"content-type":"application/json"}
if __name__ == '__main__' :
#
# setup mongodb session management (not sure why)
#app.config['SESSION_TYPE'] = 'mongodb'
# app.config['SESSION_TYPE'] = 'filesystem'
# app.config['MONGO_URI'] = 'mongodb://localhost:27017'
#app.config['SESSION_MONGODB_DB'] = CONFIG['store']['logger']['db']
#app.config['SESSION_MONGODB_COLLECT'] = 'session'
# app.config['SESSION_MONGODB_DB'] = 'sessions' #CONFIG['d']['logger']['db']
# app.config['SESSION_MONGODB_COLLECT'] = CONFIG['default']['id']
# mongo = PyMongo(app)
# app.session_interface = MongoDBSessionInterface(app,mongo.db, 'store')
# app.config['MONGODB_DB'] = 'sessions'
# app.session_interface = MongoDBSessionInterface(app, mongo.db, 'store')
app.debug = True ;
app.secret_key = '360-8y-[0v@t10n]+kr81v17y'
app.config['MAX_CONTENT_LENGTH'] = 1600 * 1024 * 1024
#Session(app)
Session(app)
app.run(port=PORT,threaded=True,host='0.0.0.0')
# app.run() #'0.0.0.0',PORT,True,threaded=True)

@ -7,5 +7,6 @@ stripe
flask-mongo-sessions
flask-pymongo
flask-session
git+https://dev.the-phi.com/git/steve/data-transport.git
stripe==2.48.0
git+https://github.com/lnyemba/data-transport.git
stripe
# stripe==2.48.0
Loading…
Cancel
Save