Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Many to many playground #341

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions joplin/base/migrations/0082_servicepage_related_topics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.4 on 2019-08-21 22:36

from django.db import migrations
import modelcluster.fields


class Migration(migrations.Migration):

dependencies = [
('base', '0081_auto_20190807_1916'),
]

operations = [
migrations.AddField(
model_name='servicepage',
name='related_topics',
field=modelcluster.fields.ParentalManyToManyField(blank=True, to='base.TopicPage'),
),
]
19 changes: 19 additions & 0 deletions joplin/base/migrations/0083_topicpage_related_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.4 on 2019-08-21 22:47

from django.db import migrations
import modelcluster.fields


class Migration(migrations.Migration):

dependencies = [
('base', '0082_servicepage_related_topics'),
]

operations = [
migrations.AddField(
model_name='topicpage',
name='related_pages',
field=modelcluster.fields.ParentalManyToManyField(blank=True, to='base.ServicePage'),
),
]
54 changes: 33 additions & 21 deletions joplin/base/models/service_page.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.db import models
from django import forms

from modelcluster.models import ClusterableModel
from modelcluster.fields import ParentalKey
from modelcluster.fields import ParentalKey, ParentalManyToManyField

from wagtail.core.fields import RichTextField, StreamField
from wagtail.core.blocks import ListBlock, RichTextBlock, StructBlock, TextBlock
Expand All @@ -17,8 +18,10 @@
from .constants import WYSIWYG_GENERAL, SHORT_DESCRIPTION_LENGTH
WYSIWYG_SERVICE_STEP = ['ul', 'ol', 'link', 'code', 'rich-text-button-link']


class ServicePage(JanisBasePage):
janis_url_page_type = "services"
related_topics = ParentalManyToManyField('base.TopicPage', blank=True)

steps = StreamField(
[
Expand All @@ -28,7 +31,8 @@ class ServicePage(JanisBasePage):
)),
('step_with_options_accordian', StructBlock(
[
('options_description', TextBlock('Describe the set of options')),
('options_description', TextBlock(
'Describe the set of options')),
('options', ListBlock(
StructBlock([
('option_name', TextBlock(
Expand Down Expand Up @@ -84,30 +88,34 @@ class ServicePage(JanisBasePage):
InlinePanel('topics', label='Topics'),
InlinePanel('related_departments', label='Related Departments'),
MultiFieldPanel(
[
HelpPanel(steps.help_text, classname="coa-helpPanel"),
StreamFieldPanel('steps')
],
heading=steps.verbose_name,
classname='coa-multiField-nopadding'
[
HelpPanel(steps.help_text, classname="coa-helpPanel"),
StreamFieldPanel('steps')
],
heading=steps.verbose_name,
classname='coa-multiField-nopadding'
),
StreamFieldPanel('dynamic_content'),
MultiFieldPanel(
[
HelpPanel(additional_content.help_text, classname="coa-helpPanel"),
FieldPanel('additional_content')
],
heading=additional_content.verbose_name,
classname='coa-multiField-nopadding'
)
,
[
HelpPanel(additional_content.help_text,
classname="coa-helpPanel"),
FieldPanel('additional_content')
],
heading=additional_content.verbose_name,
classname='coa-multiField-nopadding'
),
InlinePanel('contacts', label='Contacts'),
FieldPanel('related_topics', widget=forms.CheckboxSelectMultiple)
]


class ServicePageTopic(ClusterableModel):
page = ParentalKey(ServicePage, related_name='topics')
topic = models.ForeignKey('base.TopicPage', verbose_name='Select a Topic', related_name='+', on_delete=models.CASCADE)
toplink = models.BooleanField(default=False, verbose_name='Make this service a top link for this topic')
topic = models.ForeignKey(
'base.TopicPage', verbose_name='Select a Topic', related_name='+', on_delete=models.CASCADE)
toplink = models.BooleanField(
default=False, verbose_name='Make this service a top link for this topic')

panels = [
MultiFieldPanel(
Expand All @@ -121,9 +129,11 @@ class ServicePageTopic(ClusterableModel):
def __str__(self):
return self.topic.title


class ServicePageContact(ClusterableModel):
page = ParentalKey(ServicePage, related_name='contacts')
contact = models.ForeignKey(Contact, related_name='+', on_delete=models.CASCADE)
contact = models.ForeignKey(
Contact, related_name='+', on_delete=models.CASCADE)

panels = [
SnippetChooserPanel('contact'),
Expand All @@ -132,8 +142,10 @@ class ServicePageContact(ClusterableModel):
def __str__(self):
return self.contact.name


class ServicePageRelatedDepartments(ClusterableModel):
page = ParentalKey(ServicePage, related_name='related_departments', default=None)
page = ParentalKey(
ServicePage, related_name='related_departments', default=None)
related_department = models.ForeignKey(
"base.departmentPage",
on_delete=models.PROTECT,
Expand All @@ -142,4 +154,4 @@ class ServicePageRelatedDepartments(ClusterableModel):
panels = [
# Use a SnippetChooserPanel because blog.BlogAuthor is registered as a snippet
PageChooserPanel("related_department"),
]
]
18 changes: 13 additions & 5 deletions joplin/base/models/topic_page.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.db import models
from django import forms

from modelcluster.models import ClusterableModel
from modelcluster.fields import ParentalKey
from modelcluster.fields import ParentalKey, ParentalManyToManyField

from wagtail.core.fields import StreamField
from wagtail.core.blocks import CharBlock, StructBlock, URLBlock
Expand All @@ -13,12 +14,15 @@
from .janis_page import JanisBasePage
from .translated_image import TranslatedImage


class TopicPage(JanisBasePage):
janis_url_page_type = "topic"

description = models.TextField(blank=True)
related_pages = ParentalManyToManyField('base.ServicePage', blank=True)

image = models.ForeignKey(TranslatedImage, null=True, blank=True, on_delete=models.SET_NULL, related_name='+')
image = models.ForeignKey(TranslatedImage, null=True,
blank=True, on_delete=models.SET_NULL, related_name='+')

external_services = StreamField(
[
Expand Down Expand Up @@ -53,16 +57,20 @@ class TopicPage(JanisBasePage):
FieldPanel('description'),
ImageChooserPanel('image'),
StreamFieldPanel('external_services'),
InlinePanel('topiccollections', label='Topic Collections this page belongs to'),
InlinePanel('topiccollections',
label='Topic Collections this page belongs to'),
FieldPanel('related_pages', widget=forms.CheckboxSelectMultiple)
]


class TopicPageTopicCollection(ClusterableModel):
page = ParentalKey(TopicPage, related_name='topiccollections')
topiccollection = models.ForeignKey('base.TopicCollectionPage', verbose_name='Select a Topic Collection', related_name='+', on_delete=models.CASCADE)
topiccollection = models.ForeignKey(
'base.TopicCollectionPage', verbose_name='Select a Topic Collection', related_name='+', on_delete=models.CASCADE)

panels = [
PageChooserPanel('topiccollection'),
]

def __str__(self):
return self.topiccollection.text
return self.topiccollection.text
Loading