class ISyncSettings(model.Schema): """Configure content syncing.""" model.fieldset( "collective.contentsync", label=_("Content Sync"), fields=[ "sync_disabled", "sync_settings", ], ) sync_disabled = schema.Bool( default=False, description=_( "When activated synchronization of sub content will stop at this " u"content item for all sync targets.", ), required=False, title=_("Exclude item from content sync"), ) directives.widget(sync_settings=DataGridFieldFactory) sync_settings = schema.List( default=[], required=False, title=_("Sync Settings"), value_type=DictRow(title=_("Sync Setting"), schema=ISyncSettingRow), )
class SyncAddForm(ActionAddForm): """An add form for sync-to-external-Plone-sites actions.""" schema = ISyncAction label = _(u"Add Sync Action") description = _( u"A sync action can sync an object to a different Plone site.") Type = SyncAction
class ISyncSettingRow(model.Schema): """A dedicated sync configuration.""" sync_target = schema.Choice( description=_(u"Please select one target from the list."), required=True, title=_(u"Sync Target"), vocabulary="collective.contentsync.targets", ) sync_enabled = schema.Bool( default=False, description=_( "When activated synchronization will be active. Note that there must be " u"a corresponding content rule available executing the ”Sync content” " u"action.", ), required=False, title=_("Enable content sync"), ) sync_target_path = schema.TextLine( required=True, title=_(u"Target path"), ) sync_include_subcontent = schema.Bool( default=False, description=_( "When activated sub content will be synchronized as well."), required=False, title=_("Sync sub content"), )
def handle_run_sync(self, action): sync_queue() plone.api.portal.show_message( message=_(u"Synchronization run was successful."), request=self.request, ) self.request.response.redirect(u"{0}/{1}".format( plone.api.portal.get().absolute_url(), "@@collective.contentsync-settings"))
class SyncControlPanelForm(controlpanel.RegistryEditForm): """Sync control panel form.""" schema = ISyncSettings schema_prefix = "collective.contentsync" label = _(u"Content Sync Settings") buttons = controlpanel.RegistryEditForm.buttons.copy() handlers = controlpanel.RegistryEditForm.handlers.copy() targets = context_property('targets') def updateActions(self): # noqa: N802 super(SyncControlPanelForm, self).updateActions() if "run_sync" in self.actions: self.actions["run_sync"].addClass("destructive") @button.buttonAndHandler( _(u"Sync queued items now"), name="run_sync", ) def handle_run_sync(self, action): sync_queue() plone.api.portal.show_message( message=_(u"Synchronization run was successful."), request=self.request, ) self.request.response.redirect(u"{0}/{1}".format( plone.api.portal.get().absolute_url(), "@@collective.contentsync-settings")) @button.buttonAndHandler( _(u"Full sync"), name="full_sync", ) def handle_full_sync(self, action): queue = plone.api.portal.get_registry_record( "collective.contentsync.queue") queue = queue or set() missed = full_sync() queue = queue & missed plone.api.portal.set_registry_record("collective.contentsync.queue", queue)
class ISyncSettings(model.Schema): """Global settings.""" sync_immediately = schema.Bool( description=_( u"If activated, a synchronization will be tried right away. If it fails, " u"the content item will be added to the queue.", ), default=False, required=False, title=_(u"Sync immediately"), ) omitted_update_fields = schema.List( default=DEFAULT_OMITTED_UPDATE_FIELDS, description=_( u"This list contains field names which should be ignored when the remote " u"item already exists. Add one item per line."), required=False, title=_(u"Ignored fields for update"), value_type=schema.TextLine(), ) # directives.widget("targets", MultiWidget) directives.widget("targets", DataGridFieldFactory) targets = schema.List(description=_(u"Synchronization targets"), required=False, title=_(u"Targets"), default=[], value_type=DictRow(title="row", schema=ITargetRow)) directives.mode(ISyncControlPanelForm, queue="display") queue = schema.Set( description=_( u"A list of content items which should be synced with next " u"synchronization run."), required=False, title=_(u"Sync Queue"), value_type=schema.TextLine(title=_(u"Path")), )
def _get_registry_record(self, iface=None, name=None): try: return plone.api.portal.get_registry_record(name=name, interface=iface) except plone.api.exc.InvalidParameterError: return [] except KeyError: registry = getUtility(IRegistry) registry.registerInterface(iface) try: return plone.api.portal.get_registry_record(name=name, interface=iface) except (KeyError, plone.api.exc.InvalidParameterError): plone.api.portal.show_message( message=_( u"Please upgrade or reinstall collective.contentsync"), request=getRequest(), ) return []
class SyncAction(SimpleItem): """The actual persistent implementation of the action element.""" element = "collective.contentsync.actions.Sync" summary = _(u"Sync to an external Plone site")
class ITargetRow(model.Schema): id = schema.TextLine(title=_("ID target")) title = schema.TextLine(title=_("Title target")) url = schema.TextLine(title=_("URL")) username = schema.TextLine(title=_("Username")) password = schema.TextLine(title=_("Password"))