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

Add markdown rendering #172

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe

## [Unreleased]
### Added
- markdown rendering
- link to changelog in docs panel
- progress bar to show simulation state
- WMS layers flurstuecke and ertragspotenzial
Expand Down
10 changes: 10 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"rest_framework",
"django_distill",
"template_partials",
"markdownify.apps.MarkdownifyConfig",
]

LOCAL_APPS = ["digiplan.map.apps.MapConfig", "django_oemof", "django_mapengine"]
Expand Down Expand Up @@ -266,6 +267,15 @@ def __getitem__(self, item): # noqa: D105, ANN001, ANN204
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"

MARKDOWNIFY = {
"default": {
"BLEACH": False,
"MARKDOWN_EXTENSIONS": [
"markdown.extensions.extra",
],
},
}

OEMOF_SCENARIO = env.str("OEMOF_SCENARIO", "scenario_2045")

# django-mapengine
Expand Down
3 changes: 3 additions & 0 deletions digiplan/map/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
ADDITIONAL_TRAFFIC_SETTINGS_FILE = settings.DATA_DIR.path("digipipe/settings/traffic_settings_panel.json")
TECHNOLOGY_DATA_FILE = settings.DIGIPIPE_DIR.path("scalars").path("technology_data.json")

# MARKDOWNS
LANDING_PAGE_MD = utils.read_file(settings.APPS_DIR.path("static/markdown/landing_page.md"))

# FILTERS
FILTER_DEFINITION = {}
REGION_FILTER_LAYERS = []
Expand Down
6 changes: 6 additions & 0 deletions digiplan/map/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
from django.template.context import make_context


def read_file(filename: str) -> str:
"""Read file."""
with pathlib.Path(filename).open("r", encoding="utf-8") as f:
return f.read()


def get_translated_json_from_file(json_filename: str, request: HttpRequest = None) -> dict:
"""
Render JSON using translations.
Expand Down
1 change: 1 addition & 0 deletions digiplan/map/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MapGLView(TemplateView, views.MapEngineMixin):
"pv_map_control": _("Negativkriterien PV"),
"store_hot_init": config.STORE_HOT_INIT,
"oemof_scenario": settings.OEMOF_SCENARIO,
"markdown": {"landing_page": config.LANDING_PAGE_MD},
}

def get_context_data(self, **kwargs) -> dict:
Expand Down
15 changes: 15 additions & 0 deletions digiplan/static/markdown/landing_page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Test

This is a test list:

* a
* b
* c
* d
* holla

| Month | Savings |
| -------- | ------- |
| January | $250 |
| February | $80 |
| March | $420 |
20 changes: 2 additions & 18 deletions digiplan/templates/components/map.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load static i18n %}
{% load static i18n markdownify %}

{% include "components/onboarding.html" %}

Expand All @@ -23,23 +23,7 @@ <h1 class="modal-title fs-5 fw-bold ps-1" id="goalModalLabel">Ziele</h1>
<div id="onboarding_wind_chart" class="onboarding__chart" style="width: 448px; height: 320px;"></div>
</div>
<div class="challenges-modal__text">
Hier folgt noch Text zu diesen Punkten:
<ul>
<li>Vom Großen ins Kleine</li>
<li>Klimaziele und EE-Ziele Deutschland</li>
<li>Energiestrategie Brandenburg und Regionales Energiekonzept OLS</li>
<li>Stand Ausbau Wind & PV</li>
<li>Tool beleuchtet ausgewählte Aspekte, Beispiele</li>
<li>Beispielhafte Fragen aus Präsi:
<ul>
<li>Wie viel Energie kann auf den geplanten Windvorranggebieten "geerntet" werden?</li>
<li>Und wie viel mit Aufdach- und Agri-Photovoltaik?</li>
<li>Genügt das, um den zukünftigen Energiebedarf der Region zu decken, auch den der Wärmepumpen und Elektroautos?</li>
<li>Bis zu welchem Grad kann Oderland-Spree energetisch unabhängig werden?</li>
<li>Wie passt das zur Brandenburger Energiestrategie 2040?</li>
</ul>
</li>
</ul>
{{ markdown.landing_page | markdownify }}
</div>
</div>
<div class="challenges-modal">
Expand Down
83 changes: 82 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ geojson = "^3.0.1"
oemof-network = "0.5.0a5"
django-template-partials = "^23.4"
django-cache-memoize = "^0.2.0"
django-markdownify = "^0.9.5"

[tool.poetry.group.dev.dependencies]
Werkzeug = "^2.0.1" # https://github.com/pallets/werkzeug
Expand Down