creer to_percent(x, d)

This commit is contained in:
2017-07-26 19:11:18 +02:00
parent 52949ec15b
commit 156b5093a5
5 changed files with 25 additions and 15 deletions

View File

@@ -23,8 +23,8 @@ class GlobalLayout(object):
def to_euro(self, x):
return to_euro(x)
def to_percent(self, x):
return to_percent(x)
def to_percent(self, x, d):
return to_percent(x, d)
def isAnonymous(self):
user = authenticated_userid(self.request)

View File

@@ -32,7 +32,7 @@
<div class="col-md-4">
<table class="table table-condensed table-striped table-bordered">
<tr>
<th class=text-center"">MAISON</th>
<th class="text-center">MAISON</th>
</tr>
<tr tal:repeat="ligne docs_maison">

View File

@@ -20,9 +20,9 @@
<tr tal:repeat="item items">
<td class="${item.bg_color}">${item.classe}</td>
<td class="text-right">${item.pc_cible} %</td>
<td class="text-right">${layout.to_percent(item.pc_atteint)}</td>
<td tal:condition="(item.pc_atteint - item.pc_cible)>=0" class="text-right" style="color: green;">${layout.to_percent(item.pc_atteint - item.pc_cible)}</td>
<td tal:condition="(item.pc_atteint - item.pc_cible) <0" class="text-right" style="color: red;">${layout.to_percent(item.pc_atteint - item.pc_cible)}</td>
<td class="text-right">${layout.to_percent(item.pc_atteint,1)}</td>
<td tal:condition="(item.pc_atteint - item.pc_cible)>=0" class="text-right" style="color: green;">${layout.to_percent(item.pc_atteint - item.pc_cible,1)}</td>
<td tal:condition="(item.pc_atteint - item.pc_cible) <0" class="text-right" style="color: red;">${layout.to_percent(item.pc_atteint - item.pc_cible,1)}</td>
<td class="text-right">${layout.to_euro(item.valeur)}</td>
</tr>
</tbody>
@@ -45,7 +45,7 @@
<th class="text-right">% de +/-</th>
<th class="text-right">% PF</th>
<th class="text-right">TER</th>
<th class="text-right">Rendement</th>
<th class="text-right">Rdt</th>
</tr>
</thead>
<tbody>
@@ -55,17 +55,17 @@
<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)}</td>
<td tal:condition="ligne.pc_plusvalue <0" class="text-right" style="color: red;">${layout.to_percent(ligne.pc_plusvalue)}</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 class="text-right">${layout.to_percent(ligne.ter)}</td>
<td class="text-right">${layout.to_percent(ligne.rdt)}</td>
<td class="text-right">${layout.to_percent(ligne.ter,2)}</td>
<td class="text-right">${layout.to_percent(ligne.rdt,1)}</td>
</tr>
<tr>
<td colspan="2"></td>
<td class="text-right">${layout.to_euro(total_valeur)}</td>
<td class="text-right">${layout.to_euro(total_pv)}</td>
<td class="text-right">${layout.to_percent(total_pc_value)}</td>
<td class="text-right">${layout.to_percent(total_pc_value,1)}</td>
<td class="text-right">100 %</td>
<td colspan="2"></td>
</tr>

View File

@@ -56,8 +56,8 @@
<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}/doc_list">DOCS</a></li>
<li><a href="${request.application_url}/histo_list">HISTORIQUE</a></li>
<li><a href="${request.application_url}/doc_list">DOCS</a></li>
${panel('dropdown_menu_panel')}
</ul>
</div>

View File

@@ -62,9 +62,19 @@ def to_int(x):
except ValueError:
return 0
def to_percent(x):
def to_percent(x, d):
"""Takes a float and returns a string"""
return (u"%.1f " % x).replace('.', ',') + "%"
if x == 0:
pc = ''
elif d == 2:
pc = u"%.2f " % x
elif d == 3:
pc = u"%.3f " % x
else:
pc = u"%.1f " % x
if len(pc) > 0:
pc += "%"
return pc.replace('.', ',')
@view_config(route_name='home', renderer='../templates/home.pt', permission='view')