Skip to content

Commit

Permalink
use localized page tree for menu, add language chooser to footer (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeriox authored Sep 4, 2023
1 parent 3ff3b81 commit bfb430a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
3 changes: 3 additions & 0 deletions myhpi/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def base_context(request):
if not root_page:
return {"root_page": None, "pages_by_parent": None}

# Determine the correct root for the active language
root_page = root_page.localized

# Determine all pages the user may view based on his groups
user_groups = get_user_groups(request.user)

Expand Down
16 changes: 16 additions & 0 deletions myhpi/core/migrations/0008_remove_footer_column_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.0.7 on 2023-08-15 19:35

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("core", "0007_alter_footer_column_1_alter_footer_column_2_and_more"),
]

operations = [
migrations.RemoveField(
model_name="footer",
name="column_4",
),
]
3 changes: 0 additions & 3 deletions myhpi/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,11 @@ class Footer(models.Model):
column_1 = CustomMarkdownField()
column_2 = CustomMarkdownField()
column_3 = CustomMarkdownField()
column_4 = CustomMarkdownField()

panels = [
FieldPanel("column_1"),
FieldPanel("column_2"),
FieldPanel("column_3"),
FieldPanel("column_4"),
]

def __str__(self):
Expand All @@ -240,7 +238,6 @@ def get_first_line(content):
get_first_line(self.column_1)
+ get_first_line(self.column_2)
+ get_first_line(self.column_3)
+ get_first_line(self.column_4)
)


Expand Down
4 changes: 2 additions & 2 deletions myhpi/core/templatetags/core_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def get_nav_children_for(pages_by_parent, parent_path):


@register.inclusion_tag("footer.html")
def insert_footer():
def insert_footer(page):
footer = Footer.objects.first()
return {"footer_columns": [footer.column_1, footer.column_2, footer.column_3, footer.column_4]}
return {"footer_columns": [footer.column_1, footer.column_2, footer.column_3], "page": page}


@register.filter(name="tag_external_links")
Expand Down
2 changes: 1 addition & 1 deletion myhpi/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
</div>
</div>

{% insert_footer %}
{% insert_footer page %}

{# Global javascript #}
<script src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
Expand Down
7 changes: 7 additions & 0 deletions myhpi/templates/footer.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load i18n %}
{% load core_extras %}

<footer class="footer-myhpi container-lg page text-light">
Expand All @@ -9,5 +10,11 @@
{% endwith %}
</div>
{% endfor %}
<div class="footer-category">
<h2>{% translate "Language" %}</h2>
{% for translation in page.get_translations %}
<a href="{{ translation.url }}">{{ translation.locale }}</a>
{% endfor %}
</div>
</div>
</footer>
1 change: 0 additions & 1 deletion myhpi/tests/core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def create_basic_page_structure():
column_1="# Fachschaft\r\n",
column_2="# Rechtliches\r\n\r\n- [Impressum]()\r\n- [Datenschutzerklärung]()",
column_3="# Entwicklung\r\n\r\n- [GitHub](https://github.com/fsr-de/myHPI/)",
column_4="# Sprache\r\n",
).save()
# Remove dummy site
Site.objects.all()[0].delete()
Expand Down

0 comments on commit bfb430a

Please sign in to comment.