Skip to content

Commit

Permalink
CONCD-765 Allow CMs to change Guide titles (Requires Migration) (#2373)
Browse files Browse the repository at this point in the history
* CONCD-765 Guide titles (requires migration)

* CONCD-765 having guides point to simple pages, instead of vice versa
  • Loading branch information
rasarkar authored May 10, 2024
1 parent 6b38aa0 commit fba4549
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 23 deletions.
24 changes: 24 additions & 0 deletions concordia/migrations/0091_guide_simple_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.13 on 2024-05-09 19:21

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("concordia", "0090_auto_20240408_1334"),
]

operations = [
migrations.AddField(
model_name="guide",
name="page",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="concordia.simplepage",
),
),
]
30 changes: 30 additions & 0 deletions concordia/migrations/0092_auto_20240509_1522.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.2.13 on 2024-05-09 19:22

from django.db import migrations


def set_simplepages(apps, schema_editor):
SimplePage = apps.get_model("concordia", "SimplePage")
Guide = apps.get_model("concordia", "Guide")
for guide in Guide.objects.all():
page = SimplePage.objects.get(title=guide.title)
guide.page = page
guide.save()


def backwards(apps, schema_editor):
Guide = apps.get_model("concordia", "Guide")
for guide in Guide.objects.all():
guide.page = None
guide.save()


class Migration(migrations.Migration):

dependencies = [
("concordia", "0091_guide_simple_page"),
]

operations = [
migrations.RunPython(set_simplepages, backwards),
]
3 changes: 3 additions & 0 deletions concordia/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,9 @@ class Meta:

class Guide(models.Model):
title = models.CharField(max_length=80)
page = models.ForeignKey(
SimplePage, on_delete=models.SET_NULL, blank=True, null=True
)
body = models.TextField(blank=True)
order = models.IntegerField(default=1)
link_text = models.CharField(max_length=80, blank=True, null=True)
Expand Down
10 changes: 4 additions & 6 deletions concordia/templates/static-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ <h1 class="my-3">{{ title }}</h1>
<div class="col-3">
<div class="nav flex-column help-center">
<h4>Instructions</h4>
{% for link in toc %}
{% if link.1 %}
<a class="nav-link{% if title|lower == link.0|lower %} active{% endif %}" href="{{ link.1 }}">
{{ link.0 }}
</a>
{% endif %}
{% for guide in guides %}
<a class="nav-link{% if guide.page.path == request.path %} active{% endif %}" href="{{ guide.page.path }}">
{{ guide.title }}
</a>
{% endfor %}
<span lang="es">
<a class="nav-link" href="/help-center/how-to-transcribe-esp/">Instrucciones en español</a>
Expand Down
21 changes: 4 additions & 17 deletions concordia/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,14 @@ def simple_page(request, path=None, slug=None):
"breadcrumbs": breadcrumbs,
}

guides = Guide.objects.order_by("order")
links = []
try:
guide = guides.get(title__iexact=page.title)
guide = page.guide_set.all().first()
if guide is not None:
html = "".join((page.body, guide.body))
ctx["add_navigation"] = True
except Guide.DoesNotExist:
else:
html = page.body
if page.title == "Get started":
ctx["add_navigation"] = True
links.append("Get started", reverse("welcome-guide"))
if "add_navigation" in ctx:
for guide in guides.all():
try:
simple_page = SimplePage.objects.get(title__iexact=guide.title)
url = simple_page.path
except SimplePage.DoesNotExist:
url = None
if url is not None:
links.append((guide.title, url))
ctx["toc"] = links
ctx["guides"] = Guide.objects.order_by("order")
ctx["body"] = md.convert(html)

resp = render(request, "static-page.html", ctx)
Expand Down

0 comments on commit fba4549

Please sign in to comment.