From 468582026745877099f1cffb094ec7b1c31accf1 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 26 Sep 2024 12:14:11 +0530 Subject: [PATCH] Update homepage to not used wagtail pages --- hypha/apply/dashboard/wagtail_hooks.py | 10 ++---- ..._systemsettings_home_strapline_and_more.py | 32 +++++++++++++++++++ .../0007_copy_homepage_title_strapline.py | 23 +++++++++++++ hypha/core/models/system_settings.py | 20 ++++++++++++ hypha/home/models.py | 18 ----------- .../templates/apply_home/apply_home_page.html | 22 ------------- hypha/home/templates/home/home.html | 26 +++++++++++++++ .../includes/fund-list-item.html} | 4 +-- hypha/home/tests.py | 3 -- hypha/home/views.py | 17 ++++++++-- .../static_src/sass/wagtail_global_admin.css | 3 +- hypha/templates/base-apply.html | 3 +- hypha/templates/base.html | 2 +- hypha/urls.py | 2 ++ 14 files changed, 128 insertions(+), 57 deletions(-) create mode 100644 hypha/core/migrations/0006_systemsettings_home_strapline_and_more.py create mode 100644 hypha/core/migrations/0007_copy_homepage_title_strapline.py delete mode 100644 hypha/home/templates/apply_home/apply_home_page.html create mode 100644 hypha/home/templates/home/home.html rename hypha/home/templates/{apply_home/includes/apply_listing.html => home/includes/fund-list-item.html} (88%) delete mode 100644 hypha/home/tests.py diff --git a/hypha/apply/dashboard/wagtail_hooks.py b/hypha/apply/dashboard/wagtail_hooks.py index ecfbe1a08b..dad354a6f7 100644 --- a/hypha/apply/dashboard/wagtail_hooks.py +++ b/hypha/apply/dashboard/wagtail_hooks.py @@ -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, ) diff --git a/hypha/core/migrations/0006_systemsettings_home_strapline_and_more.py b/hypha/core/migrations/0006_systemsettings_home_strapline_and_more.py new file mode 100644 index 0000000000..96bb032992 --- /dev/null +++ b/hypha/core/migrations/0006_systemsettings_home_strapline_and_more.py @@ -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", + ), + ), + ] diff --git a/hypha/core/migrations/0007_copy_homepage_title_strapline.py b/hypha/core/migrations/0007_copy_homepage_title_strapline.py new file mode 100644 index 0000000000..17bdb79e8c --- /dev/null +++ b/hypha/core/migrations/0007_copy_homepage_title_strapline.py @@ -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), + ] diff --git a/hypha/core/models/system_settings.py b/hypha/core/models/system_settings.py index 530195b7ae..b586211207 100644 --- a/hypha/core/models/system_settings.py +++ b/hypha/core/models/system_settings.py @@ -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, @@ -79,6 +92,13 @@ class Meta: ) panels = [ + MultiFieldPanel( + [ + FieldPanel("home_title"), + FieldPanel("home_strapline"), + ], + "Homepage", + ), MultiFieldPanel( [ FieldPanel("site_logo_default"), diff --git a/hypha/home/models.py b/hypha/home/models.py index 8eab4bdcd2..c415cb37cc 100644 --- a/hypha/home/models.py +++ b/hypha/home/models.py @@ -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): @@ -12,17 +8,3 @@ class ApplyHomePage(Page): subpage_types = ["funds.FundType", "funds.LabType", "funds.RequestForPartners"] strapline = models.CharField(blank=True, max_length=255) - - 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 diff --git a/hypha/home/templates/apply_home/apply_home_page.html b/hypha/home/templates/apply_home/apply_home_page.html deleted file mode 100644 index 7451640777..0000000000 --- a/hypha/home/templates/apply_home/apply_home_page.html +++ /dev/null @@ -1,22 +0,0 @@ -{% extends "base-apply.html" %} -% load wagtailcore_tags static %} - -{% block content %} -
-

{{ page.title }}

- - {% if page.strapline %} -

{{ page.strapline }}

- {% endif %} - -
- {% for fund in open_funds %} - {% include "apply_home/includes/apply_listing.html" with page=fund %} - {% endfor %} - {% for lab in open_labs %} - {% include "apply_home/includes/apply_listing.html" with page=lab %} - {% endfor %} -
- -
-{% endblock %} diff --git a/hypha/home/templates/home/home.html b/hypha/home/templates/home/home.html new file mode 100644 index 0000000000..1a5ef48fb8 --- /dev/null +++ b/hypha/home/templates/home/home.html @@ -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 %} +
+ +

+ {{ settings.core.SystemSettings.home_title}} +

+ + {% if settings.core.SystemSettings.home_strapline %} +

{{ settings.core.SystemSettings.home_strapline|nh3|safe }}

+ {% endif %} + +
+ {% for fund in funds %} + {% include "home/includes/fund-list-item.html" with page=fund %} + {% endfor %} +
+ +
+{% endblock %} diff --git a/hypha/home/templates/apply_home/includes/apply_listing.html b/hypha/home/templates/home/includes/fund-list-item.html similarity index 88% rename from hypha/home/templates/apply_home/includes/apply_listing.html rename to hypha/home/templates/home/includes/fund-list-item.html index d4b4ac9e49..fc0de6210f 100644 --- a/hypha/home/templates/apply_home/includes/apply_listing.html +++ b/hypha/home/templates/home/includes/fund-list-item.html @@ -1,7 +1,7 @@ {% load i18n nh3_tags wagtailcore_tags markdown_tags heroicons %} {% if page.open_round and page.list_on_front_page %} -
+

{{ page.title }}

@@ -31,5 +31,5 @@

{{ page.title }}

{% trans 'Apply' %}
-
+ {% endif %} diff --git a/hypha/home/tests.py b/hypha/home/tests.py deleted file mode 100644 index a79ca8be56..0000000000 --- a/hypha/home/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.test import TestCase - -# Create your tests here. diff --git a/hypha/home/views.py b/hypha/home/views.py index fd0e044955..23b002ce71 100644 --- a/hypha/home/views.py +++ b/hypha/home/views.py @@ -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) diff --git a/hypha/static_src/sass/wagtail_global_admin.css b/hypha/static_src/sass/wagtail_global_admin.css index 006c9afc5b..fd63dbec47 100644 --- a/hypha/static_src/sass/wagtail_global_admin.css +++ b/hypha/static_src/sass/wagtail_global_admin.css @@ -1,3 +1,4 @@ -.sidebar form[role="search"] { +.sidebar form[role="search"], +.sidebar-page-explorer-item { display: none; } diff --git a/hypha/templates/base-apply.html b/hypha/templates/base-apply.html index 310615f223..144e98cfce 100644 --- a/hypha/templates/base-apply.html +++ b/hypha/templates/base-apply.html @@ -9,7 +9,8 @@ > + href="{{ settings.core.SystemSettings.site_logo_link|default:"/" }}" + > {% include 'includes/header-logo.html' %} diff --git a/hypha/templates/base.html b/hypha/templates/base.html index 189de7ad51..3615c5a0b5 100644 --- a/hypha/templates/base.html +++ b/hypha/templates/base.html @@ -8,7 +8,7 @@ {% 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 %} - + {% comment %} diff --git a/hypha/urls.py b/hypha/urls.py index f80b96e917..3d86d9cfc7 100644 --- a/hypha/urls.py +++ b/hypha/urls.py @@ -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")),