Skip to content

Commit

Permalink
Merge branch 'TP1-168-strange-horizontal-panning-on-opportunity-pages…
Browse files Browse the repository at this point in the history
…-on' of github-mf:MozillaFoundation/foundation.mozilla.org into TP1-168-strange-horizontal-panning-on-opportunity-pages-on
  • Loading branch information
ramram-mf committed Jun 11, 2024
2 parents 37ee44a + 6ec9352 commit 21ab9e2
Show file tree
Hide file tree
Showing 116 changed files with 1,019 additions and 569 deletions.
16 changes: 16 additions & 0 deletions copy-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ if (APP === STAGE_APP) {
);
}

if (!isLoggedInToHeroku()) {
console.log(
"You are not logged into Heroku. Make sure you have the Heroku CLI installed. Run `heroku login` and try again."
);
process.exit(1);
}

const HEROKU_OUTPUT = run(`heroku config:get DATABASE_URL -a ${APP}`);
const HEROKU_TEXT = HEROKU_OUTPUT.toString().replaceAll(`\n`, ` `);
const URL_START = HEROKU_TEXT.indexOf(`postgres://`);
Expand Down Expand Up @@ -71,6 +78,15 @@ function stopContainers() {
}
}

function isLoggedInToHeroku() {
try {
execSync("heroku whoami");
return true;
} catch (error) {
return false;
}
}

// ======================== //
// Our script starts here //
// ======================== //
Expand Down
6 changes: 3 additions & 3 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ django==4.2.11
# via
# -c requirements.txt
# django-debug-toolbar
django-debug-toolbar==4.3.0
django-debug-toolbar==4.4.2
# via -r dev-requirements.in
djhtml==3.0.6
# via -r dev-requirements.in
Expand Down Expand Up @@ -72,15 +72,15 @@ pathspec==0.11.1
# djlint
platformdirs==2.5.3
# via black
pluggy==1.4.0
pluggy==1.5.0
# via pytest
ptvsd==4.3.2
# via -r dev-requirements.in
pycodestyle==2.11.0
# via flake8
pyflakes==3.2.0
# via flake8
pytest==8.1.1
pytest==8.2.2
# via
# -r dev-requirements.in
# pytest-cov
Expand Down

This file was deleted.

20 changes: 0 additions & 20 deletions network-api/networkapi/donate/factory/customblocks/notice_block.py

This file was deleted.

7 changes: 3 additions & 4 deletions network-api/networkapi/donate/factory/help_page.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import wagtail_factories
from factory import Faker, SubFactory
from wagtail_factories import PageFactory

from networkapi.donate.factory.customblocks.notice_block import NoticeBlockFactory
from networkapi.donate.factory.snippets.help_page_notice import HelpPageNoticeFactory
from networkapi.donate.models import DonateHelpPage, DonateLandingPage
from networkapi.utility.faker import StreamfieldProvider
from networkapi.utility.faker.helpers import reseed
Expand All @@ -18,12 +17,12 @@ class Meta:

title = Faker("sentence", nb_words=2)
body = Faker("streamfield", fields=streamfield_fields)
notice = wagtail_factories.StreamFieldFactory({"notice": SubFactory(NoticeBlockFactory)})
notice = SubFactory(HelpPageNoticeFactory)


def generate(seed):
reseed(seed)

print("Generating a Help page")
home_page = DonateLandingPage.objects.get(title="Donate Now")
DonateHelpPageFactory(parent=home_page, title="Donate Help", slug="help", notice__0="notice")
DonateHelpPageFactory(parent=home_page, title="Donate Help", slug="help")
22 changes: 22 additions & 0 deletions network-api/networkapi/donate/factory/snippets/help_page_notice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import factory
from factory import Faker, LazyAttribute
from wagtail.rich_text import RichText
from wagtail_factories import ImageFactory

from networkapi.donate.snippets.help_page_notice import HelpPageNotice

notice_text_contents = Faker("paragraph", nb_sentences=3, variable_nb_sentences=False)


class HelpPageNoticeFactory(factory.django.DjangoModelFactory):
class Meta:
model = HelpPageNotice
exclude = ("notice_text",)

name = Faker("sentence", nb_words=3)
text = LazyAttribute(lambda o: RichText(f"<p>{o.notice_text}</p>"))
notice_image = factory.SubFactory(ImageFactory)
notice_image_alt_text = Faker("sentence", nb_words=4)

# Lazy Values
notice_text = notice_text_contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Generated by Django 4.2.11 on 2024-05-22 22:22

import uuid

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


class Migration(migrations.Migration):

dependencies = [
("donate", "0010_make_link_to_required_in_link_block"),
]

operations = [
migrations.RemoveField(
model_name="donatehelppage",
name="notice",
),
migrations.CreateModel(
name="HelpPageNotice",
fields=[
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("translation_key", models.UUIDField(default=uuid.uuid4, editable=False)),
("name", models.CharField(help_text="What will this notice be called in the CMS?", max_length=50)),
("text", wagtail.fields.RichTextField()),
(
"notice_image_alt_text",
models.CharField(blank=True, help_text="Image description (for screen readers).", max_length=50),
),
(
"locale",
models.ForeignKey(
editable=False,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="wagtailcore.locale",
),
),
(
"notice_image",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="wagtailimages.image",
verbose_name="Notice Image",
),
),
],
options={
"abstract": False,
"unique_together": {("translation_key", "locale")},
},
),
migrations.AddField(
model_name="donatehelppage",
name="notice",
field=models.ForeignKey(
blank=True,
help_text="Optional notice that will render at the top of the page.",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="donate.helppagenotice",
),
),
]

This file was deleted.

13 changes: 7 additions & 6 deletions network-api/networkapi/donate/pagemodels/help_page.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from urllib.parse import urlencode

from django.db import models
from wagtail.admin.panels import FieldPanel
from wagtail.fields import StreamField
from wagtail.models import Page
from wagtail_localize.fields import SynchronizedField, TranslatableField

from networkapi.donate.models import BaseDonationPage
from networkapi.donate.pagemodels.customblocks.notice_block import NoticeBlock
from networkapi.donate.snippets.help_page_notice import HelpPageNotice
from networkapi.wagtailpages.pagemodels.customblocks.base_fields import base_fields


Expand All @@ -19,12 +20,12 @@ class DonateHelpPage(BaseDonationPage):

max_count = 1

notice = StreamField(
[("notice", NoticeBlock())],
help_text="Optional notice that will render at the top of the page.",
notice = models.ForeignKey(
HelpPageNotice,
null=True,
blank=True,
max_num=1,
use_json_field=True,
on_delete=models.SET_NULL,
help_text="Optional notice that will render at the top of the page.",
)

body = StreamField(base_fields, blank=True, use_json_field=True)
Expand Down
Empty file.
53 changes: 53 additions & 0 deletions network-api/networkapi/donate/snippets/help_page_notice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from django.core.exceptions import ValidationError
from django.db import models
from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField
from wagtail.models import TranslatableMixin
from wagtail_localize.fields import SynchronizedField, TranslatableField

from networkapi.wagtailpages.pagemodels.customblocks.base_rich_text_options import (
base_rich_text_options,
)


class HelpPageNotice(TranslatableMixin, models.Model):
name = models.CharField(max_length=50, help_text="What will this notice be called in the CMS?")

text = RichTextField(
features=base_rich_text_options,
blank=False,
)
notice_image = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
verbose_name="Notice Image",
)
notice_image_alt_text = models.CharField(
max_length=50, blank=True, help_text="Image description (for screen readers)."
)

panels = [
FieldPanel("name"),
FieldPanel("text"),
FieldPanel("notice_image"),
FieldPanel("notice_image_alt_text"),
]

translatable_fields = [
SynchronizedField("name"),
TranslatableField("text"),
SynchronizedField("notice_image"),
TranslatableField("notice_image_alt_text"),
]

def __str__(self):
return self.name

def clean(self):
super().clean()
if self.notice_image and not self.notice_image_alt_text:
raise ValidationError({"notice_image_alt_text": "Image must include alt text."})
if self.notice_image_alt_text and not self.notice_image:
raise ValidationError({"notice_image": "Alt text must have an associated image."})
Loading

0 comments on commit 21ab9e2

Please sign in to comment.