def migrate_legacy_events(self): print cformat('%{white!}migrating legacy events') # XXX: removed display manager / internal page manager update # don't forget to handle them when updating this for 2.0! wfr = WebFactoryRegistry()._getConfRegistry() for event in self._committing_iterator(self._get_events()): if not hasattr(event, '_old_id'): new_id = self.gen_event_id() event.unindexConf() del self.zodb_root['conferences'][event.id] wf = wfr.pop(event.id, None) event._old_id = event.id event.id = new_id if wf is not None: wfr[event.id] = wf self.zodb_root['conferences'][event.id] = event event.indexConf() EventSetting.find(event_id=event._old_id).update({EventSetting.event_id: event.id}) EventSettingPrincipal.find(event_id=event._old_id).update({EventSettingPrincipal.event_id: event.id}) db.session.add(LegacyEventMapping(legacy_event_id=event._old_id, event_id=int(event.id))) if not self.quiet: self.print_success(cformat('%{cyan}{}').format(event.id), event_id=event._old_id) else: # happens if this importer was executed before but you want to add the mapping to your DB again db.session.add(LegacyEventMapping(legacy_event_id=event._old_id, event_id=int(event.id))) if not self.quiet: self.print_success(cformat('%{cyan}{}%{reset} %{yellow}(already updated in zodb)').format(event.id), event_id=event._old_id)
def migrate_legacy_events(self): print cformat('%{white!}migrating legacy events') # XXX: removed display manager / internal page manager update # don't forget to handle them when updating this for 2.0! wfr = self.zodb_root['webfactoryregistry'] for event in self._committing_iterator(self._get_events()): if not hasattr(event, '_old_id'): new_id = self.gen_event_id() event.unindexConf() del self.zodb_root['conferences'][event.id] wf = wfr.pop(event.id, None) event._old_id = event.id event.id = new_id if wf is not None: wfr[event.id] = wf self.zodb_root['conferences'][event.id] = event event.indexConf() EventSetting.find(event_id=event._old_id).update({EventSetting.event_id: event.id}) EventSettingPrincipal.find(event_id=event._old_id).update({EventSettingPrincipal.event_id: event.id}) db.session.add(LegacyEventMapping(legacy_event_id=event._old_id, event_id=int(event.id))) if not self.quiet: self.print_success(cformat('%{cyan}{}').format(event.id), event_id=event._old_id) else: # happens if this importer was executed before but you want to add the mapping to your DB again db.session.add(LegacyEventMapping(legacy_event_id=event._old_id, event_id=int(event.id))) if not self.quiet: self.print_success(cformat('%{cyan}{}%{reset} %{yellow}(already updated in zodb)').format(event.id), event_id=event._old_id)
def delete_all(self, event): """Deletes all settings. :param event: Event (or its ID) """ EventSetting.delete_all(self.module, event_id=event) EventSettingPrincipal.delete_all(self.module, event_id=event) self._flush_cache()
def set(self, event, name, value): """Sets a single setting. :param event: Event (or its ID) :param name: Setting name :param value: Setting value; must be JSON-serializable """ self._check_name(name) EventSetting.set(self.module, name, value, event_id=event) self._flush_cache()
def migrate_event_settings(self): self.messages.append(cformat("%{magenta!} - Event Payment Settings:")) print cformat("%{white!}migrating event settings") count = 0 EventSetting.delete_all(payment_event_settings.module) for event in committing_iterator(self._iter_events()): old_payment = event._modPay default_conditions = global_settings.get('conditions') default_register_email = global_settings.get('register_email') default_success_email = global_settings.get('success_email') register_email = getattr(old_payment, 'receiptMsg', default_register_email) success_email = getattr(old_payment, 'successMsg', default_success_email) conditions = ( getattr(old_payment, 'paymentConditions', default_conditions) if (getattr(old_payment, 'paymentConditionsEnabled', False) and convert_to_unicode( getattr(old_payment, 'specificPaymentConditions', '')).strip() == '') else getattr( old_payment, 'specificPaymentConditions', '')) # The new messages are shown in an "additional info" section, so the old defaults can always go away if convert_to_unicode( register_email ) == 'Please, see the summary of your order:': register_email = '' if convert_to_unicode( success_email ) == 'Congratulations, your payment was successful.': success_email = '' # Get rid of the most terrible part of the old default conditions conditions = convert_to_unicode(conditions).replace( 'CANCELLATION :', 'CANCELLATION:') settings = { 'enabled': getattr(old_payment, 'activated', False), 'currency': event._registrationForm._currency, 'conditions': conditions, 'register_email': register_email, 'success_email': success_email, } payment_event_settings.set_multi(event, settings) count += 1 print cformat( "%{cyan}<EventSettings(id={id:>6}, enabled={enabled}, " "currency={currency})>").format(id=event.id, **settings) msg = cformat( "%{green!}migration of {0} event payment settings successful\n" ).format(count) self.messages.append(' ' + msg) print msg
def migrate_event_settings(self): self.messages.append(cformat("%{magenta!} - Event Payment Settings:")) print cformat("%{white!}migrating event settings") count = 0 EventSetting.delete_all(payment_event_settings.module) for event in committing_iterator(self._iter_events()): old_payment = event._modPay default_conditions = global_settings.get("conditions") default_register_email = global_settings.get("register_email") default_success_email = global_settings.get("success_email") register_email = getattr(old_payment, "receiptMsg", default_register_email) success_email = getattr(old_payment, "successMsg", default_success_email) conditions = ( getattr(old_payment, "paymentConditions", default_conditions) if ( getattr(old_payment, "paymentConditionsEnabled", False) and convert_to_unicode(getattr(old_payment, "specificPaymentConditions", "")).strip() == "" ) else getattr(old_payment, "specificPaymentConditions", "") ) # The new messages are shown in an "additional info" section, so the old defaults can always go away if convert_to_unicode(register_email) == "Please, see the summary of your order:": register_email = "" if convert_to_unicode(success_email) == "Congratulations, your payment was successful.": success_email = "" # Get rid of the most terrible part of the old default conditions conditions = convert_to_unicode(conditions).replace("CANCELLATION :", "CANCELLATION:") settings = { "enabled": getattr(old_payment, "activated", False), "currency": event._registrationForm._currency, "conditions": conditions, "register_email": register_email, "success_email": success_email, } payment_event_settings.set_multi(event, settings) count += 1 print cformat("%{cyan}<EventSettings(id={id:>6}, enabled={enabled}, " "currency={currency})>").format( id=event.id, **settings ) msg = cformat("%{green!}migration of {0} event payment settings successful\n").format(count) self.messages.append(" " + msg) print msg
def migrate_event_settings(self): print cformat('%{white!}migrating event settings') default_method_name = PaypalPaymentPlugin.settings.get('method_name') EventSetting.delete_all(PaypalPaymentPlugin.event_settings.module) account_id_re = re.compile(r'^[a-zA-Z0-9]{13}$') for event in committing_iterator(self._iter_events(), 25): pp = event._modPay.payMods['PayPal'] business = pp._business.strip() if not business or (not is_valid_mail(business, multi=False) and not account_id_re.match(business)): print cformat(' - %{yellow!}event {} skipped (business: {})').format(event.id, business or '(none)') continue PaypalPaymentPlugin.event_settings.set(event, 'enabled', True) method_name = convert_to_unicode(pp._title) if method_name.lower() == 'paypal': method_name = default_method_name PaypalPaymentPlugin.event_settings.set(event, 'method_name', method_name) PaypalPaymentPlugin.event_settings.set(event, 'business', pp._business) print cformat(' - %{cyan}event {} (business: {})').format(event.id, pp._business)
def set_multi(self, event, items): """Sets multiple settings at once. :param event: Event (or its ID) :param items: Dict containing the new settings """ self._split_call(items, lambda x: EventSetting.set_multi(self.module, x, event_id=event), lambda x: EventSettingPrincipal.set_acl_multi(self.module, x, event_id=event)) self._flush_cache()
def delete(self, event, *names): """Deletes settings. :param event: Event (or its ID) :param names: One or more names of settings to delete """ self._split_call(names, lambda name: EventSetting.delete(self.module, *name, event_id=event), lambda name: EventSettingPrincipal.delete(self.module, *name, event_id=event)) self._flush_cache()
def migrate_surveys(self): self.print_step("Migrating old event evaluations") notification_pending = {es.event_id: es.value for es in EventSetting.find_all(module='evaluation', name='send_notification')} for event, evaluation in committing_iterator(self._iter_evaluations(), 10): survey = self.migrate_survey(evaluation, event) if (survey.notifications_enabled and survey.start_notification_emails and not notification_pending.get(survey.event_id)): survey.start_notification_sent = True db.session.add(survey)
def set_multi(self, event, items): """Sets multiple settings at once. :param event: Event (or its ID) :param items: Dict containing the new settings """ items = {k: self._convert_from_python(k, v) for k, v in items.iteritems()} self._split_call(items, lambda x: EventSetting.set_multi(self.module, x, event_id=event), lambda x: EventSettingPrincipal.set_acl_multi(self.module, x, event_id=event)) self._flush_cache()
def migrate_surveys(self): self.print_step("Migrating old event evaluations") notification_pending = { es.event_id: es.value for es in EventSetting.find_all(module='evaluation', name='send_notification') } for event, evaluation in committing_iterator(self._iter_evaluations(), 10): survey = self.migrate_survey(evaluation, event) if (survey.notifications_enabled and survey.start_notification_emails and not notification_pending.get(survey.event_id)): survey.start_notification_sent = True db.session.add(survey)
def migrate_legacy_events(self): print cformat('%{white!}migrating legacy events') dmr = ConfDisplayMgrRegistery()._getDisplayMgrRegistery() wfr = WebFactoryRegistry()._getConfRegistry() ipmr = InternalPagesMgrRegistery()._getInternalPagesMgrRegistery() for event in self._committing_iterator(self._get_events()): if not hasattr(event, '_old_id'): new_id = self.gen_event_id() event.unindexConf() del self.zodb_root['conferences'][event.id] dm = dmr.pop(event.id, None) wf = wfr.pop(event.id, None) ipm = ipmr.pop(event.id, None) event._old_id = event.id event.id = new_id if dm is not None: dmr[event.id] = dm if wf is not None: wfr[event.id] = wf if ipm is not None: ipmr[event.id] = ipm self.zodb_root['conferences'][event.id] = event event.indexConf() IndexedEvent.find(id=event._old_id).update({IndexedEvent.id: event.id}) EventSetting.find(event_id=event._old_id).update({EventSetting.event_id: event.id}) EventSettingPrincipal.find(event_id=event._old_id).update({EventSettingPrincipal.event_id: event.id}) db.session.add(LegacyEventMapping(legacy_event_id=event._old_id, event_id=int(event.id))) print cformat('%{green}+++%{reset} ' '%{white!}{:6s}%{reset} %{cyan}{}').format(event._old_id, int(event.id)) else: # happens if this importer was executed before but you want to add the mapping to your DB again db.session.add(LegacyEventMapping(legacy_event_id=event._old_id, event_id=int(event.id))) msg = cformat('%{green}+++%{reset} ' '%{white!}{:6s}%{reset} %{cyan}{}%{reset} %{yellow}(already updated in zodb)') print msg.format(event._old_id, int(event.id))
def query(self): """Returns a query object filtering by the proxy's module.""" return EventSetting.find(module=self.module)
def _event_deleted(event, **kwargs): event.as_event.is_deleted = True EventSetting.delete_event(int(event.id)) EventSettingPrincipal.delete_event(int(event.id)) if hasattr(event, '_old_id'): LegacyEventMapping.find(legacy_event_id=event._old_id).delete()
def _event_deleted(event, **kwargs): EventSetting.delete_event(event.id) EventSettingPrincipal.delete_event(event.id)