From 75808d6d20e32aba3486b13a694f89bf09894a38 Mon Sep 17 00:00:00 2001 From: crflynn Date: Mon, 13 Aug 2018 22:06:47 -0400 Subject: [PATCH] move plot declarations to app config --- pypistats/settings.py | 10 ++++++++++ pypistats/views/general.py | 13 ++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pypistats/settings.py b/pypistats/settings.py index 190f12f..b5f8e4a 100644 --- a/pypistats/settings.py +++ b/pypistats/settings.py @@ -2,6 +2,7 @@ import os from celery.schedules import crontab +from flask import json def get_db_uri(env): @@ -34,6 +35,15 @@ class Config(object): SECRET_KEY = os.environ.get("PYPISTATS_SECRET", "secret-key") SQLALCHEMY_TRACK_MODIFICATIONS = False + # Plotly chart definitions + PLOT_BASE = json.load( + open(os.path.join(os.path.dirname(__file__), "plots", "plot_base.json")) + ) + DATA_BASE = json.load( + open(os.path.join(os.path.dirname(__file__), "plots", "data_base.json")) + ) + + class ProdConfig(Config): """Production configuration.""" diff --git a/pypistats/views/general.py b/pypistats/views/general.py index e3b466d..65b1684 100644 --- a/pypistats/views/general.py +++ b/pypistats/views/general.py @@ -33,15 +33,6 @@ MODELS = [ ] -# Plotly chart definitions -PLOT_BASE = json.load( - open(os.path.join(current_app.root_path, 'plots', 'plot_base.json')) -) -DATA_BASE = json.load( - open(os.path.join(current_app.root_path, 'plots', 'data_base.json')) -) - - class MyForm(FlaskForm): """Search form.""" @@ -128,10 +119,10 @@ def package(package): # Build the plots plots = [] for model in model_data: - plot = deepcopy(PLOT_BASE) + plot = deepcopy(current_app.config["PLOT_BASE"]) data = [] for category, values in model["data"].items(): - base = deepcopy(DATA_BASE["data"][0]) + base = deepcopy(current_app.config["DATA_BASE"]["data"][0]) base["x"] = values["x"] base["y"] = values["y"] base["name"] = category.title()