Commit 8a9e695f by Nicolas Joyard

Ajout URL pdf amendements + reinit db

parent de7905ff
......@@ -38,7 +38,6 @@ $ psql -c "create database parlapi with owner parlapi;"
### Utilisation
```bash
$ parlapi createdb
$ parlapi db upgrade
$ parlapi update_amo_an
$ parlapi runserver
......
"""Maj trigger TS amendements
Revision ID: 14e3a8ca0ec4
Revises: 0c154fdc1261
Create Date: 2017-04-15 07:56:45.263214
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '14e3a8ca0ec4'
down_revision = '0c154fdc1261'
branch_labels = None
depends_on = None
def upgrade():
conn = op.get_bind()
conn.execute("""
CREATE OR REPLACE FUNCTION public.amendements_search_vector_update ()
RETURNS trigger
LANGUAGE plpgsql
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100
AS $$
BEGIN
NEW.search_vector = (((
to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.numero_long, ''), '[-@.]', ' ', 'g'))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.corps_expose, ''), '[-@.]', ' ', 'g')))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.corps_dispositif, ''), '[-@.]', ' ', 'g')))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.code_loi, ''), '[-@.]', ' ', 'g')))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.code_loi_division, ''), '[-@.]', ' ', 'g'))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.auteur_texte_affichable, ''), '[-@.]', ' ', 'g'));
RETURN NEW;
END
$$;
ALTER FUNCTION public.amendements_search_vector_update() OWNER TO parlapi;
""")
def downgrade():
conn = op.get_bind()
conn.execute("""
CREATE OR REPLACE FUNCTION public.amendements_search_vector_update ()
RETURNS trigger
LANGUAGE plpgsql
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100
AS $$
BEGIN
NEW.search_vector = (((
to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.numero_long, ''), '[-@.]', ' ', 'g'))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.corps_expose, ''), '[-@.]', ' ', 'g')))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.corps_dispositif, ''), '[-@.]', ' ', 'g')))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.code_loi, ''), '[-@.]', ' ', 'g')))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.code_loi_division, ''), '[-@.]', ' ', 'g'));
RETURN NEW;
END
$$;
ALTER FUNCTION public.amendements_search_vector_update() OWNER TO parlapi;
""")
"""empty message
"""Ajout amendement.url_pdf
Revision ID: 0c154fdc1261
Revises: 9312f57cabaf
Create Date: 2017-04-04 16:21:03.069577
Revision ID: 44148b36c11f
Revises: 511f685c2fc2
Create Date: 2017-06-22 18:34:22.235447
"""
from alembic import op
......@@ -10,19 +10,19 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '0c154fdc1261'
down_revision = '9312f57cabaf'
revision = '44148b36c11f'
down_revision = '511f685c2fc2'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('amendements', sa.Column('auteur_texte_affichable', sa.Unicode(), nullable=True))
op.add_column('an_amendements', sa.Column('url_pdf', sa.Unicode(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('amendements', 'auteur_texte_affichable')
op.drop_column('an_amendements', 'url_pdf')
# ### end Alembic commands ###
"""Separation tables
Revision ID: 511f685c2fc2
Revises: 14e3a8ca0ec4
Create Date: 2017-04-15 09:17:42.698269
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '511f685c2fc2'
down_revision = '14e3a8ca0ec4'
branch_labels = None
depends_on = None
def upgrade():
op.rename_table('actes', 'an_actes')
op.rename_table('acteurs', 'an_acteurs')
op.rename_table('acteurs_amendements', 'an_acteurs_amendements')
op.rename_table('acteurs_documents', 'an_acteurs_documents')
op.rename_table('acteurs_dossiers', 'an_acteurs_dossiers')
op.rename_table('acteurs_reunions', 'an_acteurs_reunions')
op.rename_table('amendements', 'an_amendements')
op.rename_table('documents', 'an_documents')
op.rename_table('documents_themes', 'an_documents_themes')
op.rename_table('dossiers', 'an_dossiers')
op.rename_table('jobs', 'parlapi_jobs')
op.rename_table('legislatures', 'an_legislatures')
op.rename_table('mandats', 'an_mandats')
op.rename_table('mandats_organes', 'an_mandats_organes')
op.rename_table('odjitems', 'an_odjitems')
op.rename_table('odjpoints', 'an_odjpoints')
op.rename_table('odjpoints_dossiers', 'an_odjpoints_dossiers')
op.rename_table('organes', 'an_organes')
op.rename_table('organes_documents', 'an_organes_documents')
op.rename_table('organes_dossiers', 'an_organes_dossiers')
op.rename_table('organes_reunions', 'an_organes_reunions')
op.rename_table('regimes', 'an_regimes')
op.rename_table('reunions', 'an_reunions')
op.rename_table('scrutins', 'an_scrutins')
op.rename_table('scrutins_groupes', 'an_scrutins_groupes')
op.rename_table('themes', 'an_themes')
op.rename_table('votants', 'an_votants')
def downgrade():
op.rename_table('an_actes', 'actes')
op.rename_table('an_acteurs', 'acteurs')
op.rename_table('an_acteurs_amendements', 'acteurs_amendements')
op.rename_table('an_acteurs_documents', 'acteurs_documents')
op.rename_table('an_acteurs_dossiers', 'acteurs_dossiers')
op.rename_table('an_acteurs_reunions', 'acteurs_reunions')
op.rename_table('an_amendements', 'amendements')
op.rename_table('an_documents', 'documents')
op.rename_table('an_documents_themes', 'documents_themes')
op.rename_table('an_dossiers', 'dossiers')
op.rename_table('an_legislatures', 'legislatures')
op.rename_table('an_mandats', 'mandats')
op.rename_table('an_mandats_organes', 'mandats_organes')
op.rename_table('an_odjitems', 'odjitems')
op.rename_table('an_odjpoints', 'odjpoints')
op.rename_table('an_odjpoints_dossiers', 'odjpoints_dossiers')
op.rename_table('an_organes', 'organes')
op.rename_table('an_organes_documents', 'organes_documents')
op.rename_table('an_organes_dossiers', 'organes_dossiers')
op.rename_table('an_organes_reunions', 'organes_reunions')
op.rename_table('an_regimes', 'regimes')
op.rename_table('an_reunions', 'reunions')
op.rename_table('an_scrutins', 'scrutins')
op.rename_table('an_scrutins_groupes', 'scrutins_groupes')
op.rename_table('an_themes', 'themes')
op.rename_table('an_votants', 'votants')
op.rename_table('parlapi_jobs', 'jobs')
"""empty message
Revision ID: 55c1e64eaf9f
Revises:
Create Date: 2017-03-21 11:38:18.839895
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '55c1e64eaf9f'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('documents', sa.Column('notice_numero', sa.Unicode(), nullable=True))
conn = op.get_bind()
conn.execute("""
CREATE OR REPLACE FUNCTION public.documents_search_vector_update()
RETURNS trigger AS
$BODY$
BEGIN
NEW.search_vector =
(
(
(
(
(
(
to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.titre, ''), '[-@.]', ' ', 'g'))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.type_code, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.type_libelle, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.soustype_code, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.soustype_libelle, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.statut_adoption, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.denomination_structurelle, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.notice_numero, ''), '[-@.]', ' ', 'g'))
;
RETURN NEW;
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION public.documents_search_vector_update()
OWNER TO parlapi;
""")
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
conn.execute("""
CREATE OR REPLACE FUNCTION public.documents_search_vector_update()
RETURNS trigger AS
$BODY$
BEGIN
NEW.search_vector =
(
(
(
(
(
to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.titre, ''), '[-@.]', ' ', 'g'))
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.type_code, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.type_libelle, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.soustype_code, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.soustype_libelle, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.statut_adoption, ''), '[-@.]', ' ', 'g'))
)
|| to_tsvector('pg_catalog.french', regexp_replace(coalesce(NEW.denomination_structurelle, ''), '[-@.]', ' ', 'g'))
;
RETURN NEW;
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION public.documents_search_vector_update()
OWNER TO parlapi;
""")
op.drop_column('documents', 'notice_numero')
# ### end Alembic commands ###
"""empty message
Revision ID: 9312f57cabaf
Revises: 55c1e64eaf9f
Create Date: 2017-03-30 14:56:51.669999
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '9312f57cabaf'
down_revision = '55c1e64eaf9f'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('acteurs_amendements',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('relation', sa.Unicode(), nullable=True),
sa.Column('acteur_id', sa.Unicode(), nullable=True),
sa.Column('amendement_id', sa.Unicode(), nullable=True),
sa.ForeignKeyConstraint(['acteur_id'], ['acteurs.id'], ),
sa.ForeignKeyConstraint(['amendement_id'], ['amendements.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('acteurs_amendements')
# ### end Alembic commands ###
......@@ -28,14 +28,6 @@ def runserver():
@manager.command
def createdb():
u'Crée le schéma BDD'
db.configure_mappers()
db.create_all()
@manager.command
@manager.option('-o', '--output', dest='output')
def erdiagram(output):
from eralchemy import render_er
......
......@@ -75,6 +75,15 @@ class ImportAmendementsJob(BaseANJob):
'auteur_texte_affichable': si['texteAffichable'],
}
if json.get('representations', None):
reps = json['representations']
if isinstance(rep, dict):
reps = [reps]
rep = reps[0]['representation']
if len(reps) and rep.get('nom', '') == 'PDF' and \
rep.get('contenu', {}).get('documentURI', None):
data['url_pdf'] = rep['contenu']['documentURI']
if json.get('amendementParent', None):
data['amendement_parent'] = \
self.save(Amendement, json['amendementParent'])
......
......@@ -382,6 +382,8 @@ class Amendement(db.Model):
auteur_texte_affichable = db.Column(db.Unicode)
url_pdf = db.Column(db.Unicode)
# TODO référence séance json['seanceDiscussion']
legislature_id = db.Column(db.Integer, db.ForeignKey('an_legislatures.id'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment