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

Update homepage to not used wagtail pages #4127

Merged
merged 1 commit into from
Oct 17, 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
10 changes: 3 additions & 7 deletions hypha/apply/dashboard/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from urllib.parse import urljoin

from django.urls import reverse
from django.utils.translation import gettext as _
from wagtail import hooks
from wagtail.admin.menu import MenuItem

from hypha.home.models import ApplyHomePage


@hooks.register("register_admin_menu_item")
def register_dashboard_menu_item():
apply_home = ApplyHomePage.objects.first()
return MenuItem(
"Apply Dashboard",
urljoin(apply_home.url, reverse("dashboard:dashboard", "hypha.urls")),
_("Goto Dashboard"),
reverse("dashboard:dashboard"),
classname="icon icon-arrow-left",
order=100000,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 4.2.16 on 2024-09-10 07:30

from django.db import migrations, models
import wagtail.fields


class Migration(migrations.Migration):
dependencies = [
("core", "0005_alter_systemsettings_footer_content"),
]

operations = [
migrations.AddField(
model_name="systemsettings",
name="home_strapline",
field=wagtail.fields.RichTextField(
default="",
help_text="The strapline to be displayed on the homepage.",
verbose_name="Strapline",
),
),
migrations.AddField(
model_name="systemsettings",
name="home_title",
field=models.CharField(
default="",
help_text="The title to be displayed on the homepage.",
max_length=255,
verbose_name="Title",
),
),
]
23 changes: 23 additions & 0 deletions hypha/core/migrations/0007_copy_homepage_title_strapline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.16 on 2024-09-10 07:34

from django.db import migrations


class Migration(migrations.Migration):
def copy_homepage_title_and_strapline(apps, schema_editor):
from hypha.core.models import SystemSettings
from hypha.home.models import ApplyHomePage

if home_page := ApplyHomePage.objects.first():
system_settings = SystemSettings.load()
system_settings.home_title = home_page.title
system_settings.home_strapline = home_page.strapline
system_settings.save()

dependencies = [
("core", "0006_systemsettings_home_strapline_and_more"),
]

operations = [
migrations.RunPython(copy_homepage_title_and_strapline),
]
20 changes: 20 additions & 0 deletions hypha/core/models/system_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ class Meta:
verbose_name = "System settings"
db_table = "system_settings"

home_title = models.CharField(
_("Title"),
max_length=255,
default="",
help_text=_("The title to be displayed on the homepage."),
)

home_strapline = RichTextField(
_("Strapline"),
default="",
help_text=_("The strapline to be displayed on the homepage."),
)

site_logo_default = models.ForeignKey(
"images.CustomImage",
null=True,
Expand Down Expand Up @@ -79,6 +92,13 @@ class Meta:
)

panels = [
MultiFieldPanel(
[
FieldPanel("home_title"),
FieldPanel("home_strapline"),
],
"Homepage",
),
MultiFieldPanel(
[
FieldPanel("site_logo_default"),
Expand Down
18 changes: 0 additions & 18 deletions hypha/home/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from django.db import models
from wagtail.admin.panels import FieldPanel
from wagtail.models import Page
from wagtail.search import index

from hypha.apply.funds.models import ApplicationBase, LabBase


class ApplyHomePage(Page):
Expand All @@ -12,17 +8,3 @@ class ApplyHomePage(Page):
subpage_types = ["funds.FundType", "funds.LabType", "funds.RequestForPartners"]

strapline = models.CharField(blank=True, max_length=255)
Copy link
Member

@frjo frjo Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this line makes the code in copy_homepage_title_and_strapline not run since the model no longer have a strapline.

Would be really good to get this working making the deployment of this release seamless.

Maybe we can remove the strapline field in a separate release?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, hasattr will always be false. I think we can remove it later after couple of releases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code so that it keeps the strapline on the ApplyHome model.


search_fields = Page.search_fields + [
index.SearchField("strapline"),
]

content_panels = Page.content_panels + [
FieldPanel("strapline"),
]

def get_context(self, *args, **kwargs):
context = super().get_context(*args, **kwargs)
context["open_funds"] = ApplicationBase.objects.order_by_end_date().specific()
context["open_labs"] = LabBase.objects.public().live().specific()
return context
22 changes: 0 additions & 22 deletions hypha/home/templates/apply_home/apply_home_page.html

This file was deleted.

26 changes: 26 additions & 0 deletions hypha/home/templates/home/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "base-apply.html" %}
{% load nh3_tags %}

{% block title_prefix %}{{ settings.core.SystemSettings.home_title }} | {% endblock %}
{% block title %}{{ ORG_SHORT_NAME }}{% endblock %}
{% block meta_description %}{{ settings.core.SystemSettings.home_strapline|striptags|truncatechars:200 }}{% endblock %}

{% block content %}
<div class="py-8 lg:py-16 max-w-3xl mx-auto">

<h1 class="font-bold text-5xl text-balance">
{{ settings.core.SystemSettings.home_title}}
</h1>

{% if settings.core.SystemSettings.home_strapline %}
<p class="mb-8 text-fg-muted text-pretty">{{ settings.core.SystemSettings.home_strapline|nh3|safe }}</p>
{% endif %}

<div class="divide-y">
{% for fund in funds %}
{% include "home/includes/fund-list-item.html" with page=fund %}
{% endfor %}
</div>

</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% load i18n nh3_tags wagtailcore_tags markdown_tags heroicons %}

{% if page.open_round and page.list_on_front_page %}
<div class="flex justify-between items-center px-4 py-8 gap-4 hover:bg-slate-50 transition-colors">
<article class="flex justify-between items-center px-4 py-8 gap-4 hover:bg-slate-50 transition-colors">

<div>
<h2>{{ page.title }}</h2>
Expand Down Expand Up @@ -31,5 +31,5 @@ <h2>{{ page.title }}</h2>
{% trans 'Apply' %}
</a>
</div>
</div>
</article>
{% endif %}
3 changes: 0 additions & 3 deletions hypha/home/tests.py

This file was deleted.

17 changes: 15 additions & 2 deletions hypha/home/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# from django.shortcuts import render
from django.shortcuts import render

# Create your views here.
from hypha.apply.funds.models import ApplicationBase, LabBase


def home(request):
"""Home page view.

Displays the list of active rounds and labs to both logged in and logged out users.
"""
ctx = {}
rounds = ApplicationBase.objects.order_by_end_date().specific()
labs = LabBase.objects.public().live().specific()

ctx["funds"] = list(rounds) + list(labs)
return render(request, "home/home.html", ctx)
3 changes: 2 additions & 1 deletion hypha/static_src/sass/wagtail_global_admin.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.sidebar form[role="search"] {
.sidebar form[role="search"],
.sidebar-page-explorer-item {
display: none;
}
3 changes: 2 additions & 1 deletion hypha/templates/base-apply.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
>
<a
class="py-2 px-0.5"
href="{{ settings.core.SystemSettings.site_logo_link|default:"/" }}">
href="{{ settings.core.SystemSettings.site_logo_link|default:"/" }}"
>
{% include 'includes/header-logo.html' %}
</a>

Expand Down
2 changes: 1 addition & 1 deletion hypha/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>{% block title_prefix %}{% if current_site.site_name %}{{ current_site.site_name }} | {% endif %}{% endblock %}{% block title %}{% if page.seo_title %}{{ page.seo_title }}{% else %}{{ page.title }}{% endif %}{% endblock %}{% block title_suffix %}{{ TITLE_SUFFIX }}{% endblock %}</title>
<meta name="description" content="{% if page.search_description %}{{ page.search_description }}{% else %}{{ page.listing_summary }}{% endif %}">
<meta name="description" content="{% block meta_description %}{% if page.search_description %}{{ page.search_description }}{% else %}{{ page.listing_summary }}{% endif %}{% endblock %}">

<!-- favicons -->
{% comment %}
Expand Down
2 changes: 2 additions & 0 deletions hypha/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
from hypha.apply.users.urls import urlpatterns as user_urls
from hypha.apply.users.views import become, oauth_complete
from hypha.apply.utils.views import custom_wagtail_page_delete
from hypha.home.views import home

urlpatterns = [
path("", home, name="home"),
path("apply/", include("hypha.apply.funds.urls", "apply")),
path("activity/", include("hypha.apply.activity.urls", "activity")),
path("todo/", include("hypha.apply.todo.urls", "todo")),
Expand Down
Loading