Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Betty 0.4 #102

Open
wants to merge 1 commit into
base: main
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
12 changes: 6 additions & 6 deletions ancestry/cli.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import click

from betty.app import App
from betty.cli import app_command
from betty.cli import pass_project, command
from betty.project import Project

from ancestry.report import report


@click.command(help="Generate an ancestry report.")
@app_command
async def _report(app: App) -> None:
await report(app)
@pass_project
@command
async def _report(project: Project) -> None:
await report(project)
56 changes: 24 additions & 32 deletions ancestry/extension/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
from typing import override

from betty.app.extension import Extension, UserFacingExtension
from betty.cli import CommandProvider
from betty.extension import Privatizer
from betty.load import PostLoader, getLogger
from betty.locale import Str, DEFAULT_LOCALIZER
from betty.load import PostLoader
from betty.locale import DEFAULT_LOCALIZER
from betty.locale.localizable import Localizable, plain
from betty.model.ancestry import (
PersonName,
Person,
Expand All @@ -15,9 +15,7 @@
Subject,
)
from betty.model.event_type import Birth, Conference
from click import Command

from ancestry.cli import _report
from betty.project.extension import Extension, UserFacingExtension

_PEOPLE = {
"I0000": ("Bart", "Feenstra"),
Expand All @@ -33,28 +31,21 @@
}


class Ancestry(UserFacingExtension, PostLoader, CommandProvider):
class Ancestry(UserFacingExtension, PostLoader):
@override
@classmethod
def comes_after(cls) -> set[type[Extension]]:
return {Privatizer}

@override
@classmethod
def label(cls) -> Str:
return Str.plain("Publish people")
def label(cls) -> Localizable:
return plain("Publish people")

@override
@classmethod
def description(cls) -> Str:
return Str.plain("Publishes curated information about selected people.")

@override
@property
def commands(self) -> dict[str, Command]:
return {
"report": _report,
}
def description(cls) -> Localizable:
return plain("Publishes curated information about selected people.")

@override
async def post_load(self) -> None:
Expand All @@ -63,40 +54,41 @@ async def post_load(self) -> None:
self._publish_files()

def _publish_people(self):
getLogger().info("Publishing selected people...")
logger = logging.getLogger("betty")
logger.info("Publishing selected people...")
for person_id, (individual_name, affiliation_name) in _PEOPLE.items():
person = self._app.project.ancestry[Person][person_id]
person = self.project.ancestry[Person][person_id]
person.public = True
person_name = PersonName(
person=person,
individual=individual_name,
affiliation=affiliation_name,
public=True,
)
self._app.project.ancestry.add(person_name)
getLogger().info(
f"Published {person_name.label.localize(DEFAULT_LOCALIZER)}"
)
self.project.ancestry.add(person_name)
logger.info(f"Published {person_name.label.localize(DEFAULT_LOCALIZER)}")

def _publish_bart(self):
getLogger().info("Publishing Bart...")
bart = self._app.project.ancestry[Person]["I0000"]
netherlands = self._app.project.ancestry[Place]["P0052"]
logger = logging.getLogger("betty")
logger.info("Publishing Bart...")
bart = self.project.ancestry[Person]["I0000"]
netherlands = self.project.ancestry[Place]["P0052"]
birth = Event(
event_type=Birth,
place=netherlands,
public=True,
)
Presence(bart, Subject(), birth)
self._app.project.ancestry.add(birth)
self.project.ancestry.add(birth)
for presence in bart.presences:
if presence.event and presence.event.event_type is Conference:
presence.public = True
presence.event.public = True

def _publish_files(self):
getLogger().info("Publishing selected files...")
logger = logging.getLogger("betty")
logger.info("Publishing selected files...")
for file_id in _FILES:
file = self._app.project.ancestry[File][file_id]
file = self.project.ancestry[File][file_id]
file.public = True
getLogger().info(f"Published {file.label.localize(DEFAULT_LOCALIZER)}")
logger.info(f"Published {file.label.localize(DEFAULT_LOCALIZER)}")
6 changes: 3 additions & 3 deletions ancestry/report.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging

from betty.app import App
from betty.load import load
from betty.project import Project


async def report(app: App) -> None:
async def report(project: Project) -> None:
logging.getLogger("betty").setLevel(logging.DEBUG)
await load(app)
await load(project)
4 changes: 2 additions & 2 deletions assets/templates/footer.html.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% if app.project.configuration.author %}
{% if project.configuration.author %}
<p>
{% trans author = app.project.configuration.author %}© Copyright {{ author }}, unless otherwise credited{% endtrans %}
{% trans author = project.configuration.author %}© Copyright {{ author }}, unless otherwise credited{% endtrans %}
</p>
{% endif %}
<p>{% trans %}Contact me on <a href="https://twitter.com/BartFeenstra">Twitter</a> or via <a href="mailto:[email protected]">email</a>{% endtrans %}</p>
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ authors = [
]
requires-python = '~= 3.11'
dependencies = [
'betty == 0.3.8',
'betty == 0.4.0a2',
'click ~= 8.1, >= 8.1.2',
]

[project.entry-points.'betty.command']
'report' = 'ancestry.cli._report'

[project.entry-points.'betty.extensions']
'ancestry.extension.Ancestry' = 'ancestry.extension.Ancestry'

Expand Down