added historique
This commit is contained in:
BIN
cao_blogr - Copie.sqlite
Normal file
BIN
cao_blogr - Copie.sqlite
Normal file
Binary file not shown.
BIN
cao_blogr.sqlite
BIN
cao_blogr.sqlite
Binary file not shown.
81
cao_blogr/alembic/versions/20230123_19d939dbc6d0.py
Normal file
81
cao_blogr/alembic/versions/20230123_19d939dbc6d0.py
Normal file
@@ -0,0 +1,81 @@
|
||||
"""add portfolio tables
|
||||
|
||||
Revision ID: 19d939dbc6d0
|
||||
Revises: 7995372bd306
|
||||
Create Date: 2023-01-23 14:49:31.713228
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '19d939dbc6d0'
|
||||
down_revision = '7995372bd306'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('actifs',
|
||||
sa.Column('no_id', sa.Integer(), nullable=False),
|
||||
sa.Column('symbole', sa.Unicode(length=45), nullable=False),
|
||||
sa.Column('libelle', sa.Unicode(length=45), nullable=False),
|
||||
sa.Column('classe', sa.Unicode(length=45), nullable=False),
|
||||
sa.Column('nombre', sa.Integer(), nullable=True),
|
||||
sa.Column('cours', sa.Float(), nullable=True),
|
||||
sa.Column('pru', sa.Float(), nullable=True),
|
||||
sa.Column('valeur', sa.Float(), nullable=True),
|
||||
sa.Column('plus_value', sa.Float(), nullable=True),
|
||||
sa.Column('pc_plusvalue', sa.Float(), nullable=True),
|
||||
sa.Column('rendement', sa.Float(), nullable=True),
|
||||
sa.Column('pc_rdt', sa.Float(), nullable=True),
|
||||
sa.Column('pc_allocation', sa.Float(), nullable=True),
|
||||
sa.Column('ter', sa.Float(), nullable=True),
|
||||
sa.Column('ter_pondere', sa.Float(), nullable=True),
|
||||
sa.Column('devise', sa.Unicode(length=45), nullable=True),
|
||||
sa.Column('parite', sa.Float(), nullable=True),
|
||||
sa.Column('website', sa.Unicode(length=100), nullable=True),
|
||||
sa.Column('modif_le', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('no_id', name=op.f('pk_actifs')),
|
||||
sa.UniqueConstraint('symbole', name=op.f('uq_actifs_symbole'))
|
||||
)
|
||||
op.create_index('symbole_index', 'actifs', ['symbole'], unique=False)
|
||||
op.create_table('allocation',
|
||||
sa.Column('no_cat', sa.Integer(), nullable=False),
|
||||
sa.Column('classe', sa.Unicode(length=45), nullable=False),
|
||||
sa.Column('pc_cible', sa.Integer(), nullable=True),
|
||||
sa.Column('pc_atteint', sa.Float(), nullable=True),
|
||||
sa.Column('valeur', sa.Float(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('no_cat', name=op.f('pk_allocation'))
|
||||
)
|
||||
op.create_table('classes',
|
||||
sa.Column('classe', sa.Unicode(), nullable=False),
|
||||
sa.Column('type', sa.Unicode(length=45), nullable=True),
|
||||
sa.Column('ordre', sa.Integer(), nullable=True),
|
||||
sa.Column('bg_color', sa.Unicode(length=45), nullable=True),
|
||||
sa.PrimaryKeyConstraint('classe', name=op.f('pk_classes'))
|
||||
)
|
||||
op.create_index('ordre_index', 'classes', ['ordre'], unique=False)
|
||||
op.create_table('histo',
|
||||
sa.Column('no_id', sa.Integer(), nullable=False),
|
||||
sa.Column('date', sa.DateTime(), nullable=True),
|
||||
sa.Column('mvt_cash', sa.Float(), nullable=True),
|
||||
sa.Column('valeur_pf', sa.Float(), nullable=True),
|
||||
sa.Column('nb_part', sa.Float(), nullable=True),
|
||||
sa.Column('val_part', sa.Float(), nullable=True),
|
||||
sa.Column('cours_ref', sa.Float(), nullable=True),
|
||||
sa.Column('val_part_ref', sa.Float(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('no_id', name=op.f('pk_histo'))
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('histo')
|
||||
op.drop_index('ordre_index', table_name='classes')
|
||||
op.drop_table('classes')
|
||||
op.drop_table('allocation')
|
||||
op.drop_index('symbole_index', table_name='actifs')
|
||||
op.drop_table('actifs')
|
||||
# ### end Alembic commands ###
|
||||
26
cao_blogr/alembic/versions/20230123_7995372bd306.py
Normal file
26
cao_blogr/alembic/versions/20230123_7995372bd306.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""add portfolio tables
|
||||
|
||||
Revision ID: 7995372bd306
|
||||
Revises: fe8f8a5bfdb5
|
||||
Create Date: 2023-01-23 14:43:22.632056
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '7995372bd306'
|
||||
down_revision = 'fe8f8a5bfdb5'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
@@ -1,8 +1,8 @@
|
||||
"""init
|
||||
"""add portfolio tables
|
||||
|
||||
Revision ID: a632e375e7dc
|
||||
Revision ID: fe8f8a5bfdb5
|
||||
Revises:
|
||||
Create Date: 2023-01-21 11:25:48.517435
|
||||
Create Date: 2023-01-23 14:42:10.171291
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
@@ -10,17 +10,17 @@ import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'a632e375e7dc'
|
||||
revision = 'fe8f8a5bfdb5'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('entries', 'author')
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('entries', sa.Column('author', sa.VARCHAR(length=50), nullable=True))
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
@@ -7,6 +7,7 @@ import zope.sqlalchemy
|
||||
# Base.metadata prior to any initialization routines
|
||||
from .user import User
|
||||
from .blog_record import BlogRecord
|
||||
from .portfolio import Actifs
|
||||
|
||||
# run configure_mappers after defining all of the models to ensure
|
||||
# all relationships can be setup
|
||||
|
||||
63
cao_blogr/models/portfolio.py
Normal file
63
cao_blogr/models/portfolio.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import datetime #<- will be used to set default dates on models
|
||||
from cao_blogr.models.meta import Base #<- we need to import our sqlalchemy metadata from which model classes will inherit
|
||||
from sqlalchemy import (
|
||||
Column,
|
||||
Integer,
|
||||
Float,
|
||||
Unicode, #<- will provide Unicode field
|
||||
UnicodeText, #<- will provide Unicode text field
|
||||
DateTime, #<- time abstraction field
|
||||
Index,
|
||||
ForeignKey,
|
||||
)
|
||||
|
||||
|
||||
class Actifs(Base):
|
||||
__tablename__ = 'actifs'
|
||||
no_id = Column(Integer, primary_key=True)
|
||||
symbole = Column(Unicode(45), unique=True, nullable=False)
|
||||
libelle = Column(Unicode(45), nullable=False)
|
||||
classe = Column(Unicode(45), nullable=False)
|
||||
nombre = Column(Integer)
|
||||
cours = Column(Float)
|
||||
pru = Column(Float)
|
||||
valeur = Column(Float)
|
||||
plus_value = Column(Float)
|
||||
pc_plusvalue = Column(Float)
|
||||
rendement = Column(Float)
|
||||
pc_rdt = Column(Float)
|
||||
pc_allocation = Column(Float)
|
||||
ter = Column(Float)
|
||||
ter_pondere = Column(Float)
|
||||
devise = Column(Unicode(45), default='EUR')
|
||||
parite = Column(Float)
|
||||
website = Column(Unicode(100))
|
||||
modif_le = Column(DateTime, default=datetime.datetime.utcnow)
|
||||
__table_args__ = (Index('symbole_index', 'symbole'),)
|
||||
|
||||
class Allocation(Base):
|
||||
__tablename__ = 'allocation'
|
||||
no_cat = Column(Integer, primary_key=True)
|
||||
classe = Column(Unicode(45), nullable=False)
|
||||
pc_cible = Column(Integer)
|
||||
pc_atteint = Column(Float)
|
||||
valeur = Column(Float)
|
||||
|
||||
class Classes(Base):
|
||||
__tablename__ = 'classes'
|
||||
classe = Column(Unicode, primary_key=True)
|
||||
type = Column(Unicode(45), default='ACTION')
|
||||
ordre = Column(Integer)
|
||||
bg_color = Column(Unicode(45))
|
||||
__table_args__ = (Index('ordre_index', 'ordre'),)
|
||||
|
||||
class Histo(Base):
|
||||
__tablename__ = 'histo'
|
||||
no_id = Column(Integer, primary_key=True)
|
||||
date = Column(DateTime, default=datetime.datetime.utcnow)
|
||||
mvt_cash = Column(Float)
|
||||
valeur_pf = Column(Float)
|
||||
nb_part = Column(Float)
|
||||
val_part = Column(Float)
|
||||
cours_ref = Column(Float)
|
||||
val_part_ref = Column(Float)
|
||||
@@ -12,3 +12,10 @@ def includeme(config):
|
||||
config.add_route('users', '/users')
|
||||
config.add_route('user_add', '/user_add/{name}')
|
||||
config.add_route('user_pwd', '/user_pwd/{name}')
|
||||
# portfolio
|
||||
config.add_route('actif_edit', '/actif_edit/{no_id}')
|
||||
config.add_route('actif2_edit', '/actif2_edit/{no_id}')
|
||||
config.add_route('allocation_edit', '/allocation_edit/{no_cat}')
|
||||
config.add_route('histo_list', '/histo_list')
|
||||
config.add_route('histo_edit', '/histo_edit/{no_id}')
|
||||
config.add_route('portfolio', '/portfolio')
|
||||
|
||||
15
cao_blogr/services/portfolio.py
Normal file
15
cao_blogr/services/portfolio.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import sqlalchemy as sa
|
||||
from ..models.portfolio import Histo
|
||||
|
||||
|
||||
class PFService(object):
|
||||
|
||||
@classmethod
|
||||
def get_histo(cls, request, no_id):
|
||||
if no_id == '0':
|
||||
items = request.dbsession.query(Histo).order_by(sa.asc(Histo.date)).all()
|
||||
else:
|
||||
# lire le histo par le no_id
|
||||
items = request.dbsession.query(Histo).filter(Histo.id == id).first()
|
||||
return items
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="content">
|
||||
<h1><span class="font-semi-bold">Pyramid</span> <span class="smaller">Starter project</span></h1>
|
||||
<h1><span class="font-semi-bold">CAO Blog</span></h1>
|
||||
<p class="lead"><span class="font-semi-bold">404</span> Page Not Found</p>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
{% if request.authenticated_userid == 'admin' %}
|
||||
<li><a href="{{request.route_url('users')}}"><span class="glyphicon glyphicon-user"></span> Utilisateurs</a></li>
|
||||
{% endif %}
|
||||
<li><a href="{{ request.route_url('portfolio') }}"><span class="glyphicon glyphicon-briefcase"></span> Portfolio</a></li>
|
||||
<li><a href="{{ request.route_url('tags') }}"><span class="glyphicon glyphicon-tag"></span> Tags</a></li>
|
||||
<li><a href="{{ request.route_url('logout') }}"><span class="glyphicon glyphicon-off"></span> Se déconnecter</a></li>
|
||||
</ul>
|
||||
|
||||
67
cao_blogr/templates/portfolio/histo_edit.jinja2
Normal file
67
cao_blogr/templates/portfolio/histo_edit.jinja2
Normal file
@@ -0,0 +1,67 @@
|
||||
<div metal:use-macro="load: ../global_layout.pt">
|
||||
<div metal:fill-slot="content">
|
||||
|
||||
<div tal:condition="message" tal:content="message" class="alert alert-danger" />
|
||||
<br />
|
||||
<div class="row">
|
||||
<form id="histo_edit-form" class="form-horizontal" action="${url}" method="post" tal:condition="item"
|
||||
data-fv-framework="bootstrap"
|
||||
data-fv-icon-valid="glyphicon glyphicon-ok"
|
||||
data-fv-icon-invalid="glyphicon glyphicon-remove"
|
||||
data-fv-icon-validating="glyphicon glyphicon-refresh">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-xs-2 control-label">Date</label>
|
||||
<div class="col-xs-2">
|
||||
<p class="form-control-static"><b>${item.date.strftime('%d-%m-%Y')}</b></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-2" for="mvt_cash">Montant cash</label>
|
||||
<div class="col-xs-2">
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon">€</div>
|
||||
<input class="form-control" type="text" id="mvt_cash" name="mvt_cash" value="${item.mvt_cash}"
|
||||
data-fv-numeric="true"
|
||||
data-fv-numeric-message="Le montant doit être composé de chiffres ou de ., +, -" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-xs-2 control-label">Nombre part</label>
|
||||
<div class="col-xs-2">
|
||||
<p class="form-control-static"><b>${item.nb_part}</b></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
<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}/histo_list">
|
||||
<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>
|
||||
<button class="btn btn-warning" type="submit" name="form.deleted"
|
||||
tal:condition="item.no_id != 0">
|
||||
<span class="glyphicon glyphicon-remove"></span> Supprimer</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
</div> <!-- row -->
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#histo_edit-form').formValidation();
|
||||
$('form input').on('keypress', function(e) {
|
||||
return e.which !== 13;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
45
cao_blogr/templates/portfolio/histo_list.jinja2
Normal file
45
cao_blogr/templates/portfolio/histo_list.jinja2
Normal file
@@ -0,0 +1,45 @@
|
||||
{% extends "cao_blogr:templates/layout.jinja2" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<p><a href="{{ request.route_url('histo_edit', no_id='0') }}" class="btn btn-success" role="button">
|
||||
<span class="glyphicon glyphicon-plus"></span> Entrée / Sortie cash</a>
|
||||
</p>
|
||||
|
||||
<table id="histo_list" class="table table-striped table-bordered table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th align='right'>E/S Cash</th>
|
||||
<th align='right'>Valeur Pf</th>
|
||||
<th align='right'>Nb Part</th>
|
||||
<th align='right'>Valeur Part</th>
|
||||
<th align='right'>Cours ref</th>
|
||||
<th align='right'>Valeur Part ref</th>
|
||||
<th align='center'>No Id</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for item in items %}
|
||||
<tr>
|
||||
<td>{{ item.date.strftime('%d/%m/%Y') }}</td>
|
||||
<td align='right'>{{ item.mvt_cash }} €</td>
|
||||
<td align='right'>{{ item.valeur_pf }}</td>
|
||||
<td align='right'>{{ item.nb_part }}</td>
|
||||
<td align='right'>{{ item.val_part }}</td>
|
||||
<td align='right'>{{ item.nb_part_ref }}</td>
|
||||
<td align='right'>{{ item.val_part_ref }}</td>
|
||||
<td align='center'>
|
||||
<a href="{{ request.route_url('histo_edit', no_id=item.no_id) }}">{{ item.no_id }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ from ..forms import UserCreateForm
|
||||
from ..models.user import User
|
||||
|
||||
|
||||
@view_config(route_name='home',
|
||||
renderer='cao_blogr:templates/home.jinja2')
|
||||
@view_config(route_name='home', renderer='cao_blogr:templates/home.jinja2')
|
||||
def home(request):
|
||||
# get the last created posts
|
||||
last_ten = BlogRecordService.get_last_created(request)
|
||||
|
||||
return {
|
||||
'page_title': "Bienvenue sur mon blog",
|
||||
'last_ten': last_ten,
|
||||
|
||||
22
cao_blogr/views/portfolio.py
Normal file
22
cao_blogr/views/portfolio.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from pyramid.view import (
|
||||
view_config,
|
||||
forbidden_view_config,
|
||||
)
|
||||
from pyramid.httpexceptions import HTTPFound
|
||||
from pyramid.security import remember, forget
|
||||
from ..services.portfolio import PFService
|
||||
from ..forms import UserCreateForm
|
||||
from ..models.portfolio import Histo
|
||||
|
||||
|
||||
@view_config(route_name='histo_list', renderer='../templates/portfolio/histo_list.jinja2', permission='view')
|
||||
def histo_list(request):
|
||||
# lire l historique
|
||||
items = PFService.get_histo(request, '0')
|
||||
|
||||
return {
|
||||
'page_title': 'Historique',
|
||||
'items': items,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user