Skip to content

Commit

Permalink
Remove configurable and dynamic background images from the Cotton Can…
Browse files Browse the repository at this point in the history
…dy theme. (bartfeenstra#911)
  • Loading branch information
bartfeenstra authored Nov 12, 2022
1 parent 76f1ef3 commit cd895f6
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 128 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ extensions:
betty.anonymizer.Anonymizer: {}
betty.cleaner.Cleaner: {}
betty.cotton_candy.CottonCandy:
background_image_id: O0301
featured_entities:
- entity_type: Person
entity_id: P123
Expand Down Expand Up @@ -140,8 +139,6 @@ extensions:
- `betty.anonymizer.Anonymizer` (optional): Removes personal information from private people. It provides no
configuration options.
- `betty.cotton_candy.CottonCandy` (optional): Configuration:
- `background_image_id` (optional): The ID of the file entity whose (image) file to use for page backgrounds if
a page does not provide any image media itself.
- `featured_entities` (optional): A list of entities to feature on the front page. Each item has the following
configuration:
- `entity_type` (required): The name of the entity type to feature, e.g. `Person`.
Expand Down
8 changes: 1 addition & 7 deletions betty/assets/betty.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Betty VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-11-07 23:23+0000\n"
"POT-Creation-Date: 2022-11-12 03:18+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -177,9 +177,6 @@ msgstr ""
msgid "Author"
msgstr ""

msgid "Background image"
msgstr ""

msgid "Baptism"
msgstr ""

Expand Down Expand Up @@ -677,9 +674,6 @@ msgstr ""
msgid "The ID for the resource to retrieve."
msgstr ""

msgid "The ID of the file entity whose (image) file to use for page backgrounds if a page does not provide any image media itself."
msgstr ""

msgid "The age at which people are presumed dead."
msgstr ""

Expand Down
10 changes: 1 addition & 9 deletions betty/assets/locale/fr_FR/LC_MESSAGES/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-11-07 23:23+0000\n"
"POT-Creation-Date: 2022-11-12 03:18+0000\n"
"PO-Revision-Date: 2020-11-27 19:49+0100\n"
"Last-Translator: \n"
"Language: fr\n"
Expand Down Expand Up @@ -228,9 +228,6 @@ msgstr "Participant"
msgid "Author"
msgstr "Non autorisé"

msgid "Background image"
msgstr ""

msgid "Baptism"
msgstr "Baptême"

Expand Down Expand Up @@ -777,11 +774,6 @@ msgstr "Sujet"
msgid "The ID for the resource to retrieve."
msgstr "L'ID de la ressource à récupérer."

msgid ""
"The ID of the file entity whose (image) file to use for page backgrounds "
"if a page does not provide any image media itself."
msgstr ""

msgid "The age at which people are presumed dead."
msgstr ""

Expand Down
12 changes: 1 addition & 11 deletions betty/assets/locale/nl_NL/LC_MESSAGES/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-11-07 23:23+0000\n"
"POT-Creation-Date: 2022-11-12 03:18+0000\n"
"PO-Revision-Date: 2022-04-08 01:58+0100\n"
"Last-Translator: \n"
"Language: nl\n"
Expand Down Expand Up @@ -243,9 +243,6 @@ msgstr "Aanwezige"
msgid "Author"
msgstr "Auteur"

msgid "Background image"
msgstr "Achtergrondafbeelding"

msgid "Baptism"
msgstr "Doping"

Expand Down Expand Up @@ -795,13 +792,6 @@ msgstr "Onderwerp"
msgid "The ID for the resource to retrieve."
msgstr "Het ID van het op te halen document."

msgid ""
"The ID of the file entity whose (image) file to use for page backgrounds "
"if a page does not provide any image media itself."
msgstr ""
"Het ID van de bestandsentiteit waarvan de afbeelding gebruikt wordt voor "
"de achtergrond van pagina's waarvoor geen afbeeldingen beschikbaar zijn."

msgid "The age at which people are presumed dead."
msgstr "De leeftijd waarop mensen overleden verondersteld worden"

Expand Down
10 changes: 1 addition & 9 deletions betty/assets/locale/uk/LC_MESSAGES/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Betty VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-11-07 23:23+0000\n"
"POT-Creation-Date: 2022-11-12 03:18+0000\n"
"PO-Revision-Date: 2020-05-02 22:29+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: uk\n"
Expand Down Expand Up @@ -221,9 +221,6 @@ msgstr "Відвідувач"
msgid "Author"
msgstr "Автор(а)"

msgid "Background image"
msgstr ""

msgid "Baptism"
msgstr "Хрещення"

Expand Down Expand Up @@ -761,11 +758,6 @@ msgstr "Предмет"
msgid "The ID for the resource to retrieve."
msgstr ""

msgid ""
"The ID of the file entity whose (image) file to use for page backgrounds "
"if a page does not provide any image media itself."
msgstr ""

msgid "The age at which people are presumed dead."
msgstr ""

Expand Down
18 changes: 1 addition & 17 deletions betty/cotton_candy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
from betty.error import ensure_context
from betty.gui import GuiBuilder
from betty.jinja2 import Jinja2Provider
from betty.model.ancestry import File
from betty.npm import _Npm, NpmBuilder
from betty.project import EntityReference, EntityReferences
from betty.project import EntityReferences

if TYPE_CHECKING:
from betty.builtins import _
Expand All @@ -23,19 +22,9 @@
class CottonCandyConfiguration(Configuration):
def __init__(self):
super().__init__()
self._background_image = EntityReference(entity_type_constraint=File)
self._featured_entities = EntityReferences()
self._featured_entities.react(self)

@reactive # type: ignore
@property
def background_image(self) -> EntityReference:
return self._background_image

@background_image.setter
def background_image(self, background_image: EntityReference) -> None:
self._background_image = background_image

@property
def featured_entities(self) -> EntityReferences:
return self._featured_entities
Expand All @@ -44,17 +33,12 @@ def load(self, dumped_configuration: DumpedConfiguration) -> None:
if not isinstance(dumped_configuration, dict):
raise ConfigurationError(_('The theme configuration must be a mapping (dictionary).'))

if 'background_image_id' in dumped_configuration:
with ensure_context('background_image_id'):
self.background_image.load(dumped_configuration['background_image_id'])

if 'featured_entities' in dumped_configuration:
with ensure_context('featured_entities'):
self.featured_entities.load(dumped_configuration['featured_entities'])

def dump(self) -> DumpedConfiguration:
return minimize_dumped_configuration({
'background_image_id': self._background_image.dump(),
'featured_entities': self.featured_entities.dump(),
})

Expand Down
20 changes: 0 additions & 20 deletions betty/cotton_candy/assets/public/static/css/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,6 @@ body > * {
z-index: 1;
}

#background-header {
background-position: center;
height: 9rem;
z-index: -1;
}

#background-footer {
background-position: bottom center;
bottom: 0;
height: 100%;
z-index: -2;
}

.background {
background-size: cover;
filter: blur(2px) grayscale(50%);
position: absolute;
width: 100%;
}

/*
* Footer.
*/
Expand Down
9 changes: 0 additions & 9 deletions betty/cotton_candy/assets/templates/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,10 @@
<script src="{{ '/search.js' | static_url }}" defer></script>
<script src="{{ '/show.js' | static_url }}" defer></script>
</head>
{% if page_resource is has_files %}
{% set page_image = page_resource.associated_files | selectattr('media_type.type', 'eq', 'image') | first %}
{% elif app.extensions['betty.cotton_candy.CottonCandy'].configuration.background_image.entity_id and app.extensions['betty.cotton_candy.CottonCandy'].configuration.background_image.entity_id in app.project.ancestry.entities['File'] %}
{% set page_image = app.project.ancestry.entities['File'][app.extensions['betty.cotton_candy.CottonCandy'].configuration.background_image.entity_id] %}
{% endif %}
<body>
<script>
document.body.classList.add('with-js');
</script>
{% if page_image is defined %}
<div id="background-header" class="background" style="background-image: url({{ page_image | image(600, 600) | static_url }});"></div>
<div id="background-footer" class="background" style="background-image: url({{ page_image | image(600, 600) | static_url }});"></div>
{% endif %}
<div id="page">
<nav id="nav-primary">
<a id="site-title" href="{{ '/index.html' | url }}" title="{{ app.project.configuration.title }}">{{ app.project.configuration.title }}</a>
Expand Down
15 changes: 1 addition & 14 deletions betty/cotton_candy/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from betty.app import App
from betty.cotton_candy import CottonCandy
from betty.gui.model import EntityReferenceCollector, EntityReferencesCollector
from betty.gui.text import Caption
from betty.gui.model import EntityReferencesCollector

if TYPE_CHECKING:
from betty.builtins import _
Expand All @@ -19,18 +18,6 @@ def __init__(self, app: App, *args, **kwargs):
self._layout = QVBoxLayout()
self.setLayout(self._layout)

self._background_image_label = QLabel()
self._layout.addWidget(self._background_image_label)
self._background_image_entity_reference_collector = EntityReferenceCollector(
self._app,
self._app.extensions[CottonCandy].configuration.background_image,
lambda: _('Background image'),
lambda: _('The ID of the file entity whose (image) file to use for page backgrounds if a page does not provide any image media itself.'),
)
self._layout.addWidget(self._background_image_entity_reference_collector)
self._background_image_caption = Caption()
self._layout.addWidget(self._background_image_caption)

self._featured_entities_label = QLabel()
self._layout.addWidget(self._featured_entities_label)
self._featured_entities_entity_references_collector = EntityReferencesCollector(
Expand Down
18 changes: 0 additions & 18 deletions betty/tests/cotton_candy/test___init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,11 @@ def test_load_without_dict_should_error(self) -> None:
with pytest.raises(ConfigurationError):
CottonCandyConfiguration().load(dumped_configuration)

def test_load_should_load_theme_background_image_id(self) -> None:
background_image_id = 'my-favorite-picture'
dumped_configuration = {
'background_image_id': background_image_id
}
configuration = CottonCandyConfiguration()
configuration.load(dumped_configuration)
assert background_image_id == configuration.background_image.entity_id

def test_dump_with_minimal_configuration(self) -> None:
sut = CottonCandyConfiguration()
expected = Void
assert expected == sut.dump()

def test_dump_with_background_image_id(self) -> None:
sut = CottonCandyConfiguration()
background_image_id = '123'
sut.background_image.entity_id = background_image_id
expected = {
'background_image_id': background_image_id,
}
assert expected == sut.dump()

def test_dump_with_featured_entities(self) -> None:
sut = CottonCandyConfiguration()
entity_type = Entity
Expand Down
11 changes: 0 additions & 11 deletions betty/tests/cotton_candy/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@


class TestCottonCandyGuiWidget:
def test_background_image(self, qtbot: QtBot) -> None:
with App() as app:
app.project.configuration.extensions.enable(CottonCandy)
sut = _CottonCandyGuiWidget(app)
qtbot.addWidget(sut)
sut.show()

background_image_id = 'O0301'
sut._background_image_entity_reference_collector._entity_id.setText(background_image_id)
assert app.extensions[CottonCandy].configuration.background_image.entity_id == background_image_id

def test_add_featured_entities(self, qtbot: QtBot) -> None:
with App() as app:
app.project.configuration.extensions.enable(CottonCandy)
Expand Down

0 comments on commit cd895f6

Please sign in to comment.