mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Add markdown support
This commit is contained in:
@@ -1,23 +1,4 @@
|
|||||||
import os
|
from dcc.utils import git_suffix
|
||||||
import subprocess
|
|
||||||
|
|
||||||
|
|
||||||
def git_suffix(fname):
|
|
||||||
"""
|
|
||||||
:returns: `<short git hash>` if Git repository found
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
gh = subprocess.check_output(
|
|
||||||
['git', 'rev-parse', '--short', 'HEAD'],
|
|
||||||
stderr=open(os.devnull, 'w')).strip()
|
|
||||||
gh = "-git" + gh.decode() if gh else ''
|
|
||||||
except Exception:
|
|
||||||
# trapping everything on purpose; git may not be installed or it
|
|
||||||
# may not work properly
|
|
||||||
gh = ''
|
|
||||||
|
|
||||||
return gh
|
|
||||||
|
|
||||||
|
|
||||||
__version__ = '0.0.1'
|
__version__ = '0.0.1'
|
||||||
__version__ += git_suffix(__file__)
|
__version__ += git_suffix(__file__)
|
||||||
|
@@ -18,21 +18,20 @@ from django.conf.urls.static import static
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
|
|
||||||
|
from portal.utils import get_site_conf
|
||||||
from portal.views import GetHome
|
from portal.views import GetHome
|
||||||
from consist import urls as consist_urls
|
|
||||||
from roster import urls as roster_urls
|
|
||||||
from driver import urls as driver_urls
|
|
||||||
|
|
||||||
admin.site.site_header = "Trains assets manager"
|
site_conf = get_site_conf()
|
||||||
|
admin.site.site_header = site_conf.site_name
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', GetHome.as_view(), name='index'),
|
path("", GetHome.as_view(), name="index"),
|
||||||
path('page/<int:page>', GetHome.as_view(), name='index_pagination'),
|
path("page/", include("portal.urls")),
|
||||||
path("ht/", include("health_check.urls")),
|
path("ht/", include("health_check.urls")),
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
path("api/v1/consist/", include(consist_urls)),
|
path("api/v1/consist/", include("consist.urls")),
|
||||||
path("api/v1/roster/", include(roster_urls)),
|
path("api/v1/roster/", include("roster.urls")),
|
||||||
path("api/v1/dcc/", include(driver_urls)),
|
path("api/v1/dcc/", include("driver.urls")),
|
||||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|
||||||
# if settings.DEBUG:
|
# if settings.DEBUG:
|
||||||
|
@@ -1,7 +1,27 @@
|
|||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from django.utils.text import slugify as django_slugify
|
from django.utils.text import slugify as django_slugify
|
||||||
|
|
||||||
|
|
||||||
|
def git_suffix(fname):
|
||||||
|
"""
|
||||||
|
:returns: `<short git hash>` if Git repository found
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
gh = subprocess.check_output(
|
||||||
|
['git', 'rev-parse', '--short', 'HEAD'],
|
||||||
|
stderr=open(os.devnull, 'w')).strip()
|
||||||
|
gh = "-git" + gh.decode() if gh else ''
|
||||||
|
except Exception:
|
||||||
|
# trapping everything on purpose; git may not be installed or it
|
||||||
|
# may not work properly
|
||||||
|
gh = ''
|
||||||
|
|
||||||
|
return gh
|
||||||
|
|
||||||
|
|
||||||
def get_image_preview(url):
|
def get_image_preview(url):
|
||||||
return format_html(
|
return format_html(
|
||||||
'<img src="%s" style="max-width: 150px; max-height: 150px;'
|
'<img src="%s" style="max-width: 150px; max-height: 150px;'
|
||||||
|
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 4.0.3 on 2022-04-09 21:01
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('portal', '0004_rename_footer_short_siteconfiguration_footer_extended_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='siteconfiguration',
|
||||||
|
name='homepage_content',
|
||||||
|
),
|
||||||
|
]
|
@@ -16,8 +16,6 @@ class SiteConfiguration(SingletonModel):
|
|||||||
(str(x * 3), str(x * 3)) for x in range(2, 11)],
|
(str(x * 3), str(x * 3)) for x in range(2, 11)],
|
||||||
default='6'
|
default='6'
|
||||||
)
|
)
|
||||||
|
|
||||||
homepage_content = models.TextField(blank=True)
|
|
||||||
footer = models.TextField(blank=True)
|
footer = models.TextField(blank=True)
|
||||||
footer_extended = models.TextField(blank=True)
|
footer_extended = models.TextField(blank=True)
|
||||||
show_version = models.BooleanField(default=True)
|
show_version = models.BooleanField(default=True)
|
||||||
|
@@ -1,10 +1,12 @@
|
|||||||
|
{% load markdown %}
|
||||||
|
|
||||||
<footer class="text-muted py-5">
|
<footer class="text-muted py-5">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<p class="float-end mb-1">
|
<p class="float-end mb-1">
|
||||||
<a href="#">Back to top</a>
|
<a href="#">Back to top</a>
|
||||||
</p>
|
</p>
|
||||||
<p class="mb-1">© {% now "Y" %} {{ site_conf.footer }}</p>
|
<p class="mb-1">© {% now "Y" %} {{ site_conf.footer | markdown | safe }}</p>
|
||||||
<p class="mb-0">{{ site_conf.footer_extended }}</p>
|
<p class="mb-0">{{ site_conf.footer_extended | markdown | safe }}</p>
|
||||||
</div>
|
</div>
|
||||||
{% if site_conf.show_version %}
|
{% if site_conf.show_version %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
{% load solo_tags %}
|
{% load solo_tags %}
|
||||||
|
{% load markdown %}
|
||||||
{% get_solo 'portal.SiteConfiguration' as site_conf %}
|
{% get_solo 'portal.SiteConfiguration' as site_conf %}
|
||||||
|
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
@@ -11,11 +12,8 @@
|
|||||||
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
|
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
|
||||||
<meta name="generator" content="Hugo 0.88.1">
|
<meta name="generator" content="Hugo 0.88.1">
|
||||||
<title>{{ site_conf.site_name }}</title>
|
<title>{{ site_conf.site_name }}</title>
|
||||||
|
|
||||||
<link rel="canonical" href="https://getbootstrap.com/docs/5.1/examples/album/">
|
<link rel="canonical" href="https://getbootstrap.com/docs/5.1/examples/album/">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Bootstrap core CSS -->
|
<!-- Bootstrap core CSS -->
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<link href="{% static "css/main.css" %}" rel="stylesheet">
|
<link href="{% static "css/main.css" %}" rel="stylesheet">
|
||||||
@@ -35,8 +33,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
@@ -57,7 +53,7 @@
|
|||||||
<div class="row py-lg-5">
|
<div class="row py-lg-5">
|
||||||
<div class="mx-auto">
|
<div class="mx-auto">
|
||||||
<h1 class="fw-light">About</h1>
|
<h1 class="fw-light">About</h1>
|
||||||
<p class="lead text-muted">{{ site_conf.about | safe }}</p>
|
<p class="lead text-muted">{{ site_conf.about | markdown | safe }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
0
dcc/portal/templatetags/__init__.py
Normal file
0
dcc/portal/templatetags/__init__.py
Normal file
12
dcc/portal/templatetags/markdown.py
Normal file
12
dcc/portal/templatetags/markdown.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from django import template
|
||||||
|
from django.template.defaultfilters import stringfilter
|
||||||
|
|
||||||
|
import markdown as md
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
@stringfilter
|
||||||
|
def markdown(value):
|
||||||
|
return md.markdown(value, extensions=['markdown.extensions.fenced_code'])
|
7
dcc/portal/urls.py
Normal file
7
dcc/portal/urls.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from portal.views import GetHome
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("<int:page>", GetHome.as_view(), name='index_pagination'),
|
||||||
|
]
|
Reference in New Issue
Block a user