Пример #1
0
def sharedata():
    js = share_data.getalljsonshares(current_user.username)
    io = StringIO()
    #return json.dumps(js, io)
    data= json.dumps(js, io)

    if current_user.is_authenticated:

        return render_template('sharedata.html', data=share_data.getalljsonshares(current_user.username),
                               portfolioids=Userownedshare.listportfolios())
Пример #2
0
    def getportfoliovalues(user):

        portfolioids = Userownedshare.listportfolios()
        portfoliovalues ={}

        for id in portfolioids:

            portfoliovalues[id] = share_data.getsubportfoliovalue(user, id)

        print "test:"
        print portfoliovalues
        return portfoliovalues
Пример #3
0
def edit_share(bookmark_id):
    tempeditshare = Userownedshare.query.get_or_404(bookmark_id)
    if current_user.username != tempeditshare.user:
        abort(403)
    form = EditShareForm(obj=tempeditshare)
    if form.validate_on_submit():
        form.populate_obj(tempeditshare)
        db.session.commit()
        flash("You have successfully edited the share: '{}'". format(tempeditshare.name.name))
        return redirect(url_for('index'))

    return render_template('editshare_form.html', portfolioids = Userownedshare.listportfolios(), form=form, title="Edit share")
Пример #4
0
def add():
    form = ShareForm()
    if form.validate_on_submit():
        ticker = form.ticker.data
        quantity = form.quantity.data
        dividends = form.dividends.data
        bm = Userownedshare(user=current_user.username, quantity=quantity, ticker=ticker, dividends=dividends)
        db.session.add(bm)
        db.session.commit()
        flash("Added share '{}'".format(ticker))
        return redirect(url_for('index'))
    return render_template('add.html', form=form, portfolioids = Userownedshare.listportfolios())
Пример #5
0
def list_portfolio(portfolio_id):

    allshares = share_data.getalljsonshares(current_user.username)
    sharesinportfolio = []

    for share in allshares:

        if share['portfolioid'] == portfolio_id:

            sharesinportfolio.append(share)


    return render_template('portfolio.html', id=portfolio_id, portfolioids = Userownedshare.listportfolios(), portfolioshares=sharesinportfolio)
Пример #6
0
def add():
    form = AddShareForm()
    if form.validate_on_submit():
        ticker = form.ticker.data
        quantity = form.quantity.data
        dividends = form.dividends.data
        portfolioid = form.portfolioid.data

        if not Share.exists(ticker):

            sharedata = share_data.JSONSharePrice(ticker)
            sharename = sharedata['query']['results']['quote']['Name']

            newshare = Share(ticker=ticker, name=sharename)
            db.session.add(newshare)
           # db.session.commit()

        bm = Userownedshare(user=current_user.username, quantity=quantity, ticker=ticker, dividends=dividends, portfolioid=portfolioid)
        db.session.add(bm)
        db.session.commit()
        flash("Added share '{}'".format(ticker))
        return redirect(url_for('index'))
    return render_template('add.html', form=form, portfolioids = Userownedshare.listportfolios())
Пример #7
0
def index():

    if current_user.is_authenticated:



        return render_template('index.html', shares=share_data.getalljsonshares(current_user.username), portfolioids = Userownedshare.listportfolios())

    else: return render_template('index.html')