def publish(self, publishers=[], accounts={}): obj = self.context selected_publishers = self.request.get('publishers', publishers) if not selected_publishers: msg = _(u"Select at list one publisher!") self.update_message(msg, type="error") return published = {} self._update_settings(publishers=publishers, accounts=accounts) content = self.get_content() manager = IPublishStorageManager(obj) if manager.get_text() and not self.request.get('one_shot_text'): content = manager.get_text() published['content'] = content selected_accounts = self.request.get('accounts', accounts) for pub in selected_publishers: account_id = selected_accounts.get(pub) self._publish(content, pub, account_id) published[pub] = account_id msg = _(u'content_published', default=u"Content published on ${published_on}", mapping={'published_on': ', '.join(selected_publishers)}) translated = self.context.translate(msg) self.update_message(translated) return published
class ControlPanelForm(RegistryEditForm): schema = IGlobalSettings label = _("Social publisher global settings") def applyChanges(self, data): super(ControlPanelForm, self).applyChanges(data) pass
def handle_autopublish(self): form = self.request.form obj = self.context changed = False if form.get('enable'): if not IAutoPublishable.providedBy(obj): alsoProvides(obj, IAutoPublishable) msg = _('Auto-publish enabled') changed = True else: if IAutoPublishable.providedBy(obj): noLongerProvides(obj, IAutoPublishable) msg = _('Auto-publish disabled') changed = True if changed: obj.reindexObject(idxs=['object_provides']) self.update_message(msg)
class IGlobalSettings(interface.Interface): """ global settings """ autopublish_enabled = schema.Bool( title=_("Auto-publish enabled"), description=_(u"If disabled the cron will not publish anything."), default=False) # XXX: this should be used to mark content type klasses on the fly # but I can't find a clean way to do that since it seems there's no safe way # to get the klass of the content type. # enabled_content_types = schema.List( # title = _(u'Publishable content types'), # required = False, # default = [], # description = _(u"A list of types can be pusblished"), # value_type = schema.Choice( # title=_(u"Content types"), # source="plone.app.vocabularies.ReallyUserFriendlyTypes" # ) # )
def update_settings(self, publishers=[], accounts={}): self._update_settings(publishers=publishers, accounts=accounts) msg = _(u"Settings updated") self.update_message(msg)