Skip to content
Snippets Groups Projects
Commit 9a22a464 authored by Alexa Valentová's avatar Alexa Valentová
Browse files

fix octo person saving

parent d430b74a
Branches
No related tags found
2 merge requests!1175Release,!1171Minor fixes
Pipeline #20015 failed
......@@ -12,7 +12,7 @@ from dateutil.rrule import rrulestr
from dateutil.tz import UTC, gettz
from icalendar import Calendar
from icalendar.prop import vDDDLists, vText
from icalendar.windows_to_olson import WINDOWS_TO_OLSON
from icalendar.timezone.windows_to_olson import WINDOWS_TO_OLSON
from pytz import timezone
......
......@@ -36,9 +36,11 @@ class JekyllImportForm(SharedJekyllImportForm):
class DistrictPeoplePageForm(WagtailAdminPageForm):
def save(self, *args, **kwargs):
# If anything inside the content field has changed,
parental_save_result = super().save(*args, **kwargs)
# If anything inside the content field has changed and the instance exists,
# sync Octopus profiles just in case.
if "content" in self.changed_data:
if "content" in self.changed_data and self.instance.pk:
collection_id = self.instance.root_page.image_collection_id
if collection_id is None:
......@@ -52,23 +54,7 @@ class DistrictPeoplePageForm(WagtailAdminPageForm):
group["title"],
)
return super().save(*args, **kwargs)
class DistrictManualOctopusPersonPageForm(WagtailAdminPageForm):
def save(self, *args, **kwargs):
# Sync every time this type page is saved, just in case.
collection_id = self.instance.root_page.image_collection_id
if collection_id is None:
collection_id = Collection.objects.first().id
import_manual_person.delay(
self.instance.id,
collection_id,
)
return super().save(*args, **kwargs)
return parental_save_result
class DistrictArticlesPageForm(SharedArticlesPageForm, JekyllImportForm):
......
......@@ -25,6 +25,8 @@ from wagtail.fields import RichTextField, StreamField
from wagtail.models import Orderable, Page
from wagtail.models.media import Collection
from wagtailmetadata.models import MetadataPageMixin
from wagtail import hooks
from .tasks import import_manual_person
from calendar_utils.models import CalendarMixin
from maps_utils.blocks import MapPointBlock
......@@ -76,7 +78,6 @@ from shared.utils import (
from . import blocks
from .forms import (
DistrictArticlesPageForm,
DistrictManualOctopusPersonPageForm,
DistrictPeoplePageForm,
)
......@@ -351,6 +352,9 @@ class PersonPageMixin(Page):
@property
def profile_image(self):
if self.person is None:
return None
return self.person.photo
def get_profile_image(self):
......@@ -361,13 +365,22 @@ class PersonPageMixin(Page):
@property
def before_name(self):
if self.person is None:
return None
return self.person.degree_before
@property
def after_name(self):
if self.person is None:
return None
return self.person.degree_after
def get_full_name(self) -> str:
if self.person is None:
return None
full_name = ""
if self.person.degree_before:
......@@ -382,20 +395,30 @@ class PersonPageMixin(Page):
@property
def position(self):
print(self.person.position)
if self.person is None:
return None
return self.person.position
@property
def perex(self):
if self.person is None:
return None
return self.person.short_text
@property
def text(self):
if self.person is None:
return None
return markdown(self.person.long_text)
@property
def social_links(self):
if self.person is None:
return None
link_blocks = []
for attr_name, attr_info in {
......@@ -430,10 +453,16 @@ class PersonPageMixin(Page):
@property
def email(self):
if self.person is None:
return None
return self.person.email
@property
def phone(self):
if self.person is None:
return None
return self.person.phone
@property
......@@ -471,8 +500,6 @@ class PersonPageMixin(Page):
class DistrictManualOctopusPersonPage(
ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, PersonPageMixin, Page
):
base_form_class = DistrictManualOctopusPersonPageForm
### FIELDS
username = models.CharField(
......@@ -1579,6 +1606,24 @@ class DistrictGeoFeatureDetailPage(
raise ValidationError({"geojson": str(exc)}) from exc
# Hooks - DistrictManualOctopusPersonPage
@hooks.register("after_create_page")
@hooks.register("after_edit_page")
def after_create_edit_page_hook(request, page):
print(page)
if isinstance(page, DistrictManualOctopusPersonPage):
collection_id = page.root_page.image_collection_id
if collection_id is None:
collection_id = Collection.objects.first().id
import_manual_person.delay(
page.id,
collection_id,
)
# Legacy models required for migrations
......
......@@ -254,6 +254,7 @@ class RegkonSubPage(Page, ExtendedMetadataPageMixin, MetadataPageMixin):
def root_page(self):
if not hasattr(self, "_root_page"):
self._root_page = self.get_ancestors().type(RegkonHomePage).specific().get()
return self._root_page
def get_meta_image(self):
......
......@@ -162,6 +162,7 @@ class SubpageMixin:
# vypada to hackove ale lze takto pouzit: dle dokumentace get_ancestors
# vraci stranky v poradi od rootu, tedy domovska stranka je druha v poradi
self._root_page = self.get_ancestors().specific()[1]
return self._root_page
def get_meta_image(self):
......@@ -1670,6 +1671,7 @@ class MainArticlePageMixin(
"""
Returns root page of article, or a root page of Articles page to which this article was shared
"""
if self.shared_from is None:
return self.get_parent().get_ancestors().specific().live().last()
......
......@@ -59,6 +59,7 @@ class ImporterMixin:
}
if person is None:
if hasattr(self, "new_user_count"):
self.new_user_count += 1
logger.info(
......@@ -259,7 +260,7 @@ class PeopleGroupImporter(ImporterMixin):
allGroups(
filters:
{{
shortcut: {{exact: "{self.group_shortcut}" }}
shortcut: {{iExact: "{self.group_shortcut}" }}
}}
) {{
edges {{
......@@ -426,7 +427,7 @@ class PeopleTeamImporter(ImporterMixin):
allTeams(
filters:
{{
shortcut: {{exact: "{self.team_shortcut}" }}
shortcut: {{iExact: "{self.team_shortcut}" }}
}}
) {{
edges {{
......@@ -608,7 +609,7 @@ class PersonImporter(ImporterMixin):
query {{
allPeople(
filters: {{
username: {{ exact: "{username}" }}
username: {{ iExact: "{username}" }}
}}
) {{
edges {{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment