fusionner actifs_list avec home.pt et le supprimer
This commit is contained in:
@@ -10,6 +10,8 @@ from zope.sqlalchemy import ZopeTransactionExtension, mark_changed
|
||||
|
||||
from datetime import *
|
||||
import transaction
|
||||
from bs4 import BeautifulSoup
|
||||
import urllib2
|
||||
|
||||
from .default import (
|
||||
execute_query,
|
||||
@@ -139,3 +141,34 @@ def delete_histo(request, no_id):
|
||||
query = "DELETE FROM histo WHERE no_id = :no_id ;"
|
||||
execute_query(request, query, {'no_id': no_id})
|
||||
|
||||
def getCurrencyRate(currency):
|
||||
# specify the url
|
||||
quote_page = 'http://www.finances.net/devises/courseuro'
|
||||
|
||||
# query & parse the html using beautiful soap and store in variable `soup`
|
||||
soup = BeautifulSoup(urllib2.urlopen(quote_page), 'html.parser')
|
||||
# get the history table
|
||||
rows = soup.find('table', attrs={'class': 'news_table'}).tbody.findAll('tr')
|
||||
divs = rows[1].findAll('td')
|
||||
rate = divs[1].span.text
|
||||
return float(rate.replace(',','.'))
|
||||
|
||||
def getYahooQuote(ticker):
|
||||
# specify the url
|
||||
quote_page = 'https://finance.yahoo.com/quote/%s/history/' % ticker
|
||||
|
||||
# query & parse the html using beautiful soap and store in variable `soup`
|
||||
soup = BeautifulSoup(urllib2.urlopen(quote_page), 'html.parser')
|
||||
data = []
|
||||
# get the quote price
|
||||
rows = soup.findAll('table')[0].tbody.findAll('tr')
|
||||
for each_row in rows:
|
||||
divs = each_row.findAll('td')
|
||||
if divs[1].span.text != 'Dividend': #Ignore this row in the table
|
||||
#I'm only interested in 'Close' price;
|
||||
data.append({'Date': divs[0].span.text, 'Close': float(divs[5].span.text.replace(',',''))})
|
||||
break
|
||||
|
||||
# retourne la prière ligne
|
||||
return data[0]
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ def includeme(config):
|
||||
config.add_route('doc_list', '/doc_list')
|
||||
config.add_route('doc_view', '/doc_view/{doc_id}')
|
||||
# actifs
|
||||
config.add_route('actifs_list', '/actifs_list')
|
||||
config.add_route('actif_edit', '/actif_edit/{no_id}')
|
||||
config.add_route('actif2_edit', '/actif2_edit/{no_id}')
|
||||
config.add_route('allocation_list', '/allocation_list')
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
<div class="form-group">
|
||||
<div class="col-xs-offset-2 col-xs-10">
|
||||
<div class="form-group">
|
||||
<a class="btn btn-default" href="${request.application_url}/actifs_list">
|
||||
<a class="btn btn-default" href="${request.application_url}/home">
|
||||
<span class="glyphicon glyphicon-chevron-left"></span> Retour</a>
|
||||
<button class="btn btn-primary" type="submit" name="form.submitted">
|
||||
<span class="glyphicon glyphicon-ok"></span> Enregistrer</button>
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
<div class="form-group">
|
||||
<div class="col-xs-offset-2 col-xs-10">
|
||||
<div class="form-group">
|
||||
<a class="btn btn-default" href="${request.application_url}/actifs_list">
|
||||
<a class="btn btn-default" href="${request.application_url}/home">
|
||||
<span class="glyphicon glyphicon-chevron-left"></span> Retour</a>
|
||||
<button class="btn btn-primary" type="submit" name="form.submitted">
|
||||
<span class="glyphicon glyphicon-ok"></span> Enregistrer</button>
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
<metal:block use-macro="main_template">
|
||||
<div metal:fill-slot="content">
|
||||
|
||||
<div tal:condition="message" tal:content="message" class="alert alert-info" />
|
||||
|
||||
<form id="actif_list-form" action="${url}" method="post">
|
||||
<div class="form-group">
|
||||
<div class="form-group">
|
||||
<button id="updateButton" class="btn btn-primary" type="submit" name="form.submitted">
|
||||
<i class="glyphicon glyphicon-refresh"></i> MAJ du portefeuille</button>
|
||||
<a href="#" class="btn btn-success" role="button"
|
||||
data-toggle="modal" data-target="#choixTypeActif"><span class="glyphicon glyphicon-plus"></span> Nouvel actif</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<table id="actifs_list" class="table table-condensed table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Classe</th>
|
||||
<th>Symbole</th>
|
||||
<th>Libellé</th>
|
||||
<th class="text-right">Nombre</th>
|
||||
<th class="text-right">PRU</th>
|
||||
<th class="text-right">Cours</th>
|
||||
<th class="text-right">Valeur</th>
|
||||
<th class="text-right">+/- Valeur</th>
|
||||
<th class="text-right">% de +/-</th>
|
||||
<th class="text-right">% PF</th>
|
||||
<th class="text-right"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr tal:repeat="ligne items">
|
||||
<td class="${ligne.bg_color}">${ligne.classe}</td>
|
||||
<td>${ligne.symbole}</td>
|
||||
<td tal:condition="ligne.type=='ACTION'"><a href="actif_edit/${ligne.no_id}">${ligne.libelle}</a></td>
|
||||
<td tal:condition="ligne.type<>'ACTION'"><a href="actif2_edit/${ligne.no_id}">${ligne.libelle}</a></td>
|
||||
<td class="text-right">${ligne.nombre}</td>
|
||||
<td class="text-right">${layout.to_euro(ligne.pru)}</td>
|
||||
<td class="text-right">${ligne.cours}</td>
|
||||
<td class="text-right">${layout.to_euro(ligne.valeur)}</td>
|
||||
<td tal:condition="ligne.plus_value>=0" class="text-right" style="color: green;">${layout.to_euro(ligne.plus_value)}</td>
|
||||
<td tal:condition="ligne.plus_value <0" class="text-right" style="color: red;">${layout.to_euro(ligne.plus_value)}</td>
|
||||
<td tal:condition="ligne.pc_plusvalue>=0" class="text-right" style="color: green;">${layout.to_percent(ligne.pc_plusvalue, 1)}</td>
|
||||
<td tal:condition="ligne.pc_plusvalue <0" class="text-right" style="color: red;">${layout.to_percent(ligne.pc_plusvalue, 1)}</td>
|
||||
<td class="text-right">${ligne.pc_allocation} %</td>
|
||||
<td tal:condition="ligne.website"><a href="${ligne.website}" target="__blank"><span class="glyphicon glyphicon-search"></span></td>
|
||||
<td tal:condition="not ligne.website"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-right" colspan="6"><b>Total</b></td>
|
||||
<td class="text-right"><b>${layout.to_euro(total_valeur)}</b></td>
|
||||
<td class="text-right"><b>${layout.to_euro(total_pv)}</b></td>
|
||||
<td class="text-right"><b>${layout.to_percent(total_pc_value, 1)}</b></td>
|
||||
<td class="text-right"><b>100.0 %</b></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<!-- MODAL POPUP : Affichage de la FAQ -->
|
||||
<div class="modal fade" id="choixTypeActif" tabindex="-1" role="dialog" aria-labelledby="choixTypeActif" aria-hidden="true">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span class="glyphicon glyphicon-remove"></span></button>
|
||||
<h4 class="modal-title" id="choixTypeActif">Choix du type d'actif à créer</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>
|
||||
Voulez-vous créer un actif de type <br />
|
||||
<br />
|
||||
<a href="${request.application_url}/actif_edit/0" class="btn btn-primary" role="button">
|
||||
ACTION</a> ou
|
||||
<a href="${request.application_url}/actif2_edit/0" class="btn btn-warning" role="button">
|
||||
AUTRE</a>
|
||||
<br />
|
||||
<br />
|
||||
<p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$('#updateButton').on('click', function(){
|
||||
$('i.gly-spin').removeClass('gly-spin');
|
||||
$('i').addClass('gly-spin');
|
||||
});
|
||||
</script>
|
||||
|
||||
</div><!-- content -->
|
||||
</metal:block>
|
||||
|
||||
@@ -70,9 +70,21 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<h3>+ Diversification à coût minimal</h3>
|
||||
<h3>Mes actifs</h3>
|
||||
<p>"<i>Diversification is not determined by the number of securities held.</i>"
|
||||
<a href="http://www.etf.com/sections/index-investor-corner" target="_blank">Larry Swedroe</a></p>
|
||||
|
||||
<form id="actif_list-form" action="${url}" method="post">
|
||||
<div class="form-group">
|
||||
<div class="form-group">
|
||||
<button id="updateButton" class="btn btn-primary" type="submit" name="form.submitted">
|
||||
<i class="glyphicon glyphicon-refresh"></i> MAJ du portefeuille</button>
|
||||
<a href="#" class="btn btn-success" role="button"
|
||||
data-toggle="modal" data-target="#choixTypeActif"><span class="glyphicon glyphicon-plus"></span> Nouvel actif</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<table id="actifs_list" class="table table-condensed table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -85,12 +97,14 @@
|
||||
<th class="text-right">% Rdt</th>
|
||||
<th class="text-right">% PF</th>
|
||||
<th class="text-right">TER</th>
|
||||
<th class="text-right"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr tal:repeat="ligne actifs">
|
||||
<td class="${ligne.bg_color}">${ligne.classe}</td>
|
||||
<td>${ligne.libelle}</td>
|
||||
<td tal:condition="ligne.type=='ACTION'"><a href="actif_edit/${ligne.no_id}">${ligne.libelle}</a></td>
|
||||
<td tal:condition="ligne.type<>'ACTION'"><a href="actif2_edit/${ligne.no_id}">${ligne.libelle}</a></td>
|
||||
<td class="text-right">${layout.to_euro(ligne.valeur)}</td>
|
||||
<td tal:condition="ligne.plus_value>=0" class="text-right" style="color: green;">${layout.to_euro(ligne.plus_value)}</td>
|
||||
<td tal:condition="ligne.plus_value <0" class="text-right" style="color: red;">${layout.to_euro(ligne.plus_value)}</td>
|
||||
@@ -100,6 +114,8 @@
|
||||
<td class="text-right">${layout.to_percent(ligne.pc_rdt,1)}</td>
|
||||
<td class="text-right">${ligne.pc_allocation} %</td>
|
||||
<td class="text-right">${layout.to_percent(ligne.ter,2)}</td>
|
||||
<td tal:condition="ligne.website"><a href="${ligne.website}" target="__blank"><span class="glyphicon glyphicon-search"></span></td>
|
||||
<td tal:condition="not ligne.website"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-right" colspan="2"><b>Total</b></td>
|
||||
@@ -122,7 +138,38 @@
|
||||
<div class="col-md-6">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL POPUP : Affichage de la FAQ -->
|
||||
<div class="modal fade" id="choixTypeActif" tabindex="-1" role="dialog" aria-labelledby="choixTypeActif" aria-hidden="true">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span class="glyphicon glyphicon-remove"></span></button>
|
||||
<h4 class="modal-title" id="choixTypeActif">Choix du type d'actif à créer</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>
|
||||
Voulez-vous créer un actif de type <br />
|
||||
<br />
|
||||
<a href="${request.application_url}/actif_edit/0" class="btn btn-primary" role="button">
|
||||
ACTION</a> ou
|
||||
<a href="${request.application_url}/actif2_edit/0" class="btn btn-warning" role="button">
|
||||
AUTRE</a>
|
||||
<br />
|
||||
<br />
|
||||
<p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$('#updateButton').on('click', function(){
|
||||
$('i.gly-spin').removeClass('gly-spin');
|
||||
$('i').addClass('gly-spin');
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
|
||||
<script type="text/javascript">
|
||||
google.charts.load("current", {packages:["corechart"]});
|
||||
|
||||
@@ -54,7 +54,6 @@
|
||||
</div>
|
||||
<div class="collapse navbar-collapse" id="myNavbar" tal:condition="not layout.isAnonymous()">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li><a href="${request.application_url}/actifs_list">ACTIFS</a></li>
|
||||
<li><a href="${request.application_url}/allocation_list">ALLOCATION</a></li>
|
||||
<li><a href="${request.application_url}/histo_list">HISTORIQUE</a></li>
|
||||
<li><a href="${request.application_url}/doc_list">DOCS</a></li>
|
||||
|
||||
@@ -31,86 +31,6 @@ from ..views.default import (
|
||||
|
||||
import json
|
||||
import time
|
||||
import urllib2
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
def getYahooQuote(ticker):
|
||||
# specify the url
|
||||
quote_page = 'https://finance.yahoo.com/quote/%s/history/' % ticker
|
||||
|
||||
# query & parse the html using beautiful soap and store in variable `soup`
|
||||
soup = BeautifulSoup(urllib2.urlopen(quote_page), 'html.parser')
|
||||
data = []
|
||||
# get the quote price
|
||||
rows = soup.findAll('table')[0].tbody.findAll('tr')
|
||||
for each_row in rows:
|
||||
divs = each_row.findAll('td')
|
||||
if divs[1].span.text != 'Dividend': #Ignore this row in the table
|
||||
#I'm only interested in 'Close' price;
|
||||
data.append({'Date': divs[0].span.text, 'Close': float(divs[5].span.text.replace(',',''))})
|
||||
break
|
||||
|
||||
# retourne la prière ligne
|
||||
return data[0]
|
||||
|
||||
def getCurrencyRate(currency):
|
||||
# specify the url
|
||||
quote_page = 'http://www.finances.net/devises/courseuro'
|
||||
|
||||
# query & parse the html using beautiful soap and store in variable `soup`
|
||||
soup = BeautifulSoup(urllib2.urlopen(quote_page), 'html.parser')
|
||||
# get the history table
|
||||
rows = soup.find('table', attrs={'class': 'news_table'}).tbody.findAll('tr')
|
||||
divs = rows[1].findAll('td')
|
||||
rate = divs[1].span.text
|
||||
return float(rate.replace(',','.'))
|
||||
|
||||
|
||||
@view_config(route_name='actifs_list', renderer='../templates/actifs/actifs_list.pt', permission='view')
|
||||
def actifs_list(request):
|
||||
url = request.route_url('actifs_list')
|
||||
logged_in = request.authenticated_userid
|
||||
|
||||
message = ''
|
||||
|
||||
# lire les actifs
|
||||
items = get_actifs(request, '0')
|
||||
|
||||
# MAJ du prtefeuille
|
||||
if 'form.submitted' in request.params:
|
||||
# maj des parités des devises d'après Yahoo finance
|
||||
update_actif_devise(request, 'USD', getCurrencyRate('USD'))
|
||||
|
||||
for item in items:
|
||||
if item.type == 'ACTION':
|
||||
# get yahoo price
|
||||
quote_price = getYahooQuote(item.symbole)
|
||||
if quote_price:
|
||||
update_actif_valeur(request, item.symbole, quote_price['Close'])
|
||||
time.sleep(2) # attendre 2 secondes
|
||||
|
||||
# update du portefeuille
|
||||
update_portefeuille(request, logged_in)
|
||||
# relire les actifs
|
||||
items = get_actifs(request, '0')
|
||||
message = u'Le portefeuille est mis à jour avec succès.'
|
||||
|
||||
total_valeur = 0
|
||||
total_pv = 0
|
||||
for item in items:
|
||||
total_valeur += item.valeur
|
||||
total_pv += item.plus_value
|
||||
total_pc_value = total_pv / total_valeur * 100
|
||||
|
||||
return {
|
||||
'page_title': u"Mes actifs",
|
||||
'url': url,
|
||||
'items': items,
|
||||
'message': message,
|
||||
'total_valeur': total_valeur,
|
||||
'total_pv': total_pv,
|
||||
'total_pc_value': total_pc_value,
|
||||
}
|
||||
|
||||
|
||||
@view_config(route_name='actif_edit', renderer='../templates/actifs/actif_edit.pt', permission='view')
|
||||
@@ -125,18 +45,21 @@ def actif_edit(request):
|
||||
actif = {}
|
||||
actif['no_id'] = '0'
|
||||
actif['symbole'] = ''
|
||||
actif['libelle'] = ''
|
||||
actif['classe'] = ''
|
||||
actif['devise'] = 'EUR'
|
||||
actif['nombre'] = '0'
|
||||
actif['pru'] = '0'
|
||||
actif['ter'] = '0'
|
||||
actif['pc_rdt'] = '0'
|
||||
actif['website'] = ''
|
||||
page_title= 'Nouvel actif ACTION'
|
||||
else:
|
||||
# lire la fiche du actif
|
||||
actif = get_actifs(request, no_id)
|
||||
if not actif:
|
||||
request.session.flash(u"Actif non trouvé : %s" % no_id, 'warning')
|
||||
return HTTPFound(location=request.route_url('actifs_list'))
|
||||
return HTTPFound(location=request.route_url('home'))
|
||||
page_title= u"Actif ACTION : %s" % (actif.libelle)
|
||||
|
||||
if 'form.submitted' in request.params:
|
||||
@@ -158,14 +81,14 @@ def actif_edit(request):
|
||||
|
||||
update_actif(request, no_id, new_values)
|
||||
request.session.flash(u"La fiche a été mise à jour avec succès.", 'success')
|
||||
return HTTPFound(location=request.route_url('actifs_list'))
|
||||
return HTTPFound(location=request.route_url('home'))
|
||||
else:
|
||||
message = 'Symbole inconnu. Veuillez ressaisir.'
|
||||
|
||||
if 'form.deleted' in request.params:
|
||||
delete_actif(request, no_id)
|
||||
request.session.flash(u"La fiche a été supprimée avec succès.", 'success')
|
||||
return HTTPFound(location=request.route_url('actifs_list'))
|
||||
return HTTPFound(location=request.route_url('home'))
|
||||
|
||||
return {
|
||||
'page_title': page_title,
|
||||
@@ -199,7 +122,7 @@ def actif2_edit(request):
|
||||
actif = get_actifs(request, no_id)
|
||||
if not actif:
|
||||
request.session.flash(u"Actif non trouvé : %s" % no_id, 'warning')
|
||||
return HTTPFound(location=request.route_url('actifs_list'))
|
||||
return HTTPFound(location=request.route_url('home'))
|
||||
page_title= u"Actif : %s" % (actif.symbole)
|
||||
|
||||
if 'form.submitted' in request.params:
|
||||
@@ -212,12 +135,12 @@ def actif2_edit(request):
|
||||
new_values['devise'] = 'EUR'
|
||||
update_actif(request, no_id, new_values)
|
||||
request.session.flash(u"La fiche a été mise à jour avec succès.", 'success')
|
||||
return HTTPFound(location=request.route_url('actifs_list'))
|
||||
return HTTPFound(location=request.route_url('home'))
|
||||
|
||||
if 'form.deleted' in request.params:
|
||||
delete_actif(request, no_id)
|
||||
request.session.flash(u"La fiche a été supprimée avec succès.", 'success')
|
||||
return HTTPFound(location=request.route_url('actifs_list'))
|
||||
return HTTPFound(location=request.route_url('home'))
|
||||
|
||||
return {
|
||||
'page_title': page_title,
|
||||
@@ -291,7 +214,6 @@ def allocation_edit(request):
|
||||
request.session.flash(u"La fiche a été mise à jour avec succès.", 'success')
|
||||
return HTTPFound(location=request.route_url('allocation_list'))
|
||||
|
||||
|
||||
if 'form.deleted' in request.params:
|
||||
delete_allocation(request, no_cat)
|
||||
request.session.flash(u"La fiche a été supprimée avec succès.", 'success')
|
||||
|
||||
@@ -12,23 +12,20 @@ from pyramid.httpexceptions import (
|
||||
)
|
||||
from pyramid_mailer import get_mailer
|
||||
from pyramid_mailer.message import Message, Attachment
|
||||
from datetime import *
|
||||
import hashlib
|
||||
from docutils.core import publish_parts
|
||||
|
||||
from sqlalchemy.exc import DBAPIError
|
||||
from ..security import groupfinder
|
||||
|
||||
from ..models.default import *
|
||||
from ..models.actifs import (
|
||||
get_actifs,
|
||||
get_allocation,
|
||||
get_histo,
|
||||
)
|
||||
from ..models.actifs import *
|
||||
from ..models.members import (
|
||||
get_member_by_email,
|
||||
)
|
||||
|
||||
# import datetime
|
||||
import time
|
||||
import hashlib
|
||||
import json
|
||||
|
||||
def to_decimal(x):
|
||||
@@ -76,6 +73,7 @@ def to_percent(x, d):
|
||||
def home(request):
|
||||
logged_in = request.authenticated_userid
|
||||
member = get_member_by_email(request, logged_in)
|
||||
url = request.route_url('home')
|
||||
|
||||
message = ''
|
||||
|
||||
@@ -98,6 +96,25 @@ def home(request):
|
||||
# lire les actifs
|
||||
actifs = get_actifs(request, '0')
|
||||
|
||||
# MAJ du prtefeuille
|
||||
if 'form.submitted' in request.params:
|
||||
# maj des parités des devises d'après Yahoo finance
|
||||
update_actif_devise(request, 'USD', getCurrencyRate('USD'))
|
||||
|
||||
for item in actifs:
|
||||
if item.type == 'ACTION':
|
||||
# get yahoo price
|
||||
quote_price = getYahooQuote(item.symbole)
|
||||
if quote_price:
|
||||
update_actif_valeur(request, item.symbole, quote_price['Close'])
|
||||
time.sleep(2) # attendre 2 secondes
|
||||
|
||||
# update du portefeuille
|
||||
update_portefeuille(request, logged_in)
|
||||
# relire les actifs
|
||||
actifs = get_actifs(request, '0')
|
||||
message = u'Le portefeuille est mis à jour avec succès.'
|
||||
|
||||
total_valeur = 0
|
||||
total_pv = 0
|
||||
total_rdt = 0
|
||||
@@ -120,6 +137,7 @@ def home(request):
|
||||
return {
|
||||
'page_title': u"Allocation d'actifs",
|
||||
'message': message,
|
||||
'url': url,
|
||||
'items': items,
|
||||
'member': member,
|
||||
'donut_cible': json.dumps(donut_cible),
|
||||
|
||||
Reference in New Issue
Block a user