def handle_edit_action(self, action, data): # If the CC license option has been chosen, copy the new fields # into the license if 'Creative Commons License' == data['default_license']: ad = self.adapters[IContentLicensingSettingsForm] # Get the hidden field data from the view in the form ad.setCCLicense(self.request['license_cc_name'], self.request['license_cc_url'], self.request['license_cc_button']) # Apply form changes if form.applyChanges(self.context, self.form_fields, data, self.adapters): # If there is a new license in the form, add it to the properties page if data.has_key('new_license_name') and data['new_license_name']: ad = self.adapters[IContentLicensingNewLicenseForm] ad.setNewLicense(data['new_license_name'], data['new_license_url'], data['new_license_icon']) self.status = _("Changes saved.") self._on_save(data) self.request['fieldset.current'] = u'fieldsetlegend-contentlicensingsettings' else: self.status = _("No changes made.")
def handle_edit_action(self, action, data): # If the CC license option has been chosen, copy the new fields # into the license if 'Creative Commons License' == data['default_license']: ad = self.adapters[IContentLicensingSettingsForm] # Get the hidden field data from the view in the form ad.setCCLicense(self.request['license_cc_name'], self.request['license_cc_url'], self.request['license_cc_button']) # Apply form changes if form.applyChanges(self.context, self.form_fields, data, self.adapters): # If there is a new license in the form, add it to the properties page if data.has_key('new_license_name') and data['new_license_name']: ad = self.adapters[IContentLicensingNewLicenseForm] ad.setNewLicense(data['new_license_name'], data['new_license_url'], data['new_license_icon']) self.status = _("Changes saved.") self._on_save(data) self.request[ 'fieldset.current'] = u'fieldsetlegend-contentlicensingsettings' else: self.status = _("No changes made.")
class OtherLicenseForm(AddForm): """ Other License Form """ form_fields = FormFields(IOtherLicenseForm) label = _(u'Create License') description = _(u'Create a new license for use with your content types.') @action(_(u'Submit'), name=u'Submit') def action_submit(self, action, data): """ Submit new fields for a license """ # context = aq_inner(self.context) # nl = (data['license_name'], data['license_name'], data['license_url'], data['license_image']) # clutils = getUtility(IContentLicensingUtility) # clutils.setRightsLicense(context, nl) # IStatusMessage(self.request).addStatusMessage(_(u'Copyright License Changed.'), type='info') # self.request.response.redirect('%s/insert_license' %self.context.absolute_url()) return '' @action(_(u'Cancel'), validator=null_validator, name=u'Cancel') def action_cancel(self, action, data): """ Cancel create other license. """ # context = aq_inner(self.context) # IStatusMessage(self.request).addStatusMessage(_(u'Copyright License change cancelled.'), type='info') # self.request.response.redirect(context.absolute_url()) return ''
def getAlertMsg(self): """Use this domain for translation""" msg = _( _(u'The citation for this resource is presented in APA format. ' 'Copy the citation to your clipboard for reuse.') ) return translate(msg, domain="ContentLicensing", target_language=self.request.LANGUAGE)
def getCitationInfo(self): """ Gets the citation information """ # Title title = self.context.title # Creators creator = '' index = 1 names = [name.strip() for name in self.context.Creators()] for cr in names: if cr and '@' == cr[0]: creator += '%s, ' %cr[1:] else: inits = '' crs = [] crs = cr.split(' ') for part in crs[:-1]: inits += ' ' + part[0] + '.' creator += crs[-1] if inits: creator += "," + inits creator += ', ' index += 1 if creator: creator = creator[:-2] if creator: if creator[-1] != '.': creator += '.' id = self.context.getId() portal_url = getToolByName(self.context, 'portal_url') portal_name = portal_url.getPortalObject().title # TODO: Adds support at format date on every languages at this string create_date = self.context.creation_date.strftime('%Y, %B %d') url = self.context.absolute_url() date = datetime.date.today().strftime('%B %d, %Y') ts = getToolByName(self.context, 'translation_service') if creator: prompt_text = ts.translate( _(u"%s (%s). %s. Retrieved %s, from %s Web site: %s.") ) % ( unicode_sanitize(creator), create_date,unicode_sanitize(title), date,unicode_sanitize(portal_name),url ) else: prompt_text = ts.translate( _(u"%s. (%s). Retrieved %s, from %s Web site: %s.") ) % ( unicode_sanitize(title), create_date,date,unicode_sanitize(portal_name), url ) return prompt_text.replace('\'','\\\'').replace('\"','\\\'')
def getAlertMsg(self): """Use this domain for translation""" msg = _( _(u'The citation for this resource is presented in APA format. ' 'Copy the citation to your clipboard for reuse.')) return translate(msg, domain="ContentLicensing", target_language=self.request.LANGUAGE)
def getAlertMsg(self): """Use this domain for translation""" ts = getToolByName(self.context, 'translation_service') msg = _( _(u'The citation for this resource is presented in APA format. ' 'Copy the citation to your clipboard for reuse.') ) return ts.translate(msg)
class ContentLicensingPrefsForm(ControlPanelForm): """ The view class for the content licensing preferences form. """ implements(IContentLicensingPrefsForm) form_fields = FormFieldsets(settingsset, newlicenseset) form_fields['default_license'].custom_widget = LicenseWidget form_fields[ 'supported_licenses'].custom_widget = MultiCheckBoxVocabularyWidget label = _(u'Content Licensing Settings') description = _(u'Configure site wide settings for copyright licensing ' 'of content within this portal.') form_name = _(u'Content Licensing Settings') @form.action(_(u'Save'), name=u'save') def handle_edit_action(self, action, data): # If the CC license option has been chosen, copy the new fields # into the license if 'Creative Commons License' == data['default_license']: ad = self.adapters[IContentLicensingSettingsForm] # Get the hidden field data from the view in the form ad.setCCLicense(self.request['license_cc_name'], self.request['license_cc_url'], self.request['license_cc_button']) # Apply form changes if form.applyChanges(self.context, self.form_fields, data, self.adapters): # If there is a new license in the form, add it to the properties page if data.has_key('new_license_name') and data['new_license_name']: ad = self.adapters[IContentLicensingNewLicenseForm] ad.setNewLicense(data['new_license_name'], data['new_license_url'], data['new_license_icon']) self.status = _("Changes saved.") self._on_save(data) self.request[ 'fieldset.current'] = u'fieldsetlegend-contentlicensingsettings' else: self.status = _("No changes made.")
def supportedvocab(context): props = getToolByName(context, 'portal_properties') supp = props.content_licensing_properties.AvailableLicenses ts = getToolByName(context.context,'translation_service') licenses = [] for x in supp: value = getattr(props.content_licensing_properties, x)[0], x if 'Creative Commons License' == value[0]: value = (_(u'Creative Commons License Picker'), x) value = ts.translate(value[0]), value[1] licenses.append(value) return SimpleVocabulary.fromItems(licenses)
def supportedvocab(context): props = getToolByName(context, 'portal_properties') supp = props.content_licensing_properties.AvailableLicenses ts = getToolByName(context.context, 'translation_service') licenses = [] for x in supp: value = getattr(props.content_licensing_properties, x)[0], x if 'Creative Commons License' == value[0]: value = (_(u'Creative Commons License Picker'), x) value = ts.translate(value[0]), value[1] licenses.append(value) return SimpleVocabulary.fromItems(licenses)
class IContentLicensingNewLicenseForm(Interface): """ The view for the add new license form """ new_license_name = TextLine(title=_(u'License Name'), description=_(u'The name of the license.'), required=False) new_license_url = TextLine( title=_(u'License Location'), description=_(u'The URL pointer to information about the license.'), required=False) new_license_icon = TextLine( title=_(u'License Icon'), description=_( u'The URL pointer to an image associated with the license.'), required=False)
class IOtherLicenseForm(Interface): """ Marker interface for other license form """ license_name = TextLine(title=_(u'License Name'), description=_( u'The title of the license that will ' 'appear on the licensed object.'), required=True) license_url = TextLine(title=_(u'License URL'), description=_(u'The external URL of the license, ' 'this usually contains the actual ' 'content of the license.'), required=True) license_image = TextLine(title=_(u'License Image'), description=_( u'An external URL link to an image that ' 'represents the license.'), required=False)
def setNewLicense(self, name, url, icon): """ Set a new license """ new_license = [name, name, '', ''] if url: new_license[2] = url if icon: new_license[3] = icon license_id = 'license_%s' %(''.join(name.lower().split())) self.clprops.manage_addProperty(license_id, new_license, 'lines') self.clprops.manage_changeProperties(SupportedLicenses=list(self.clprops.getProperty('SupportedLicenses')) + [license_id]) self.clprops.manage_changeProperties(AvailableLicenses=list(self.clprops.getProperty('AvailableLicenses')) + [license_id]) settingsset = FormFieldsets(IContentLicensingSettingsForm) settingsset.id = 'contentlicensingsettings' settingsset.label = _(u'Content License Settings') newlicenseset = FormFieldsets(IContentLicensingNewLicenseForm) newlicenseset.id = 'contentlicensenewlicense' newlicenseset.label = _(u'New License') class ContentLicensingPrefsForm(ControlPanelForm): """ The view class for the content licensing preferences form. """ implements(IContentLicensingPrefsForm) form_fields = FormFieldsets(settingsset, newlicenseset) form_fields['default_license'].custom_widget = LicenseWidget form_fields['supported_licenses'].custom_widget = MultiCheckBoxVocabularyWidget label = _(u'Content Licensing Settings')
new_license = [name, name, '', ''] if url: new_license[2] = url if icon: new_license[3] = icon license_id = 'license_%s' % (''.join(name.lower().split())) self.clprops.manage_addProperty(license_id, new_license, 'lines') self.clprops.manage_changeProperties(SupportedLicenses=list( self.clprops.getProperty('SupportedLicenses')) + [license_id]) self.clprops.manage_changeProperties(AvailableLicenses=list( self.clprops.getProperty('AvailableLicenses')) + [license_id]) settingsset = FormFieldsets(IContentLicensingSettingsForm) settingsset.id = 'contentlicensingsettings' settingsset.label = _(u'Content License Settings') newlicenseset = FormFieldsets(IContentLicensingNewLicenseForm) newlicenseset.id = 'contentlicensenewlicense' newlicenseset.label = _(u'New License') class ContentLicensingPrefsForm(ControlPanelForm): """ The view class for the content licensing preferences form. """ implements(IContentLicensingPrefsForm) form_fields = FormFieldsets(settingsset, newlicenseset) form_fields['default_license'].custom_widget = LicenseWidget form_fields[ 'supported_licenses'].custom_widget = MultiCheckBoxVocabularyWidget
class IContentLicensingSettingsForm(Interface): """ The view for content licensing prefs form. """ jurisdiction = Choice( title=_(u'Jurisdiction'), description=_( u'Specify the jurisdiction in which the content license ' 'is valid. (Any Jurisdiction changes must be saved before ' 'choosing a new Creative Commons license.)'), required=True, default='unported', vocabulary='contentlicensing.jurisdictionvocab') publisher = TextLine( title=_(u'Publisher'), description=_( u'The institution or individual responsible for publishing ' 'content in this portal.'), required=False) default_copyright = TextLine( title=_(u'Default Copyright'), description=_(u'The default copyright to be used with content ' 'in this portal.'), required=False) default_copyright_holder = TextLine( title=_(u'Default Copyright Holder'), description=_(u'The default copyright owner for content in ' 'this portal.'), required=False, ) default_license = Choice(title=_(u'Default License'), description=_(u'Default License'), required=True, vocabulary='contentlicensing.defaultlicensevocab') supported_licenses = Tuple( title=_(u'Supported Licenses'), description=_( u'Choose the licenses which can be selected for individual ' 'objects. The Creative Commons License Picker provides an ' 'interactive form to choose an appropriate Creative ' 'Commons license.'), required=True, missing_value=tuple(), value_type=Choice(vocabulary='contentlicensing.supportedvocab'))
def getCitationInfo(self): """ Gets the citation information """ # Title title = self.context.title # Creators creator = '' index = 1 try: names = [name.strip() for name in self.context.Creators()] except AttributeError: names = [] for cr in names: if cr and '@' == cr[0]: creator += '%s, ' % cr[1:] else: inits = '' crs = [] crs = cr.split(' ') for part in crs[:-1]: inits += ' ' + part[0] + '.' creator += crs[-1] if inits: creator += "," + inits creator += ', ' index += 1 if creator: creator = creator[:-2] if creator: if creator[-1] != '.': creator += '.' portal_url = getToolByName(self.context, 'portal_url') portal_name = portal_url.getPortalObject().title plone_view = getMultiAdapter((self.context, self.request), name='plone') create_date = plone_view.toLocalizedTime(self.context.creation_date) url = self.context.absolute_url() date = plone_view.toLocalizedTime(DateTime()) if creator: prompt_text = translate( _(u"%s (%s). %s. Retrieved %s, from %s Web site: %s."), domain="ContentLicensing", target_language=self.request.LANGUAGE, ) % (safe_unicode(creator), safe_unicode(create_date), safe_unicode(title), safe_unicode(date), safe_unicode(portal_name), safe_unicode(url)) else: prompt_text = translate( _(u"%s. (%s). Retrieved %s, from %s Web site: %s."), domain="ContentLicensing", target_language=self.request.LANGUAGE, ) % (safe_unicode(title), safe_unicode(create_date), safe_unicode(date), safe_unicode(portal_name), safe_unicode(url)) return prompt_text.replace('\'', '\\\'').replace('\"', '\\\'')
def getCitationInfo(self): """ Gets the citation information """ # Title title = self.context.title # Creators creator = '' index = 1 names = [name.strip() for name in self.context.Creators()] for cr in names: if cr and '@' == cr[0]: creator += '%s, ' %cr[1:] else: inits = '' crs = [] crs = cr.split(' ') for part in crs[:-1]: inits += ' ' + part[0] + '.' creator += crs[-1] if inits: creator += "," + inits creator += ', ' index += 1 if creator: creator = creator[:-2] if creator: if creator[-1] != '.': creator += '.' portal_url = getToolByName(self.context, 'portal_url') portal_name = portal_url.getPortalObject().title plone_view = getMultiAdapter((self.context, self.request), name='plone') create_date = plone_view.toLocalizedTime(self.context.creation_date) url = self.context.absolute_url() date = plone_view.toLocalizedTime(DateTime()) if creator: prompt_text = translate( _(u"%s (%s). %s. Retrieved %s, from %s Web site: %s."), domain="ContentLicensing", target_language=self.request.LANGUAGE, ) % ( safe_unicode(creator), safe_unicode(create_date), safe_unicode(title), safe_unicode(date), safe_unicode(portal_name), safe_unicode(url) ) else: prompt_text = translate( _(u"%s. (%s). Retrieved %s, from %s Web site: %s."), domain="ContentLicensing", target_language=self.request.LANGUAGE, ) % ( safe_unicode(title), safe_unicode(create_date), safe_unicode(date), safe_unicode(portal_name), safe_unicode(url) ) return prompt_text.replace('\'','\\\'').replace('\"','\\\'')