Skip to content

Commit

Permalink
feat: add custom fafanuka page model
Browse files Browse the repository at this point in the history
Signed-off-by: MelvinKim <melvin.kimathi@savannahinformatics.com>
Signed-off-by: MelvinKim <melobruk1@gmail.com>
  • Loading branch information
MelvinKim committed Mar 24, 2023
1 parent 86abe4e commit 220cc35
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ steps:
[
"build",
"-t",
"europe-west1-docker.pkg.dev/$PROJECT_ID/sghi/mycarehub-${_DEPLOYMENT_TYPE}:$COMMIT_SHA",
"europe-west1-docker.pkg.dev/$PROJECT_ID/bewell-app/fafanuka-${_DEPLOYMENT_TYPE}:$COMMIT_SHA",
".",
]

# Push the container image to Container Registry
- name: "gcr.io/cloud-builders/docker"
args:
["push", "europe-west1-docker.pkg.dev/$PROJECT_ID/sghi/mycarehub-${_DEPLOYMENT_TYPE}:$COMMIT_SHA"]
["push", "europe-west1-docker.pkg.dev/$PROJECT_ID/bewell-app/fafanuka-${_DEPLOYMENT_TYPE}:$COMMIT_SHA"]

# Deploy an image from Container Registry to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
Expand All @@ -21,7 +21,7 @@ steps:
'run',
'deploy',
'${_SERVICE_NAME}',
'--image', 'europe-west1-docker.pkg.dev/$PROJECT_ID/sghi/mycarehub-${_DEPLOYMENT_TYPE}:$COMMIT_SHA',
'--image', 'europe-west1-docker.pkg.dev/$PROJECT_ID/bewell-app/fafanuka-${_DEPLOYMENT_TYPE}:$COMMIT_SHA',
'--region', 'europe-west1',
'--platform', 'managed',
'--allow-unauthenticated',
Expand All @@ -36,7 +36,7 @@ steps:
]

images:
- "europe-west1-docker.pkg.dev/$PROJECT_ID/sghi/mycarehub-${_DEPLOYMENT_TYPE}:$COMMIT_SHA"
- "europe-west1-docker.pkg.dev/$PROJECT_ID/bewell-app/fafanuka-${_DEPLOYMENT_TYPE}:$COMMIT_SHA"

timeout: 1200s
queueTtl: 3600s
32 changes: 32 additions & 0 deletions mycarehub/content/migrations/0008_fafanukacontentitem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 3.2.18 on 2023-03-21 10:21

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


class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0078_referenceindex'),
('common', '0006_auto_20230214_1434'),
('content', '0007_alter_customimage_options'),
]

operations = [
migrations.CreateModel(
name='FafanukaContentItem',
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')),
('date', models.DateField(help_text='This will be shown to readers as the publication date', verbose_name='Post date')),
('category', models.CharField(choices=[('JUST_CURIOUS', 'Just Curious'), ('TYPE 1', 'Type 1'), ('TYPE 2', 'Type 2'), ('GESTATIONAL', 'Gestational')], max_length=64)),
('english_content', models.CharField(max_length=160)),
('kiswahili_content', models.CharField(max_length=160)),
('organisation', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='content_fafanukacontentitem_related', to='common.organisation')),
('program', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='content_fafanukacontentitem_related', to='common.program')),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
]
2 changes: 2 additions & 0 deletions mycarehub/content/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .documents import CustomDocument
from .fafanuka import FafanukaContentItem
from .images import CustomImage, CustomRendition
from .interactions import ContentBookmark, ContentLike, ContentShare, ContentView
from .media import CustomMedia
Expand Down Expand Up @@ -37,4 +38,5 @@
"CustomImage",
"CustomRendition",
"CustomDocument",
"FafanukaContentItem",
]
85 changes: 85 additions & 0 deletions mycarehub/content/models/fafanuka.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from django.db import models
from wagtail.admin.panels import FieldPanel, MultiFieldPanel
from wagtail.api import APIField
from wagtail.models import Page
from wagtail.search import index

from mycarehub.common.models import Organisation, Program


class FafanukaContentItem(Page):
"""
A `FafanukaContentItem` represents the content periodically
sent to Fafanuka subscribers.
"""

class ItemTypes(models.TextChoices):
GENERAL_TIPS = "GENERAL DIABETES TIPS"
TYPE_1 = "TYPE 1 DIABETES "
TYPE_2 = "TYPE 2 DIABETES "
GESTATIONAL = "GESTATIONAL DIABETES "

# basic properties that each post has
organisation = models.ForeignKey(
Organisation,
on_delete=models.PROTECT,
null=True,
blank=True,
related_name="%(app_label)s_%(class)s_related",
)

program = models.ForeignKey(
Program,
on_delete=models.PROTECT,
null=True,
blank=True,
related_name="%(app_label)s_%(class)s_related",
)

date = models.DateField(
"Post date",
help_text="This will be shown to readers as the publication date",
)
category = models.CharField(
max_length=64,
choices=ItemTypes.choices,
)
english_content = models.CharField(
max_length=160,
)
kiswahili_content = models.CharField(
max_length=160,
)
content_panels = Page.content_panels + [
MultiFieldPanel(
[
FieldPanel("date"),
FieldPanel("category"),
],
heading="About",
),
FieldPanel("english_content", classname="full"),
FieldPanel("kiswahili_content", classname="full"),
]

# these fields determine the content that is indexed for search purposes
search_fields = Page.search_fields + [
index.SearchField("category"),
index.SearchField("english_content"),
index.SearchField("kiswahili_content"),
]

# this configuration allows these custom fields to be available over the API
api_fields = [
APIField("date"),
APIField("category"),
APIField("english_content"),
APIField("kiswahili_content"),
]

# limit the parent page types
parent_page_type = [
"content.ContentItemIndexPage",
]

subpage_types = [] # type: ignore
1 change: 1 addition & 0 deletions mycarehub/content/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class ContentItemIndexPage(Page):
]
subpage_types = [
"content.ContentItem",
"content.FafanukaContentItem",
]

def get_context(self, request):
Expand Down

0 comments on commit 220cc35

Please sign in to comment.