def _migrate_menu(self, event, container, parent=None, used=None): if used is None: used = set() for pos, item in enumerate(container._listLink, 1): data = { 'parent': parent, 'event_id': int(event.id), 'is_enabled': item._active, 'position': pos } item_type = item.__class__.__name__ if item_type == 'SystemLink': if item._name in REMOVED_MENU_NAMES: continue data['name'] = MENU_ENTRY_NAME_MAP[item._name] if not parent and data['name'] in NOT_TOP_LEVEL_NAMES: self.print_warning(cformat( '%{yellow}Skipping top-level menu entry {}').format( data['name']), event_id=event.id) continue elif data['name'] in used: self.print_error( cformat('%{red!}duplicate menu entry name {}; skipping' ).format(data['name']), event_id=event.id) continue used.add(data['name']) data['title'] = _sanitize_title(item._caption) if not data['title']: data['title'] = None self.print_warning(cformat( '%{yellow!}Menu entry {} has no title; using default'). format(data['name']), event_id=event.id) elif data['title'].lower() in DEFAULT_MENU_TITLES[ data['name']]: data['title'] = None if item._name == 'chatrooms': data['plugin'] = 'chat' data['type'] = MenuEntryType.plugin_link else: data['type'] = MenuEntryType.internal_link elif item_type == 'Spacer': data['type'] = MenuEntryType.separator elif item_type == 'ExternLink': data['type'] = MenuEntryType.user_link data['title'] = _sanitize_title(item._caption) data['link_url'] = item._URL.strip() if not data['link_url']: if getattr(item, '_listLink', None): self.print_warning(cformat( '%{yellow!}Link "{}" has no URL but children'). format(data['title']), event_id=event.id) else: self.print_warning(cformat( '%{yellow}Skipping link "{}" with no URL').format( data['title']), event_id=event.id) continue if not data['title']: if getattr(item, '_listLink', None): self.print_warning(cformat( '%{yellow!}Link has no title but children'), event_id=event.id) else: self.print_warning( cformat('%{yellow}Skipping link with no title'), event_id=event.id) continue elif item_type == 'PageLink': data['type'] = MenuEntryType.page data['title'] = _sanitize_title(item._caption) data['page'] = EventPage(event_id=event.id, html=item._page._content) data['page'].legacy_mapping = LegacyPageMapping( event_id=event.id, legacy_page_id=item._page._id) if item._page._isHome: Event.get(event.id).default_page = data['page'] else: self.print_error( 'Unexpected menu item type: {}'.format(item_type), event_id=event.id) continue entry = MenuEntry(**data) yield entry if getattr(item, '_listLink', None): # child entries if not parent: for sub_entry in self._migrate_menu( event, item, entry, used): yield sub_entry else: self.print_warning('Skipping children inside nested entry', event_id=event.id)
def compat_page(**kwargs): page = LegacyPageMapping.find(**kwargs).first_or_404().page return redirect(url_for('event_pages.page_display', page), 302 if current_app.debug else 301)