Beispiel #1
0
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.")
Beispiel #2
0
    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[