diff --git a/calendar_utils/icalevents/icalparser.py b/calendar_utils/icalevents/icalparser.py index 4de4373e76423956b85c1d5f87330742308e4286..42e2a268a5642786397b9275070d550afa932944 100644 --- a/calendar_utils/icalevents/icalparser.py +++ b/calendar_utils/icalevents/icalparser.py @@ -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 diff --git a/district/forms.py b/district/forms.py index beb5f055332469c9a087f6acd2a36061fe38a00d..fa3d801a0e7507a582bc2e1a532fa8513b24cb2b 100644 --- a/district/forms.py +++ b/district/forms.py @@ -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): diff --git a/district/models.py b/district/models.py index 3afe74879c19c4155e2ce6d946e421c35cf13602..1b632c3d1abb340092b7ef0ad1e90ec5808b8925 100644 --- a/district/models.py +++ b/district/models.py @@ -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 @@ -1587,4 +1632,4 @@ class LegacyProgramPageMixin(Page): return HttpResponseRedirect("/programy/") class Meta: - abstract = True + abstract = True \ No newline at end of file diff --git a/regulace_konopi/models.py b/regulace_konopi/models.py index fe05d475d77df3d5be0dd7481f8ab6affc2b0c91..1f6c5ed2f802a9f89550c21b875539033e224a08 100644 --- a/regulace_konopi/models.py +++ b/regulace_konopi/models.py @@ -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): diff --git a/shared/models/main.py b/shared/models/main.py index 188f19961bb3de1049cd90d90fd14d8b5f6c301a..f4453e1e7d403f7740a65e06cee213b20dbd4267 100644 --- a/shared/models/main.py +++ b/shared/models/main.py @@ -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() diff --git a/shared/people_import.py b/shared/people_import.py index 664fce91603035c2a25acb01cbce95ab375b5ff4..fbdde0489bdbbb760dc9087e42878e2d42b08311 100644 --- a/shared/people_import.py +++ b/shared/people_import.py @@ -59,7 +59,8 @@ class ImporterMixin: } if person is None: - self.new_user_count += 1 + if hasattr(self, "new_user_count"): + self.new_user_count += 1 logger.info( "Creating new Octopus person profile - ID %s, username %s", @@ -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 {{