From a5eb5ee4f608824f2f09b57d71d31c4231fdb0e7 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Mon, 6 Dec 2021 10:02:18 +0530 Subject: [PATCH 01/21] Hangouts/meeting feature From 7db6b75a98b46c33a65b143f89c77ed1c0e4d4c1 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Mon, 6 Dec 2021 10:09:30 +0530 Subject: [PATCH 02/21] Added 'hangouts' app to the project --- project/hangouts/__init__.py | 0 project/hangouts/admin.py | 3 +++ project/hangouts/apps.py | 6 ++++++ project/hangouts/migrations/__init__.py | 0 project/hangouts/models.py | 3 +++ project/hangouts/tests.py | 3 +++ project/hangouts/views.py | 3 +++ 7 files changed, 18 insertions(+) create mode 100644 project/hangouts/__init__.py create mode 100644 project/hangouts/admin.py create mode 100644 project/hangouts/apps.py create mode 100644 project/hangouts/migrations/__init__.py create mode 100644 project/hangouts/models.py create mode 100644 project/hangouts/tests.py create mode 100644 project/hangouts/views.py diff --git a/project/hangouts/__init__.py b/project/hangouts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/hangouts/admin.py b/project/hangouts/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/project/hangouts/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/project/hangouts/apps.py b/project/hangouts/apps.py new file mode 100644 index 0000000..31aa520 --- /dev/null +++ b/project/hangouts/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class HangoutsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'hangouts' diff --git a/project/hangouts/migrations/__init__.py b/project/hangouts/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/hangouts/models.py b/project/hangouts/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/project/hangouts/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/project/hangouts/tests.py b/project/hangouts/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/project/hangouts/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/project/hangouts/views.py b/project/hangouts/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/project/hangouts/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From 8be45f1fa8e33ca063fced5c9ba2749a689db27e Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Mon, 6 Dec 2021 11:17:26 +0530 Subject: [PATCH 03/21] Added hangout model in the app --- project/core/settings/base.py | 1 + project/hangouts/migrations/0001_initial.py | 27 +++++++++++++++++++++ project/hangouts/models.py | 8 ++++++ 3 files changed, 36 insertions(+) create mode 100644 project/hangouts/migrations/0001_initial.py diff --git a/project/core/settings/base.py b/project/core/settings/base.py index 965e5ab..18ffbde 100644 --- a/project/core/settings/base.py +++ b/project/core/settings/base.py @@ -26,6 +26,7 @@ INSTALLED_APPS = [ 'accounts', 'chapters', + 'hangouts', 'home', 'invites', 'search', diff --git a/project/hangouts/migrations/0001_initial.py b/project/hangouts/migrations/0001_initial.py new file mode 100644 index 0000000..2897523 --- /dev/null +++ b/project/hangouts/migrations/0001_initial.py @@ -0,0 +1,27 @@ +# Generated by Django 3.2.6 on 2021-12-06 05:46 + +from django.db import migrations, models +import taggit.managers +import wagtail.core.fields + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('taggit', '0003_taggeditem_add_unique_index'), + ] + + operations = [ + migrations.CreateModel( + name='Hangout', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('description', wagtail.core.fields.RichTextField()), + ('url', models.URLField(blank=True, null=True)), + ('topics', taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags')), + ], + ), + ] diff --git a/project/hangouts/models.py b/project/hangouts/models.py index 71a8362..ca8f8ae 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -1,3 +1,11 @@ from django.db import models +from taggit.managers import TaggableManager +from wagtail.core.fields import RichTextField + # Create your models here. +class Hangout(models.Model): + title = models.CharField(max_length=200) + description = RichTextField() + topics = TaggableManager() + url = models.URLField(blank=True, null=True) From 41153de4f847f97c84b368d300a04ba062801df4 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Mon, 6 Dec 2021 12:44:24 +0530 Subject: [PATCH 04/21] Added hangouts index page Hangouts index page will be used to display all the hangouts and will also be used to create new hangouts in order for people to collaborate. --- project/hangouts/migrations/0001_initial.py | 22 ++++++++++++++--- project/hangouts/models.py | 24 +++++++++++++++++-- .../hangouts/hangouts_index_page.html | 12 ++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 project/hangouts/templates/hangouts/hangouts_index_page.html diff --git a/project/hangouts/migrations/0001_initial.py b/project/hangouts/migrations/0001_initial.py index 2897523..07a151f 100644 --- a/project/hangouts/migrations/0001_initial.py +++ b/project/hangouts/migrations/0001_initial.py @@ -1,6 +1,7 @@ -# Generated by Django 3.2.6 on 2021-12-06 05:46 +# Generated by Django 3.2.6 on 2021-12-06 06:17 from django.db import migrations, models +import django.db.models.deletion import taggit.managers import wagtail.core.fields @@ -10,18 +11,33 @@ class Migration(migrations.Migration): initial = True dependencies = [ + ('wagtailcore', '0062_comment_models_and_pagesubscription'), ('taggit', '0003_taggeditem_add_unique_index'), ] operations = [ + migrations.CreateModel( + name='HangoutsIndexPage', + 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')), + ('introduction', wagtail.core.fields.RichTextField()), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), migrations.CreateModel( name='Hangout', fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=200)), + ('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')), ('description', wagtail.core.fields.RichTextField()), ('url', models.URLField(blank=True, null=True)), ('topics', taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags')), ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), ), ] diff --git a/project/hangouts/models.py b/project/hangouts/models.py index ca8f8ae..069694a 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -1,11 +1,31 @@ from django.db import models from taggit.managers import TaggableManager +from wagtail.admin.edit_handlers import FieldPanel from wagtail.core.fields import RichTextField +from wagtail.core.models import Page # Create your models here. -class Hangout(models.Model): - title = models.CharField(max_length=200) +class Hangout(Page): description = RichTextField() topics = TaggableManager() url = models.URLField(blank=True, null=True) + + +class HangoutsIndexPage(Page): + introduction = RichTextField() + + content_panels = Page.content_panels + [ + FieldPanel("introduction"), + ] + + parent_page_types = [ + "home.HomePage", + ] + + max_count = 1 + + def get_context(self, request, *args, **kwargs): + context = super().get_context(request, *args, **kwargs) + context["hangouts"] = Hangout.objects.all() + return context diff --git a/project/hangouts/templates/hangouts/hangouts_index_page.html b/project/hangouts/templates/hangouts/hangouts_index_page.html new file mode 100644 index 0000000..7b0ff99 --- /dev/null +++ b/project/hangouts/templates/hangouts/hangouts_index_page.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block title %}{{ page.title }}{% endblock title %} + +{% load wagtailcore_tags %} + +{% block content %} +

{{ page.title }}

+ +{{ page.introduction | richtext }} + +{% endblock content %} From bc1244050d058e496dd820a67dc5a701d6378cf9 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Mon, 6 Dec 2021 14:24:35 +0530 Subject: [PATCH 05/21] Added hangout cards on hangout index page The cards are made to be clickable which would subsequently render individual hangouts pages. Also made the url to be a streamfield url block --- .../migrations/0002_remove_hangout_url.py | 17 +++++++++ .../hangouts/migrations/0003_hangout_url.py | 20 +++++++++++ project/hangouts/models.py | 35 ++++++++++++++++--- .../hangouts/hangouts_index_page.html | 14 ++++++++ 4 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 project/hangouts/migrations/0002_remove_hangout_url.py create mode 100644 project/hangouts/migrations/0003_hangout_url.py diff --git a/project/hangouts/migrations/0002_remove_hangout_url.py b/project/hangouts/migrations/0002_remove_hangout_url.py new file mode 100644 index 0000000..ebb9d9f --- /dev/null +++ b/project/hangouts/migrations/0002_remove_hangout_url.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.6 on 2021-12-06 08:15 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('hangouts', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='hangout', + name='url', + ), + ] diff --git a/project/hangouts/migrations/0003_hangout_url.py b/project/hangouts/migrations/0003_hangout_url.py new file mode 100644 index 0000000..c82db63 --- /dev/null +++ b/project/hangouts/migrations/0003_hangout_url.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.6 on 2021-12-06 08:39 + +from django.db import migrations +import wagtail.core.blocks +import wagtail.core.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('hangouts', '0002_remove_hangout_url'), + ] + + operations = [ + migrations.AddField( + model_name='hangout', + name='url', + field=wagtail.core.fields.StreamField([('hangout_link', wagtail.core.blocks.URLBlock(form_classname='hangout link', required=False))], blank=True), + ), + ] diff --git a/project/hangouts/models.py b/project/hangouts/models.py index 069694a..4707731 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -1,15 +1,35 @@ from django.db import models from taggit.managers import TaggableManager -from wagtail.admin.edit_handlers import FieldPanel -from wagtail.core.fields import RichTextField +from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel +from wagtail.core.fields import RichTextField, StreamField from wagtail.core.models import Page +from wagtail.core.blocks import URLBlock # Create your models here. class Hangout(Page): description = RichTextField() topics = TaggableManager() - url = models.URLField(blank=True, null=True) + url = StreamField( + [ + ( + "hangout_link", + URLBlock(required=False, form_classname="hangout link"), + ), + ], + block_counts={ + 'hangout_link': {'max_num': 1}, + }, + blank=True, + ) + content_panels = Page.content_panels + [ + FieldPanel("description",classname="full"), + FieldPanel("topics",classname="full"), + FieldPanel("url",classname="full") + ] + parent_page_types = [ + "hangouts.HangoutsIndexPage", + ] class HangoutsIndexPage(Page): @@ -23,9 +43,16 @@ class HangoutsIndexPage(Page): "home.HomePage", ] + subpage_types = ["hangouts.Hangout"] + max_count = 1 def get_context(self, request, *args, **kwargs): context = super().get_context(request, *args, **kwargs) - context["hangouts"] = Hangout.objects.all() + context["hangouts"] = ( + self.allowed_subpage_models()[0] + .objects.child_of(self) + .live() + .order_by("title") + ) return context diff --git a/project/hangouts/templates/hangouts/hangouts_index_page.html b/project/hangouts/templates/hangouts/hangouts_index_page.html index 7b0ff99..06139fc 100644 --- a/project/hangouts/templates/hangouts/hangouts_index_page.html +++ b/project/hangouts/templates/hangouts/hangouts_index_page.html @@ -9,4 +9,18 @@

{{ page.title }}

{{ page.introduction | richtext }} +
+ {% for hangout in hangouts %} +
+
+
+
{{ hangout.title }}
+ {{ hangout.description | richtext }} + Go somewhere +
+
+
+ {% endfor %} +
+ {% endblock content %} From 44d30f57ce5e189f3bd0d4893252016928b822ab Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Tue, 7 Dec 2021 13:19:01 +0530 Subject: [PATCH 06/21] Added URLField to Hangout model, currently throws an error --- project/hangouts/migrations/0001_initial.py | 6 +++--- .../migrations/0002_remove_hangout_url.py | 17 ---------------- .../hangouts/migrations/0003_hangout_url.py | 20 ------------------- project/hangouts/models.py | 13 +----------- 4 files changed, 4 insertions(+), 52 deletions(-) delete mode 100644 project/hangouts/migrations/0002_remove_hangout_url.py delete mode 100644 project/hangouts/migrations/0003_hangout_url.py diff --git a/project/hangouts/migrations/0001_initial.py b/project/hangouts/migrations/0001_initial.py index 07a151f..cc4c07e 100644 --- a/project/hangouts/migrations/0001_initial.py +++ b/project/hangouts/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.6 on 2021-12-06 06:17 +# Generated by Django 3.2.6 on 2021-12-07 07:37 from django.db import migrations, models import django.db.models.deletion @@ -11,8 +11,8 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('wagtailcore', '0062_comment_models_and_pagesubscription'), ('taggit', '0003_taggeditem_add_unique_index'), + ('wagtailcore', '0062_comment_models_and_pagesubscription'), ] operations = [ @@ -32,7 +32,7 @@ class Migration(migrations.Migration): 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')), ('description', wagtail.core.fields.RichTextField()), - ('url', models.URLField(blank=True, null=True)), + ('url', models.URLField(blank=True)), ('topics', taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags')), ], options={ diff --git a/project/hangouts/migrations/0002_remove_hangout_url.py b/project/hangouts/migrations/0002_remove_hangout_url.py deleted file mode 100644 index ebb9d9f..0000000 --- a/project/hangouts/migrations/0002_remove_hangout_url.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.2.6 on 2021-12-06 08:15 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('hangouts', '0001_initial'), - ] - - operations = [ - migrations.RemoveField( - model_name='hangout', - name='url', - ), - ] diff --git a/project/hangouts/migrations/0003_hangout_url.py b/project/hangouts/migrations/0003_hangout_url.py deleted file mode 100644 index c82db63..0000000 --- a/project/hangouts/migrations/0003_hangout_url.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 3.2.6 on 2021-12-06 08:39 - -from django.db import migrations -import wagtail.core.blocks -import wagtail.core.fields - - -class Migration(migrations.Migration): - - dependencies = [ - ('hangouts', '0002_remove_hangout_url'), - ] - - operations = [ - migrations.AddField( - model_name='hangout', - name='url', - field=wagtail.core.fields.StreamField([('hangout_link', wagtail.core.blocks.URLBlock(form_classname='hangout link', required=False))], blank=True), - ), - ] diff --git a/project/hangouts/models.py b/project/hangouts/models.py index 4707731..0e11cb9 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -10,18 +10,7 @@ class Hangout(Page): description = RichTextField() topics = TaggableManager() - url = StreamField( - [ - ( - "hangout_link", - URLBlock(required=False, form_classname="hangout link"), - ), - ], - block_counts={ - 'hangout_link': {'max_num': 1}, - }, - blank=True, - ) + url = models.URLField(blank=True) content_panels = Page.content_panels + [ FieldPanel("description",classname="full"), FieldPanel("topics",classname="full"), From 233e30c6a96e38bd6c39044c9ef18c7eb2d1dfa9 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Tue, 7 Dec 2021 13:31:51 +0530 Subject: [PATCH 07/21] Renamed the field as --- project/hangouts/migrations/0001_initial.py | 4 ++-- project/hangouts/models.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/project/hangouts/migrations/0001_initial.py b/project/hangouts/migrations/0001_initial.py index cc4c07e..4b62b5a 100644 --- a/project/hangouts/migrations/0001_initial.py +++ b/project/hangouts/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.6 on 2021-12-07 07:37 +# Generated by Django 3.2.6 on 2021-12-07 07:57 from django.db import migrations, models import django.db.models.deletion @@ -32,7 +32,7 @@ class Migration(migrations.Migration): 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')), ('description', wagtail.core.fields.RichTextField()), - ('url', models.URLField(blank=True)), + ('hangouts_link', models.URLField(blank=True)), ('topics', taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags')), ], options={ diff --git a/project/hangouts/models.py b/project/hangouts/models.py index 0e11cb9..14d8e5e 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -10,11 +10,11 @@ class Hangout(Page): description = RichTextField() topics = TaggableManager() - url = models.URLField(blank=True) + hangouts_link = models.URLField(blank=True) content_panels = Page.content_panels + [ FieldPanel("description",classname="full"), FieldPanel("topics",classname="full"), - FieldPanel("url",classname="full") + FieldPanel("hangouts_link",classname="full") ] parent_page_types = [ "hangouts.HangoutsIndexPage", From 5a817163ba0de0456cc86da47b7c233ff32579bb Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Tue, 7 Dec 2021 10:08:14 +0200 Subject: [PATCH 08/21] Make home page resilient to missing pages --- project/home/models.py | 13 +++++++++++-- project/home/templates/home/home_page.html | 10 +++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/project/home/models.py b/project/home/models.py index d3b0b46..d54fd43 100644 --- a/project/home/models.py +++ b/project/home/models.py @@ -1,3 +1,4 @@ +from django.core.exceptions import ObjectDoesNotExist from django.db import models from wagtail.core.models import Page @@ -31,6 +32,14 @@ class HomePage(Page): def get_context(self, request): context = super().get_context(request) # Get Respective page objects in context for redirection and links - context["invite_friends_page"] = InviteFriendsPage.objects.get() - context["chapters_index_page"] = ChaptersIndexPage.objects.get() + try: + context["invite_friends_page"] = InviteFriendsPage.objects.get() + except ObjectDoesNotExist: + context["invite_friends_page"] = None + + try: + context["chapters_index_page"] = ChaptersIndexPage.objects.get() + except ObjectDoesNotExist: + context["chapters_index_page"] = None + return context diff --git a/project/home/templates/home/home_page.html b/project/home/templates/home/home_page.html index 28a9e16..52e8d23 100644 --- a/project/home/templates/home/home_page.html +++ b/project/home/templates/home/home_page.html @@ -20,14 +20,14 @@

{{ block.value }}

{% endif %} {% endfor %} -
- {% with invite_friends_page=invite_friends_page %} +
+ {% if invite_friends_page %}

{{ invite_friends_page.title }}

- {% endwith %} + {% endif %}
- {% with chapters_index_page=chapters_index_page %} + {% if chapters_index_page %}

{{ chapters_index_page.title }}

- {% endwith %} + {% endif %}
{% endblock content %} From 5613b9edeff7f36745402d34b0bc1ee568af5534 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Tue, 7 Dec 2021 10:10:53 +0200 Subject: [PATCH 09/21] Hangouts should be flat --- project/hangouts/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/project/hangouts/models.py b/project/hangouts/models.py index 14d8e5e..c54e6c0 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -19,6 +19,7 @@ class Hangout(Page): parent_page_types = [ "hangouts.HangoutsIndexPage", ] + subpage_types = [] class HangoutsIndexPage(Page): From 57c448c021443cc1d50ab8e162326701806ac453 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Tue, 7 Dec 2021 10:14:44 +0200 Subject: [PATCH 10/21] Lint --- project/hangouts/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/project/hangouts/models.py b/project/hangouts/models.py index c54e6c0..56542a0 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -11,6 +11,7 @@ class Hangout(Page): description = RichTextField() topics = TaggableManager() hangouts_link = models.URLField(blank=True) + content_panels = Page.content_panels + [ FieldPanel("description",classname="full"), FieldPanel("topics",classname="full"), From 97188eb163453a6d83f01f7958401c9c0de12e41 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Tue, 7 Dec 2021 10:14:55 +0200 Subject: [PATCH 11/21] Reset migrations --- project/hangouts/migrations/0001_initial.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/hangouts/migrations/0001_initial.py b/project/hangouts/migrations/0001_initial.py index 4b62b5a..55e2444 100644 --- a/project/hangouts/migrations/0001_initial.py +++ b/project/hangouts/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.6 on 2021-12-07 07:57 +# Generated by Django 3.2.6 on 2021-12-07 08:11 from django.db import migrations, models import django.db.models.deletion @@ -11,8 +11,8 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('taggit', '0003_taggeditem_add_unique_index'), ('wagtailcore', '0062_comment_models_and_pagesubscription'), + ('taggit', '0003_taggeditem_add_unique_index'), ] operations = [ From cbebbdbff7e2b321418b1b307783a67fdf1624ba Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Tue, 7 Dec 2021 14:21:59 +0530 Subject: [PATCH 12/21] Added 'truncate' tag to hangouts card in template --- project/hangouts/templates/hangouts/hangouts_index_page.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/hangouts/templates/hangouts/hangouts_index_page.html b/project/hangouts/templates/hangouts/hangouts_index_page.html index 06139fc..23a61ae 100644 --- a/project/hangouts/templates/hangouts/hangouts_index_page.html +++ b/project/hangouts/templates/hangouts/hangouts_index_page.html @@ -15,8 +15,8 @@

{{ page.title }}

{{ hangout.title }}
- {{ hangout.description | richtext }} - Go somewhere + {{ hangout.description | richtext | truncatewords:50 }} + Go somewhere
From 55133823cf87f6bc69b3e7fb465ec5294922f7ca Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Tue, 7 Dec 2021 14:22:22 +0530 Subject: [PATCH 13/21] Added hangout page template --- project/hangouts/templates/hangouts/hangout.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 project/hangouts/templates/hangouts/hangout.html diff --git a/project/hangouts/templates/hangouts/hangout.html b/project/hangouts/templates/hangouts/hangout.html new file mode 100644 index 0000000..d8445b8 --- /dev/null +++ b/project/hangouts/templates/hangouts/hangout.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block title %}{{ page.title }}{% endblock title %} + +{% load wagtailcore_tags %} + +{% block content %} +

{{ page.title }}

+ +{{ page.description | richtext }} + +{% endblock content %} From 710610996215680ceada8cee7711b5224085ace5 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Wed, 8 Dec 2021 10:48:55 +0530 Subject: [PATCH 14/21] ClusterTaggableManager for tags --- project/hangouts/migrations/0001_initial.py | 32 +++++++++++++++------ project/hangouts/models.py | 13 +++++++-- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/project/hangouts/migrations/0001_initial.py b/project/hangouts/migrations/0001_initial.py index 55e2444..aa74f6d 100644 --- a/project/hangouts/migrations/0001_initial.py +++ b/project/hangouts/migrations/0001_initial.py @@ -1,8 +1,9 @@ -# Generated by Django 3.2.6 on 2021-12-07 08:11 +# Generated by Django 3.2.6 on 2021-12-08 05:13 from django.db import migrations, models import django.db.models.deletion -import taggit.managers +import modelcluster.contrib.taggit +import modelcluster.fields import wagtail.core.fields @@ -17,10 +18,11 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='HangoutsIndexPage', + name='Hangout', 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')), - ('introduction', wagtail.core.fields.RichTextField()), + ('description', wagtail.core.fields.RichTextField()), + ('link', models.URLField(blank=True)), ], options={ 'abstract': False, @@ -28,16 +30,30 @@ class Migration(migrations.Migration): bases=('wagtailcore.page',), ), migrations.CreateModel( - name='Hangout', + name='HangoutsIndexPage', 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')), - ('description', wagtail.core.fields.RichTextField()), - ('hangouts_link', models.URLField(blank=True)), - ('topics', taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags')), + ('introduction', wagtail.core.fields.RichTextField()), ], options={ 'abstract': False, }, bases=('wagtailcore.page',), ), + migrations.CreateModel( + name='HangoutTag', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('content_object', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='tagged_items', to='hangouts.hangout')), + ('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='hangouts_hangouttag_items', to='taggit.tag')), + ], + options={ + 'abstract': False, + }, + ), + migrations.AddField( + model_name='hangout', + name='topics', + field=modelcluster.contrib.taggit.ClusterTaggableManager(blank=True, help_text='A comma-separated list of tags.', through='hangouts.HangoutTag', to='taggit.Tag', verbose_name='Tags'), + ), ] diff --git a/project/hangouts/models.py b/project/hangouts/models.py index 56542a0..8fecec2 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -4,18 +4,25 @@ from wagtail.core.fields import RichTextField, StreamField from wagtail.core.models import Page from wagtail.core.blocks import URLBlock +from modelcluster.contrib.taggit import ClusterTaggableManager +from taggit.models import Tag, TaggedItemBase +from modelcluster.fields import ParentalKey + + +class HangoutTag(TaggedItemBase): + content_object = ParentalKey('hangouts.Hangout', related_name='tagged_items', on_delete=models.CASCADE) # Create your models here. class Hangout(Page): description = RichTextField() - topics = TaggableManager() - hangouts_link = models.URLField(blank=True) + topics = ClusterTaggableManager(through=HangoutTag, blank=True) + link = models.URLField(blank=True) content_panels = Page.content_panels + [ FieldPanel("description",classname="full"), FieldPanel("topics",classname="full"), - FieldPanel("hangouts_link",classname="full") + FieldPanel("link",classname="full") ] parent_page_types = [ "hangouts.HangoutsIndexPage", From c54c8a0a4c4312d4b5045ecee38493c261e48d93 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Wed, 8 Dec 2021 10:50:59 +0530 Subject: [PATCH 15/21] Black and isort --- project/hangouts/models.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/project/hangouts/models.py b/project/hangouts/models.py index 8fecec2..b6fa79c 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -1,16 +1,18 @@ from django.db import models +from modelcluster.contrib.taggit import ClusterTaggableManager +from modelcluster.fields import ParentalKey from taggit.managers import TaggableManager +from taggit.models import Tag, TaggedItemBase from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel +from wagtail.core.blocks import URLBlock from wagtail.core.fields import RichTextField, StreamField from wagtail.core.models import Page -from wagtail.core.blocks import URLBlock -from modelcluster.contrib.taggit import ClusterTaggableManager -from taggit.models import Tag, TaggedItemBase -from modelcluster.fields import ParentalKey class HangoutTag(TaggedItemBase): - content_object = ParentalKey('hangouts.Hangout', related_name='tagged_items', on_delete=models.CASCADE) + content_object = ParentalKey( + "hangouts.Hangout", related_name="tagged_items", on_delete=models.CASCADE + ) # Create your models here. @@ -18,11 +20,11 @@ class Hangout(Page): description = RichTextField() topics = ClusterTaggableManager(through=HangoutTag, blank=True) link = models.URLField(blank=True) - + content_panels = Page.content_panels + [ - FieldPanel("description",classname="full"), - FieldPanel("topics",classname="full"), - FieldPanel("link",classname="full") + FieldPanel("description", classname="full"), + FieldPanel("topics", classname="full"), + FieldPanel("link", classname="full"), ] parent_page_types = [ "hangouts.HangoutsIndexPage", From ff20ae5dcaf8202c89129b665ef641e774ac8642 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Wed, 8 Dec 2021 11:21:55 +0530 Subject: [PATCH 16/21] Topics rendered on template Get Topics property fetches all the topics and displays them on the respective hangouts pages. --- project/hangouts/models.py | 13 +++++++++++++ project/hangouts/templates/hangouts/hangout.html | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/project/hangouts/models.py b/project/hangouts/models.py index b6fa79c..7586274 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -31,6 +31,19 @@ class Hangout(Page): ] subpage_types = [] + @property + def get_topics(self): + + topics = self.topics.all() + for topic in topics: + topic.url = '/' + '/'.join(s.strip('/') for s in [ + self.get_parent().url, + 'tags', + topic.slug + ]) + return topics + + class HangoutsIndexPage(Page): introduction = RichTextField() diff --git a/project/hangouts/templates/hangouts/hangout.html b/project/hangouts/templates/hangouts/hangout.html index d8445b8..d35b16d 100644 --- a/project/hangouts/templates/hangouts/hangout.html +++ b/project/hangouts/templates/hangouts/hangout.html @@ -7,6 +7,13 @@ {% block content %}

{{ page.title }}

+{% if page.get_topics %} + Topics:
+ {% for topic in page.get_topics %} + {{ topic }} + {% endfor %} +{% endif %} + {{ page.description | richtext }} {% endblock content %} From f05b49c3f43597ad8e59dc1d9c4bd2e7c1ab4e64 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Wed, 8 Dec 2021 13:28:46 +0530 Subject: [PATCH 17/21] Grouped hangouts based on topics Made use of RoutablePageMixin to route pages to url of /topics/. Only those hangouts which are available in the selected topic will be rendered. --- project/core/settings/base.py | 1 + project/hangouts/models.py | 36 +++++++++++++++++-- .../hangouts/hangouts_index_page.html | 8 +++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/project/core/settings/base.py b/project/core/settings/base.py index 18ffbde..181d04c 100644 --- a/project/core/settings/base.py +++ b/project/core/settings/base.py @@ -44,6 +44,7 @@ 'wagtail.admin', 'wagtail.core', 'wagtail.contrib.modeladmin', + "wagtail.contrib.routable_page", 'modelcluster', 'taggit', diff --git a/project/hangouts/models.py b/project/hangouts/models.py index 7586274..cace5af 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -1,12 +1,17 @@ from django.db import models +from django.shortcuts import redirect + from modelcluster.contrib.taggit import ClusterTaggableManager from modelcluster.fields import ParentalKey + from taggit.managers import TaggableManager from taggit.models import Tag, TaggedItemBase + from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel from wagtail.core.blocks import URLBlock from wagtail.core.fields import RichTextField, StreamField from wagtail.core.models import Page +from wagtail.contrib.routable_page.models import RoutablePageMixin, route class HangoutTag(TaggedItemBase): @@ -38,14 +43,14 @@ def get_topics(self): for topic in topics: topic.url = '/' + '/'.join(s.strip('/') for s in [ self.get_parent().url, - 'tags', + 'topics', topic.slug ]) return topics -class HangoutsIndexPage(Page): +class HangoutsIndexPage(RoutablePageMixin, Page): introduction = RichTextField() content_panels = Page.content_panels + [ @@ -66,6 +71,31 @@ def get_context(self, request, *args, **kwargs): self.allowed_subpage_models()[0] .objects.child_of(self) .live() - .order_by("title") + .order_by('-last_published_at') ) return context + + @route(r'^topics/$', name='topic_archive') + @route(r'^topics/([\w-]+)/$', name='topic_archive') + def tag_archive(self, request, topic=None): + + try: + topic = Tag.objects.get(slug=topic) + except Tag.DoesNotExist: + if topic: + msg = 'There are no hangouts in the topic "{}"'.format(topic) + messages.add_message(request, messages.INFO, msg) + return redirect(self.url) + + hangouts = self.get_hangouts(topic=topic) + + return self.render(request, context_overrides={ + 'topic': topic, + 'hangouts': hangouts + }) + + def get_hangouts(self, topic=None): + hangouts = Hangout.objects.live().descendant_of(self).order_by('-last_published_at') + if topic: + hangouts = hangouts.filter(topics=topic) + return hangouts diff --git a/project/hangouts/templates/hangouts/hangouts_index_page.html b/project/hangouts/templates/hangouts/hangouts_index_page.html index 23a61ae..4f9becb 100644 --- a/project/hangouts/templates/hangouts/hangouts_index_page.html +++ b/project/hangouts/templates/hangouts/hangouts_index_page.html @@ -9,6 +9,14 @@

{{ page.title }}

{{ page.introduction | richtext }} +{% if topic %} +
+
+

Viewing all hangouts of topic {{ topic }}

+
+
+{% endif %} +
{% for hangout in hangouts %}
From 11e618ea309f55287107360bde37824a9d0ee624 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Wed, 8 Dec 2021 13:33:16 +0530 Subject: [PATCH 18/21] Lint --- project/hangouts/models.py | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/project/hangouts/models.py b/project/hangouts/models.py index cace5af..b7edaa2 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -1,17 +1,14 @@ from django.db import models from django.shortcuts import redirect - from modelcluster.contrib.taggit import ClusterTaggableManager from modelcluster.fields import ParentalKey - from taggit.managers import TaggableManager from taggit.models import Tag, TaggedItemBase - from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel +from wagtail.contrib.routable_page.models import RoutablePageMixin, route from wagtail.core.blocks import URLBlock from wagtail.core.fields import RichTextField, StreamField from wagtail.core.models import Page -from wagtail.contrib.routable_page.models import RoutablePageMixin, route class HangoutTag(TaggedItemBase): @@ -41,15 +38,12 @@ def get_topics(self): topics = self.topics.all() for topic in topics: - topic.url = '/' + '/'.join(s.strip('/') for s in [ - self.get_parent().url, - 'topics', - topic.slug - ]) + topic.url = "/" + "/".join( + s.strip("/") for s in [self.get_parent().url, "topics", topic.slug] + ) return topics - class HangoutsIndexPage(RoutablePageMixin, Page): introduction = RichTextField() @@ -67,16 +61,11 @@ class HangoutsIndexPage(RoutablePageMixin, Page): def get_context(self, request, *args, **kwargs): context = super().get_context(request, *args, **kwargs) - context["hangouts"] = ( - self.allowed_subpage_models()[0] - .objects.child_of(self) - .live() - .order_by('-last_published_at') - ) + context["hangouts"] = self.get_hangouts() return context - @route(r'^topics/$', name='topic_archive') - @route(r'^topics/([\w-]+)/$', name='topic_archive') + @route(r"^topics/$", name="topic_archive") + @route(r"^topics/([\w-]+)/$", name="topic_archive") def tag_archive(self, request, topic=None): try: @@ -89,13 +78,14 @@ def tag_archive(self, request, topic=None): hangouts = self.get_hangouts(topic=topic) - return self.render(request, context_overrides={ - 'topic': topic, - 'hangouts': hangouts - }) + return self.render( + request, context_overrides={"topic": topic, "hangouts": hangouts} + ) def get_hangouts(self, topic=None): - hangouts = Hangout.objects.live().descendant_of(self).order_by('-last_published_at') + hangouts = ( + Hangout.objects.live().descendant_of(self).order_by("-last_published_at") + ) if topic: hangouts = hangouts.filter(topics=topic) return hangouts From efd8f84f4ba767c89c839e7cc69bc428211e51b5 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Wed, 8 Dec 2021 14:15:08 +0530 Subject: [PATCH 19/21] Topic selection on hangouts index Added translate tags Topics selected can be cleared using "clear" button --- project/hangouts/models.py | 7 +++++++ project/hangouts/templates/hangouts/hangout.html | 3 ++- .../templates/hangouts/hangouts_index_page.html | 14 +++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/project/hangouts/models.py b/project/hangouts/models.py index b7edaa2..002bbd6 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -89,3 +89,10 @@ def get_hangouts(self, topic=None): if topic: hangouts = hangouts.filter(topics=topic) return hangouts + + def get_child_topics(self): + topics = [] + for hangout in self.get_hangouts(): + topics += hangout.get_topics + topics = sorted(set(topics)) + return topics diff --git a/project/hangouts/templates/hangouts/hangout.html b/project/hangouts/templates/hangouts/hangout.html index d35b16d..93131ae 100644 --- a/project/hangouts/templates/hangouts/hangout.html +++ b/project/hangouts/templates/hangouts/hangout.html @@ -1,4 +1,5 @@ {% extends "base.html" %} +{% load i18n %} {% block title %}{{ page.title }}{% endblock title %} @@ -8,7 +9,7 @@

{{ page.title }}

{% if page.get_topics %} - Topics:
+ {% translate 'Topics:' %}
{% for topic in page.get_topics %} {{ topic }} {% endfor %} diff --git a/project/hangouts/templates/hangouts/hangouts_index_page.html b/project/hangouts/templates/hangouts/hangouts_index_page.html index 4f9becb..65697e1 100644 --- a/project/hangouts/templates/hangouts/hangouts_index_page.html +++ b/project/hangouts/templates/hangouts/hangouts_index_page.html @@ -1,4 +1,5 @@ {% extends "base.html" %} +{% load i18n %} {% block title %}{{ page.title }}{% endblock title %} @@ -12,11 +13,22 @@

{{ page.title }}

{% if topic %}
-

Viewing all hangouts of topic {{ topic }}

+ {% translate 'Viewing all hangouts of topic' %} {{ topic }} + + x {% translate 'Clear' %} +
{% endif %} +{% if page.get_child_topics %} + {% translate 'Topics:' %}
+ {% for topic in page.get_child_topics %} + {{ topic }} + {% endfor %} + +{% endif %} +
{% for hangout in hangouts %}
From f396cff8a731f0e11e2cec4351ec864407d3a7b0 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Thu, 9 Dec 2021 14:46:46 +0530 Subject: [PATCH 20/21] Removed for loop usage while fetching topics Iterating this way is not recommended when there is a huge amount of data in the database, as it slows down the retrieval. Made use of tag filtering with distinct() to fetch the topics and separated out the function that appended url to the topic --- project/hangouts/models.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/project/hangouts/models.py b/project/hangouts/models.py index 002bbd6..a3a29c3 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -10,6 +10,12 @@ from wagtail.core.fields import RichTextField, StreamField from wagtail.core.models import Page +def topics_with_url(topics,parent_url): + for topic in topics: + topic.url = "/" + "/".join( + s.strip("/") for s in [parent_url, "topics", topic.slug] + ) + return topics class HangoutTag(TaggedItemBase): content_object = ParentalKey( @@ -35,13 +41,9 @@ class Hangout(Page): @property def get_topics(self): - topics = self.topics.all() - for topic in topics: - topic.url = "/" + "/".join( - s.strip("/") for s in [self.get_parent().url, "topics", topic.slug] - ) - return topics + + return topics_with_url(topics,self.get_parent().url) class HangoutsIndexPage(RoutablePageMixin, Page): @@ -91,8 +93,5 @@ def get_hangouts(self, topic=None): return hangouts def get_child_topics(self): - topics = [] - for hangout in self.get_hangouts(): - topics += hangout.get_topics - topics = sorted(set(topics)) - return topics + topics = Tag.objects.filter(hangout__in=self.get_hangouts()).distinct() + return topics_with_url(topics,self.url) From d869fe349a811fcbaec6670ad7882daec6586562 Mon Sep 17 00:00:00 2001 From: Upasana Dhameliya Date: Thu, 9 Dec 2021 15:02:13 +0530 Subject: [PATCH 21/21] Docstring added to the function and lint --- project/hangouts/models.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/project/hangouts/models.py b/project/hangouts/models.py index a3a29c3..a88f81b 100644 --- a/project/hangouts/models.py +++ b/project/hangouts/models.py @@ -10,13 +10,18 @@ from wagtail.core.fields import RichTextField, StreamField from wagtail.core.models import Page -def topics_with_url(topics,parent_url): + +def topics_with_url(topics, parent_url): + """ + Adding a URL to access Hangouts objects of the same tag + """ for topic in topics: topic.url = "/" + "/".join( s.strip("/") for s in [parent_url, "topics", topic.slug] ) return topics + class HangoutTag(TaggedItemBase): content_object = ParentalKey( "hangouts.Hangout", related_name="tagged_items", on_delete=models.CASCADE @@ -43,7 +48,7 @@ class Hangout(Page): def get_topics(self): topics = self.topics.all() - return topics_with_url(topics,self.get_parent().url) + return topics_with_url(topics, self.get_parent().url) class HangoutsIndexPage(RoutablePageMixin, Page): @@ -94,4 +99,4 @@ def get_hangouts(self, topic=None): def get_child_topics(self): topics = Tag.objects.filter(hangout__in=self.get_hangouts()).distinct() - return topics_with_url(topics,self.url) + return topics_with_url(topics, self.url)