mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Introduce support for Flatpages
Markdown support only
This commit is contained in:
@@ -1,6 +1,37 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from solo.admin import SingletonModelAdmin
|
from solo.admin import SingletonModelAdmin
|
||||||
|
|
||||||
from portal.models import SiteConfiguration
|
from portal.models import SiteConfiguration, Flatpage
|
||||||
|
|
||||||
admin.site.register(SiteConfiguration, SingletonModelAdmin)
|
admin.site.register(SiteConfiguration, SingletonModelAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(Flatpage)
|
||||||
|
class FlatpageAdmin(admin.ModelAdmin):
|
||||||
|
readonly_fields = ("path", "creation_time", "updated_time")
|
||||||
|
list_display = ("name", "path")
|
||||||
|
search_fields = ("name",)
|
||||||
|
|
||||||
|
fieldsets = (
|
||||||
|
(
|
||||||
|
None,
|
||||||
|
{
|
||||||
|
"fields": (
|
||||||
|
"name",
|
||||||
|
"path",
|
||||||
|
"content",
|
||||||
|
"draft",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"Audit",
|
||||||
|
{
|
||||||
|
"classes": ("collapse",),
|
||||||
|
"fields": (
|
||||||
|
"creation_time",
|
||||||
|
"updated_time",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
22
ram/portal/migrations/0008_flatpage.py
Normal file
22
ram/portal/migrations/0008_flatpage.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 4.0.6 on 2022-08-07 15:01
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('portal', '0007_siteconfiguration_items_ordering'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Flatpage',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=256, unique=True)),
|
||||||
|
('draft', models.BooleanField(default=True)),
|
||||||
|
('content', models.TextField(blank=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
19
ram/portal/migrations/0009_flatpage_path.py
Normal file
19
ram/portal/migrations/0009_flatpage_path.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.0.6 on 2022-08-07 15:19
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('portal', '0008_flatpage'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='flatpage',
|
||||||
|
name='path',
|
||||||
|
field=models.CharField(default='', max_length=256, unique=True),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
@@ -0,0 +1,25 @@
|
|||||||
|
# Generated by Django 4.0.6 on 2022-08-07 15:46
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('portal', '0009_flatpage_path'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='flatpage',
|
||||||
|
name='creation_time',
|
||||||
|
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='flatpage',
|
||||||
|
name='updated_time',
|
||||||
|
field=models.DateTimeField(auto_now=True),
|
||||||
|
),
|
||||||
|
]
|
@@ -1,8 +1,11 @@
|
|||||||
import django
|
import django
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.dispatch.dispatcher import receiver
|
||||||
|
from solo.models import SingletonModel
|
||||||
|
|
||||||
from ram import __version__ as app_version
|
from ram import __version__ as app_version
|
||||||
from solo.models import SingletonModel
|
from ram.utils import slugify
|
||||||
|
|
||||||
|
|
||||||
class SiteConfiguration(SingletonModel):
|
class SiteConfiguration(SingletonModel):
|
||||||
@@ -40,3 +43,23 @@ class SiteConfiguration(SingletonModel):
|
|||||||
|
|
||||||
def django_version(self):
|
def django_version(self):
|
||||||
return django.get_version()
|
return django.get_version()
|
||||||
|
|
||||||
|
|
||||||
|
class Flatpage(models.Model):
|
||||||
|
name = models.CharField(max_length=256, unique=True)
|
||||||
|
path = models.CharField(max_length=256, unique=True)
|
||||||
|
draft = models.BooleanField(default=True)
|
||||||
|
content = models.TextField(blank=True)
|
||||||
|
creation_time = models.DateTimeField(auto_now_add=True)
|
||||||
|
updated_time = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse("flatpage", kwargs={"flatpage": self.path})
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(models.signals.pre_save, sender=Flatpage)
|
||||||
|
def tag_pre_save(sender, instance, **kwargs):
|
||||||
|
instance.path = slugify(instance.name)
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
{% load solo_tags %}
|
{% load solo_tags %}
|
||||||
{% load markdown %}
|
{% load markdown %}
|
||||||
|
{% load show_menu %}
|
||||||
{% get_solo 'portal.SiteConfiguration' as site_conf %}
|
{% get_solo 'portal.SiteConfiguration' as site_conf %}
|
||||||
|
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
@@ -71,6 +72,7 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="{% url 'scales' %}">Scales</a>
|
<a class="nav-link" href="{% url 'scales' %}">Scales</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% show_menu %}
|
||||||
</ul>
|
</ul>
|
||||||
{% include 'includes/search.html' %}
|
{% include 'includes/search.html' %}
|
||||||
</div>
|
</div>
|
||||||
@@ -84,7 +86,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<div class="album py-5 bg-light">
|
<div class="album py-4 bg-light">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a id="rolling-stock"></a>
|
<a id="rolling-stock"></a>
|
||||||
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
|
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
|
||||||
|
@@ -57,7 +57,7 @@
|
|||||||
{% block pagination %}
|
{% block pagination %}
|
||||||
{% if company.has_other_pages %}
|
{% if company.has_other_pages %}
|
||||||
<nav aria-label="Page navigation example">
|
<nav aria-label="Page navigation example">
|
||||||
<ul class="pagination justify-content-center mt-4">
|
<ul class="pagination justify-content-center mt-4 mb-0">
|
||||||
{% if company.has_previous %}
|
{% if company.has_previous %}
|
||||||
<li class="page-item">
|
<li class="page-item">
|
||||||
<a class="page-link" href="{% url 'company_pagination' page=company.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
|
<a class="page-link" href="{% url 'company_pagination' page=company.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
|
||||||
|
@@ -103,7 +103,7 @@
|
|||||||
{% block pagination %}
|
{% block pagination %}
|
||||||
{% if rolling_stock.has_other_pages %}
|
{% if rolling_stock.has_other_pages %}
|
||||||
<nav aria-label="Page navigation example">
|
<nav aria-label="Page navigation example">
|
||||||
<ul class="pagination justify-content-center mt-4">
|
<ul class="pagination justify-content-center mt-4 mb-0">
|
||||||
{% if rolling_stock.has_previous %}
|
{% if rolling_stock.has_previous %}
|
||||||
<li class="page-item">
|
<li class="page-item">
|
||||||
<a class="page-link" href="{% url 'consist_pagination' uuid=consist.uuid page=rolling_stock.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
|
<a class="page-link" href="{% url 'consist_pagination' uuid=consist.uuid page=rolling_stock.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
|
||||||
|
@@ -70,7 +70,7 @@
|
|||||||
{% block pagination %}
|
{% block pagination %}
|
||||||
{% if consist.has_other_pages %}
|
{% if consist.has_other_pages %}
|
||||||
<nav aria-label="Page navigation example">
|
<nav aria-label="Page navigation example">
|
||||||
<ul class="pagination justify-content-center mt-4">
|
<ul class="pagination justify-content-center mt-4 mb-0">
|
||||||
{% if consist.has_previous %}
|
{% if consist.has_previous %}
|
||||||
<li class="page-item">
|
<li class="page-item">
|
||||||
<a class="page-link" href="{% url 'consists_pagination' page=consist.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
|
<a class="page-link" href="{% url 'consists_pagination' page=consist.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
|
||||||
|
19
ram/portal/templates/flatpage.html
Normal file
19
ram/portal/templates/flatpage.html
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
{% load markdown %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<h1 class="fw-light">{{ flatpage.name }}</h1>
|
||||||
|
<small class="text-muted">Updated {{ flatpage.updated_time | date:"M d, Y H:i" }}</small>
|
||||||
|
{% endblock %}
|
||||||
|
{% block extra_content %}
|
||||||
|
<section class="py-4 text-start container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="mx-auto">
|
||||||
|
<div>{{ flatpage.content | markdown | safe }} </div>
|
||||||
|
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
|
||||||
|
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:portal_flatpage_change' flatpage.pk %}">Edit</a>{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
12
ram/portal/templates/flatpage_menu.html
Normal file
12
ram/portal/templates/flatpage_menu.html
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{% if menu %}
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
More ...
|
||||||
|
</a>
|
||||||
|
{% for m in menu %}
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||||
|
<li><a class="dropdown-item" href="{{ m.get_absolute_url }}">{{ m.name }}</a></li>
|
||||||
|
</ul>
|
||||||
|
{% endfor %}
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
@@ -9,7 +9,7 @@
|
|||||||
{% block pagination %}
|
{% block pagination %}
|
||||||
{% if rolling_stock.has_other_pages %}
|
{% if rolling_stock.has_other_pages %}
|
||||||
<nav aria-label="Page navigation example">
|
<nav aria-label="Page navigation example">
|
||||||
<ul class="pagination justify-content-center mt-4">
|
<ul class="pagination justify-content-center mt-4 mb-0">
|
||||||
{% if rolling_stock.has_previous %}
|
{% if rolling_stock.has_previous %}
|
||||||
<li class="page-item">
|
<li class="page-item">
|
||||||
<a class="page-link" href="{% url 'index_pagination' page=rolling_stock.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
|
<a class="page-link" href="{% url 'index_pagination' page=rolling_stock.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
|
||||||
|
@@ -47,7 +47,7 @@
|
|||||||
{% block pagination %}
|
{% block pagination %}
|
||||||
{% if scale.has_other_pages %}
|
{% if scale.has_other_pages %}
|
||||||
<nav aria-label="Page navigation example">
|
<nav aria-label="Page navigation example">
|
||||||
<ul class="pagination justify-content-center mt-4">
|
<ul class="pagination justify-content-center mt-4 mb-0">
|
||||||
{% if scale.has_previous %}
|
{% if scale.has_previous %}
|
||||||
<li class="page-item">
|
<li class="page-item">
|
||||||
<a class="page-link" href="{% url 'scale_pagination' page=scale.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
|
<a class="page-link" href="{% url 'scale_pagination' page=scale.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
{% block pagination %}
|
{% block pagination %}
|
||||||
{% if rolling_stock.has_other_pages %}
|
{% if rolling_stock.has_other_pages %}
|
||||||
<nav aria-label="Page navigation example">
|
<nav aria-label="Page navigation example">
|
||||||
<ul class="pagination justify-content-center mt-4">
|
<ul class="pagination justify-content-center mt-4 mb-0">
|
||||||
{% if rolling_stock.has_previous %}
|
{% if rolling_stock.has_previous %}
|
||||||
<li class="page-item">
|
<li class="page-item">
|
||||||
<a class="page-link" href="{% url 'filtered_pagination' _filter=filter search=search page=rolling_stock.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
|
<a class="page-link" href="{% url 'filtered_pagination' _filter=filter search=search page=rolling_stock.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
|
||||||
|
10
ram/portal/templatetags/show_menu.py
Normal file
10
ram/portal/templatetags/show_menu.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from django import template
|
||||||
|
from portal.views import Flatpage
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.inclusion_tag('flatpage_menu.html')
|
||||||
|
def show_menu():
|
||||||
|
menu = Flatpage.objects.all()
|
||||||
|
return {"menu": menu}
|
@@ -3,6 +3,7 @@ from django.urls import path
|
|||||||
from portal.views import (
|
from portal.views import (
|
||||||
GetHome,
|
GetHome,
|
||||||
GetHomeFiltered,
|
GetHomeFiltered,
|
||||||
|
GetFlatpage,
|
||||||
GetRollingStock,
|
GetRollingStock,
|
||||||
GetConsist,
|
GetConsist,
|
||||||
Consists,
|
Consists,
|
||||||
@@ -13,6 +14,11 @@ from portal.views import (
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", GetHome.as_view(), name="index"),
|
path("", GetHome.as_view(), name="index"),
|
||||||
path("<int:page>", GetHome.as_view(), name="index_pagination"),
|
path("<int:page>", GetHome.as_view(), name="index_pagination"),
|
||||||
|
path(
|
||||||
|
"page/<str:flatpage>",
|
||||||
|
GetFlatpage.as_view(),
|
||||||
|
name="flatpage",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"search",
|
"search",
|
||||||
GetHomeFiltered.as_view(http_method_names=["post"]),
|
GetHomeFiltered.as_view(http_method_names=["post"]),
|
||||||
|
@@ -6,9 +6,10 @@ from django.http import Http404
|
|||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
from django.core.paginator import Paginator, PageNotAnInteger
|
||||||
|
|
||||||
from portal.utils import get_site_conf
|
from portal.utils import get_site_conf
|
||||||
|
from portal.models import Flatpage
|
||||||
from roster.models import RollingStock
|
from roster.models import RollingStock
|
||||||
from consist.models import Consist
|
from consist.models import Consist
|
||||||
from metadata.models import Company, Scale
|
from metadata.models import Company, Scale
|
||||||
@@ -241,3 +242,17 @@ class Scales(View):
|
|||||||
"scales.html",
|
"scales.html",
|
||||||
{"scale": scale, "page_range": page_range},
|
{"scale": scale, "page_range": page_range},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class GetFlatpage(View):
|
||||||
|
def get(self, request, flatpage):
|
||||||
|
try:
|
||||||
|
flatpage = Flatpage.objects.get(path=flatpage)
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
"flatpage.html",
|
||||||
|
{"flatpage": flatpage},
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user