Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fusion databases #204

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
18 changes: 0 additions & 18 deletions crdppf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@

db_config = 'to_overwrite'

# GET THE INITIAL CONFIGURATION FROM THE DB
def read_app_config(settings):
"""
Read the initial app config
"""
from crdppf.models import DBSession, Base
from crdppf.models.models import AppConfig
results = {}
results = DBSession.query(AppConfig).all()

for result in results :
settings['app_config'].update({str(result.parameter):str(result.paramvalue)})

return True

# INCLUDE THE CORE CONFIGURATION AND CREATE THE APPLICATION
def includeme(config):
""" This function returns a Pyramid WSGI application.
Expand All @@ -55,9 +40,6 @@ def includeme(config):
engine = engine_from_config(settings, 'sqlalchemy.')
init_model(engine)

# add app configuration from db
read_app_config(settings)

config.include(papyrus.includeme)
config.include('pyramid_mako')
# bind the mako renderer to other file extensions
Expand Down
21 changes: 13 additions & 8 deletions crdppf/lib/cached_content.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: UTF-8 -*-

from pyramid.exceptions import ConfigurationError
from dogpile.cache.region import make_region

cache_region = make_region()
cache_region.configure("dogpile.cache.memory")

from crdppf.models import DBSession

from crdppf.models.models import AppConfig, Translations, Glossar
from crdppf.models.models import Translations, Glossar
from crdppf.models.models import Informations, ExclusionsResponsabilite

import logging
Expand All @@ -20,26 +20,31 @@ def get_cached_content(request):

d = {}

canton_logo = DBSession.query(AppConfig).filter_by(parameter='cantonlogopath').first()
ch_logo = DBSession.query(AppConfig).filter_by(parameter='CHlogopath').first()
crdppf_logo = DBSession.query(AppConfig).filter_by(parameter='crdppflogopath').first()
if request.registry.settings['pdf_config']:
settings = request.registry.settings['pdf_config']
else:
raise ConfigurationError('Missing mandatory configuration settings for the application to work.')

canton_logo = settings['cantonlogo']['path']
ch_logo = settings['CHlogopath']
crdppf_logo = settings['crdppflogopath']

d['canton_logo'] = '/'.join([
request.registry.settings['localhost_url'],
'proj/images',
canton_logo.paramvalue
canton_logo
])

d['ch_logo'] = '/'.join([
request.registry.settings['localhost_url'],
'proj/images',
ch_logo.paramvalue
ch_logo
])

d['crdppf_logo'] = '/'.join([
request.registry.settings['localhost_url'],
'proj/images',
crdppf_logo.paramvalue
crdppf_logo
])

return d
Expand Down
9 changes: 4 additions & 5 deletions crdppf/lib/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from crdppf.util.pdf_functions import get_feature_info, get_translations

from crdppf.models import DBSession
from crdppf.models.models import Topics, AppConfig
from crdppf.models.models import Topics

from geoalchemy2.shape import to_shape, WKTElement
import logging
Expand Down Expand Up @@ -162,7 +162,7 @@ def get_content(id, request):
"""
# Start a session
session = request.session
configs = DBSession.query(AppConfig).all()
configs = request.registry.settings['app_config']

# initalize extract object
extract = Extract(request)
Expand All @@ -171,9 +171,8 @@ def get_content(id, request):
if type == 'file':
type = 'reduced'
directprint = True
for config in configs:
if config.parameter not in ['crdppflogopath', 'cantonlogopath']:
extract.baseconfig[config.parameter] = config.paramvalue
for config in configs.keys():
extract.baseconfig[config] = configs[config]
extract.srid = db_config['srid']

extract.topiclegenddir = request.static_url('crdppfportal:static/public/legend/')
Expand Down
Loading