Skip to content

Commit

Permalink
Merge pull request #30 from hotosm/feat/events-page
Browse files Browse the repository at this point in the history
project - open mapping hub, who we are, impact areas, open mapping hubs, tools and resources, search functionality+page, member group pages done
  • Loading branch information
luminaryFlowers authored Jul 11, 2024
2 parents c3506e0 + 4a98030 commit 7b1f0d4
Show file tree
Hide file tree
Showing 147 changed files with 3,274 additions and 243 deletions.
27 changes: 27 additions & 0 deletions app/core/migrations/0003_hotsearchablepage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.7 on 2024-07-08 21:16

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


class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0089_log_entry_data_json_null_to_object'),
('core', '0002_alter_partner_partner_logo_alter_partner_partner_url'),
]

operations = [
migrations.CreateModel(
name='HOTSearchablePage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
('intro', wagtail.fields.RichTextField(blank=True)),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
]
24 changes: 24 additions & 0 deletions app/core/migrations/0004_testpagepage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.7 on 2024-07-08 21:31

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


class Migration(migrations.Migration):

dependencies = [
('core', '0003_hotsearchablepage'),
]

operations = [
migrations.CreateModel(
name='TestPagePage',
fields=[
('hotsearchablepage_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='core.hotsearchablepage')),
],
options={
'abstract': False,
},
bases=('core.hotsearchablepage',),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.7 on 2024-07-08 21:35

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('core', '0004_testpagepage'),
]

operations = [
migrations.RemoveField(
model_name='hotsearchablepage',
name='intro',
),
migrations.DeleteModel(
name='TestPagePage',
),
]
16 changes: 16 additions & 0 deletions app/core/migrations/0006_delete_hotsearchablepage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.7 on 2024-07-09 22:09

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('core', '0005_remove_hotsearchablepage_intro_delete_testpagepage'),
]

operations = [
migrations.DeleteModel(
name='HOTSearchablePage',
),
]
2 changes: 2 additions & 0 deletions app/core/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.db import models
from wagtail.models import Page
from wagtail.fields import RichTextField

from wagtail.snippets.models import register_snippet
from wagtail.admin.panels import FieldPanel, MultiFieldPanel, InlinePanel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated by Django 4.2.7 on 2024-06-27 18:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('events', '0003_eventownerpage_event_read_more_text_and_more'),
]

operations = [
migrations.AddField(
model_name='eventownerpage',
name='keyword_search_hint',
field=models.CharField(default='Search by keyword'),
),
migrations.AddField(
model_name='eventownerpage',
name='results_text',
field=models.CharField(default='Results'),
),
migrations.AddField(
model_name='eventownerpage',
name='search_button_text',
field=models.CharField(default='Search'),
),
migrations.AddField(
model_name='eventownerpage',
name='sort_by_new',
field=models.CharField(default='Sort by New'),
),
migrations.AddField(
model_name='eventownerpage',
name='sort_by_old',
field=models.CharField(default='Sort by Old'),
),
migrations.AddField(
model_name='eventownerpage',
name='sort_by_titlea',
field=models.CharField(default='Sort by Title Alphabetical'),
),
migrations.AddField(
model_name='eventownerpage',
name='sort_by_titlez',
field=models.CharField(default='Sort by Title Reverse Alphabetical'),
),
]
84 changes: 75 additions & 9 deletions app/events/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
from django.db import models
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger

from wagtail.models import Page
from wagtail.fields import RichTextField, StreamField
from wagtail.admin.panels import FieldPanel, MultiFieldPanel, PageChooserPanel
from wagtail.blocks import CharBlock, StreamBlock, StructBlock, URLBlock, RichTextBlock, PageChooserBlock
from modelcluster.fields import ParentalKey, ParentalManyToManyField
from wagtail.search import index


class EventOwnerPage(Page):
def get_context(self, request, *args, **kwargs):
context = super().get_context(request, *args, **kwargs)

keyword = request.GET.get('keyword', '')
events_list = IndividualEventPage.objects.live().filter(locale=context['page'].locale)

if keyword:
events_list = events_list.search(keyword).get_queryset()

match request.GET.get('sort', ''):
case 'sort.new':
events_list = events_list.order_by('-start_date_time')
case 'sort.old':
events_list = events_list.order_by('start_date_time')
case 'sort.titlea':
events_list = events_list.order_by('title')
case 'sort.titlez':
events_list = events_list.order_by('-title')
case _:
events_list = events_list.order_by('-start_date_time')

page = request.GET.get('page', 1)
paginator = Paginator(events_list, 6) # if you want more/less items per page (i.e., per load), change the number here to something else
try:
events = paginator.page(page)
except PageNotAnInteger:
events = paginator.page(1)
except EmptyPage:
events = paginator.page(paginator.num_pages)

context['events'] = events
context['events_paginator'] = paginator
context['current_page'] = int(page)
return context

max_count = 1

subpage_types = [
'events.IndividualEventPage'
]

event_location_title = models.CharField(default="Event Location")
join_event_title = models.CharField(default="Join This Event")
rsvp_button_text = models.CharField(default="RSVP")
Expand All @@ -18,20 +59,39 @@ class EventOwnerPage(Page):
view_all_events_url = models.URLField(blank=True)
event_read_more_text = models.CharField(default="Read more")

keyword_search_hint = models.CharField(default="Search by keyword")
sort_by_new = models.CharField(default="Sort by New")
sort_by_old = models.CharField(default="Sort by Old")
sort_by_titlea = models.CharField(default="Sort by Title Alphabetical")
sort_by_titlez = models.CharField(default="Sort by Title Reverse Alphabetical")
search_button_text = models.CharField(default="Search")
results_text = models.CharField(default="Results")

content_panels = Page.content_panels + [
FieldPanel('event_location_title'),
FieldPanel('join_event_title'),
FieldPanel('rsvp_button_text'),
FieldPanel('more_events_title'),
FieldPanel('view_all_events_text'),
FieldPanel('view_all_events_url'),
FieldPanel('event_read_more_text'),
MultiFieldPanel([
FieldPanel('keyword_search_hint'),
FieldPanel('sort_by_new'),
FieldPanel('sort_by_old'),
FieldPanel('sort_by_titlea'),
FieldPanel('sort_by_titlez'),
FieldPanel('search_button_text'),
FieldPanel('results_text'),
], heading="Event Search Page"),
MultiFieldPanel([
FieldPanel('event_location_title'),
FieldPanel('join_event_title'),
FieldPanel('rsvp_button_text'),
FieldPanel('more_events_title'),
FieldPanel('view_all_events_text'),
FieldPanel('view_all_events_url'),
FieldPanel('event_read_more_text'),
], heading="Individual Event Page"),
]


class IndividualEventPage(Page):
parent_page_type = [
'projects.ProjectOwnerPage'
parent_page_types = [
'events.EventOwnerPage'
]

start_date_time = models.DateTimeField()
Expand Down Expand Up @@ -60,6 +120,12 @@ class IndividualEventPage(Page):
('event', PageChooserBlock(page_type="events.IndividualEventPage"))
], use_json_field=True, null=True, blank=True)

search_fields = Page.search_fields + [
index.SearchField('title'),
index.SearchField('intro'),
index.SearchField('search_description'),
]

content_panels = Page.content_panels + [
MultiFieldPanel([
FieldPanel('start_date_time'),
Expand Down
4 changes: 4 additions & 0 deletions app/events/templates/events/components/EventsSortOption.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="mt-4 flex items-center w-fit h-fit" @click="hit()" x-data="{ sort: '{{sort_id}}', hit() {setSortType('{{sort_by}}')} }" x-init="if(sort == params.get('sort')) hit()">
<input class="checked:bg-hot-red checked:hover:bg-hot-red checked:focus:bg-hot-red" type="radio" name="sort" :id="sort" :value="sort" :checked="(params.get('sort') == sort || (!params.get('sort')) && sort == 'sort.new') ? 'on' : ''">
<label class="pl-2" :for="sort">{{sort_by}}</label>
</div>
59 changes: 59 additions & 0 deletions app/events/templates/events/event_owner_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{% extends "base.html" %}
{% load static %}
{% load wagtailcore_tags %}
{% load wagtailimages_tags %}
{% load compress %}
{% block body_class %}template-eventownerpage{% endblock %}
{% block extra_css %}
{% compress css %}
{% endcompress css %}
{% endblock extra_css %}

{% block content %}
<div class="max-w-7xl mx-auto my-10" x-data="{ params: new URLSearchParams((new URL(window.location.href)).search) }">
<div class="px-6 md:px-10">
<h1 class="text-h1 font-semibold my-10">{{page.title}}</h1>
<form class="my-10">
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
{% comment %} KEYWORD SEARCH {% endcomment %}
<div class="bg-hot-off-white flex items-center">
<input class="w-full bg-transparent border-none" placeholder="{{page.keyword_search_hint}}" type="text" name="keyword" :value="params.get('keyword')">
{% include "ui/components/icon_svgs/SearchIcon.html" with class="text-hot-red mx-3" %}
</div>

{% comment %} SORT {% endcomment %}
<div class="relative" x-data="{ show: false, setSortType(text) {$refs.sorttype.innerText = text} }" @click.away="show = false">
<div class="w-full h-full flex justify-between py-2 px-3 bg-hot-off-white items-center cursor-pointer" @click="show = !show">
<p class="pointer-events-none" x-ref="sorttype">
{{page.sort_by_new}}
</p>
{% include "ui/components/icon_svgs/LinkCaret.html" with class="rotate-90 text-hot-red" %}
</div>
<div class="absolute z-20 bg-hot-off-white p-4 w-full" x-show="show">
<hr class="border-b-2">
{% include "./components/EventsSortOption.html" with sort_by=page.sort_by_new sort_id="sort.new" %}
{% include "./components/EventsSortOption.html" with sort_by=page.sort_by_old sort_id="sort.old" %}
{% include "./components/EventsSortOption.html" with sort_by=page.sort_by_titlea sort_id="sort.titlea" %}
{% include "./components/EventsSortOption.html" with sort_by=page.sort_by_titlez sort_id="sort.titlez" %}
</div>
</div>

<div class="bg-hot-red text-white font-semibold">
<input type="submit" value="{{page.search_button_text}}" class="bg-transparent w-full h-full cursor-pointer py-2">
</div>
</div>
</form>

{% comment %} EVENT ITEMS {% endcomment %}
<h2 class="text-h2 font-bold my-8">{{events_paginator.count}} {{page.results_text}}</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8 mb-10">
{% for event in events %}
{% include "ui/components/events/EventPreviewBlockEvent.html" with event=event showimage=True %}
{% endfor %}
</div>

{% comment %} PAGE NAVIGATION {% endcomment %}
{% include "ui/components/utilities/PaginatorNavigation.html" with paginator=events_paginator current_page=current_page %}
</div>
</div>
{% endblock %}
Empty file added app/get_involved/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions app/get_involved/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions app/get_involved/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class GetInvolvedConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'app.get_involved'
26 changes: 26 additions & 0 deletions app/get_involved/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.7 on 2024-07-03 18:17

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


class Migration(migrations.Migration):

initial = True

dependencies = [
('wagtailcore', '0089_log_entry_data_json_null_to_object'),
]

operations = [
migrations.CreateModel(
name='GetInvolvedPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
]
Loading

0 comments on commit 7b1f0d4

Please sign in to comment.