Esempio n. 1
0
class EditForm(base.EditForm):
    form_fields = Fields(IRecentConversationsPortlet)
    label = _(u"label_add_portlet",
              default=u"Add recent conversations portlet.")
    description = _(
        u"help_add_portlet",
        default=u"This portlet shows conversations with recent comments.")
Esempio n. 2
0
class ReportAddPage(AddForm):
    """ Add page
    """
    def __init__(self, context, request):
        super(ReportAddPage, self).__init__(context, request)
        request.debug = False

    form_fields = Fields(IAnalyticsReport)

    def create(self, data):
        """ Create
        """
        name = INameChooser(self.context).chooseName(data.get('title', ''),
                                                     None)
        ob = AnalyticsReport(id=name)
        applyChanges(ob, self.form_fields, data)
        return ob

    def add(self, obj):
        """ Add
        """
        name = obj.getId()
        self.context[name] = obj
        self._finished_add = True
        return obj

    def nextURL(self):
        """ Next URL
        """
        return "."
Esempio n. 3
0
    def __init__(self, context, request):
        def title(eid):
            """the title of entity *eid* (or *eid* itself)."""
            return getattr(context.get_entity(eid), "title", eid)

        self.form_fields = Fields(
            Choice(
                __name__=u"idp",
                title=_(u"identity_provider", u"Your identity provider"),
                vocabulary=SimpleVocabulary(
                    tuple(
                        SimpleTerm(eid, title(eid))
                        for eid in context.list_idps())),
                default=context.default_idp,
                required=True,
            ),
            ASCIILine(
                __name__=u"came_from",
                default=request.get("came_from", ""),
                required=False,
            ),
        )
        super(SelectIdp, self).__init__(context, request)
        self.form_fields["came_from"].custom_widget = make_hidden(
            GenericTextWidget)
Esempio n. 4
0
    def setUpFields(self):
        super(SourcePackageChangeUpstreamStepTwo, self).setUpFields()

        # The vocabulary for the product series is overridden to just
        # include active series from the product selected in the
        # previous step.
        product_name = self.request.form['field.product']
        self.product = getUtility(IProductSet)[product_name]
        series_list = [
            series for series in self.product.series
            if series.status != SeriesStatus.OBSOLETE
        ]

        # If the product is not being changed, then the current
        # productseries can be the default choice. Otherwise,
        # it will not exist in the vocabulary.
        if (self.context.productseries is not None
                and self.context.productseries.product == self.product):
            series_default = self.context.productseries
            # This only happens for obsolete series, since they aren't
            # added to the vocabulary normally.
            if series_default not in series_list:
                series_list.append(series_default)
        else:
            series_default = None

        # Put the development focus at the top of the list and create
        # the vocabulary.
        dev_focus = self.product.development_focus
        if dev_focus in series_list:
            series_list.remove(dev_focus)
        vocab_terms = [
            SimpleTerm(series, series.name, series.name)
            for series in series_list
        ]
        dev_focus_term = SimpleTerm(dev_focus, dev_focus.name,
                                    "%s (Recommended)" % dev_focus.name)
        vocab_terms.insert(0, dev_focus_term)

        productseries_choice = Choice(
            __name__='productseries',
            title=_("Series"),
            description=_("The series in this project."),
            vocabulary=SimpleVocabulary(vocab_terms),
            default=series_default,
            required=True)

        # The product selected in the previous step should be displayed,
        # but a widget can't be readonly and pass its value with the
        # form, so the real product field passes the value, and this fake
        # product field displays it.
        display_product_field = TextLine(__name__='fake_product',
                                         title=_("Project"),
                                         default=self.product.displayname,
                                         readonly=True)

        self.form_fields = (
            Fields(display_product_field, productseries_choice) +
            self.form_fields)
Esempio n. 5
0
class ReportEditPage(EditForm):
    """ Edit page
    """
    def __init__(self, context, request):
        super(ReportEditPage, self).__init__(context, request)
        request.debug = False

    form_fields = Fields(IAnalyticsReport)
Esempio n. 6
0
 def setUpFields(self):
     super(SourcePackageChangeUpstreamStepOne, self).setUpFields()
     series = self.context.productseries
     if series is not None:
         default = series.product
     else:
         default = None
     product_field = copy_field(IProductSeries['product'], default=default)
     self.form_fields += Fields(product_field)
Esempio n. 7
0
class AddForm(base.AddForm):
    form_fields = Fields(IRecentConversationsPortlet)
    label = _("label_add_portlet", default="Add recent conversations portlet.")
    description = _(
        "help_add_portlet",
        default="This portlet shows conversations with recent comments.")

    def create(self, data):
        return Assignment(title=data.get("title"), count=data.get("count"))
Esempio n. 8
0
class EditForm(BaseEditForm):
    """ Form to edit promotions
    """
    form_fields = Fields(IPromotion)
    form_fields = form_fields.omit('active')
    form_fields = form_fields.omit('themes')
    form_fields = form_fields.omit('themepage_section')
    form_fields['locations'].custom_widget = LocationsWidget
    label = u'Edit Promotion'
    template = ViewPageTemplateFile('form.pt')
Esempio n. 9
0
class DocumentAddForm(AddForm):
    form_fields = Fields(ISimpleDocument)
    label = u"Add document"

    template = NamedTemplate('simpledocument.form')

    def create(self, data):
        document = createObject(u'marginalia.SimpleDocument')
        applyChanges(document, self.form_fields, data)
        return document
Esempio n. 10
0
class Update(ZmiMixin, PageForm):
    label = _(u"entity_metadata_update", u"Metadata update")
    form_fields = Fields(IUpdateSchema)

    @action(_(u"update_metadata", u"Update metadata"))
    def update_(self, action, data):
        e = self.context
        e.aq_inner.aq_parent.metadata_by_id(e.id).fetch_metadata(
            data["clear_existing_metadata"])
        self.status = _(u"metadata_updated", u"Metadata updated")
Esempio n. 11
0
class ChartsEdit(EditForm, Edit):
    """ Edit google charts
    """
    label = _("Googlechart Edit")
    form_fields = Fields(IGoogleChartsEdit)

    def __call__(self, **kwargs):
        index = getattr(self, 'index', '')
        if index:
            index = index()
        result = super(ChartsEdit, self).__call__()
        return '\n'.join((index, result))
Esempio n. 12
0
class Add(AddForm):
    """ Add widget to dashboard
    """
    form_fields = Fields(IAdd)

    def prepare(self, data):
        """ Update data dict
        """
        data = super(Add, self).prepare(data)
        voc = queryUtility(IVocabularyFactory,
                           name=u'eea.googlecharts.vocabularies.charts')
        for term in voc(self.context):
            if term.value == data.get('name', ''):
                data['title'] = term.title
                data['path'] = term.token
        return data
Esempio n. 13
0
class ThemeEditForm(EditForm):
    """ Form for editing themes.
    """

    label = u'Edit themes'
    form_fields = Fields(IThemeTagging)
    form_fields['tags'].custom_widget = ThemesOrderedWidget

    def __call__(self):
        mtool = getToolByName(self.context, 'portal_membership')

        # by default max_length is decided by the IThemeTagging interface
        # but managers want to be able to add any number of themes
        if mtool.checkPermission('Manage portal', self.context):
            self.form_fields['tags'].field.max_length = None

        return super(ThemeEditForm, self).__call__()
Esempio n. 14
0
class CMISQueryAddForm(AddForm):
    label = u'Add a CMIS Query'
    form_fields = Fields(INameFromTitle, ICMISQuery)
    form_fields['browser'].custom_widget = widget_factory
    form_fields['text'].custom_widget = WYSIWYGWidget

    def create(self, data):
        query = createObject(u"collective.cmisquery.CMISQuery")
        content = self.context.add(query)
        # We need to add the content before editing it, in order to
        # have a working reference: we would get not yet overwise.
        applyChanges(content, self.form_fields, data)
        return content

    def add(self, content):
        self._finished_add = True
        return content
class MigrationView(Form):
    """view to migrate mailing lists"""

    form_fields = Fields()
    result_template = ZopeTwoPageTemplateFile('browser/migration.pt')

    @action(_('label_migrate', _(u'Migrate')))
    def handle_migrate_action(self, action, data):

        # permission checking needed since setting the permission
        # in zcml doesn't seem to work
        mtool = getToolByName(self.context, 'portal_membership')
        if not mtool.checkPermission('Manage Portal', self.context):
            return _(u'permission denied')

        ll = getUtility(IListLookup)
        mappings = ll.showAddressMapping()
        self.nlists = len(mappings)
        self.results = []
        for mapping in mappings:
            path = mapping['path']
            try:
                ml = self.context.unrestrictedTraverse(path)
                migrator = IMigrateList(ml)
                return_msg = migrator.migrate()
                absolute_url = ml.absolute_url()
            except AttributeError:
                return_msg = _(u'Error: List not found')
                absolute_url = ''

            self.results.append({
                'url': absolute_url,
                'title': path,
                'msg': return_msg
            })
        return self.result_template.render()

    def results(self):
        return self.results

    def num_lists(self):
        return self.nlists
 def __init__(self, context, request):
     """**ATTENTION** *context* is expected to be the object added
 not the container; the container is expected to be found in
 the acquisition context of *context*.
 """
     super(SchemaConfiguredAddForm, self).__init__(context, request)
     if hasattr(context, '__parent__'): parent = context.__parent__
     elif hasattr(context, 'aq_parent'): parent = context.aq_parent
     else: parent = None  # should not happen
     self.__parent__ = parent
     # set ``render_context`` for all fields different from ``id``
     # check whether there is an ``id`` field
     for f in self.form_fields:
         if f.__name__ == 'id':
             self.__id_is_field = True
             f.get_rendered = lambda form: context.getId()
         else:
             f.render_context = True
     if not self.__id_is_field:
         self.form_fields = Fields(ASCIILine(__name__='id', title=u"id")) \
                            + self.form_fields
Esempio n. 17
0
class Edit(EditForm):
    """ Edit dashboard widget
    """
    form_fields = Fields(IEdit)

    template = ViewPageTemplateFile('edit.pt')

    page = "edit"

    def prepare(self, data):
        """ Update data dict
        """
        data = super(Edit, self).prepare(data)
        data['name'] = 'multiples_' + data['name']

        voc = queryUtility(IVocabularyFactory,
                           name=u'eea.googlecharts.vocabularies.multiples')
        for term in voc(self.context):
            if term.value == data.get('name', ''):
                data['title'] = term.title
                data['path'] = term.token
        return data
Esempio n. 18
0
class AdmUtilUserPropertiesForm(FormBase):
    """ Form for user properties
    """
    form_fields = Fields(IAdmUtilUserProperties)
    label = _(u"Edit your user data")
    template_l = z3ctemplate.getLayoutTemplate(
        'org.ict_ok.ikadmin_utils.usermanagement.form')
    #getPageTemplate(
        #'org.ict_ok.ikadmin_utils.usermanagement.form')
    #template = NamedTemplate( \
        #'org.ict_ok.ikadmin_utils.usermanagement.form')
    
    def setUpWidgets(self, ignore_request=False):
        #import pdb; pdb.set_trace()
        self.adapters = {}
        self.widgets = setUpEditWidgets(
            self.form_fields, self.prefix, self.request.principal,
            self.request, adapters=self.adapters,
            ignore_request=ignore_request
            )
        
    @action(_(u"Save"), condition=haveInputWidgets)
    def handleSaveButton(self, action, data):
        principal = self.request.principal
        if applyChanges(principal, self.form_fields, data, self.adapters):
            self.status = _(u"Changes saved")
        else:
            self.status = _(u"No changes")
        pass
            
    def render(self):
        import pdb; pdb.set_trace()
        if self.template is None:
            template = zope.component.getMultiAdapter(
                (self, self.request), IPageTemplate)
            return template(self)
        return self.template()
Esempio n. 19
0
    def setUpFields(self):
        """See `LaunchpadFormView`."""
        super(SourcePackageAssociationPortletView, self).setUpFields()
        self.request.annotations['show_edit_buttons'] = True
        # Find registered products that are similarly named to the source
        # package.
        product_vocab = getVocabularyRegistry().get(None, 'Product')
        matches = product_vocab.searchForTerms(
            self.context.name,
            vocab_filter=[Product._information_type == InformationType.PUBLIC])
        # Based upon the matching products, create a new vocabulary with
        # term descriptions that include a link to the product.
        self.product_suggestions = []
        vocab_terms = []
        for item in matches[:self.max_suggestions]:
            product = item.value
            self.product_suggestions.append(product)
            item_url = canonical_url(product)
            description = structured('<a href="%s">%s</a>', item_url,
                                     product.displayname)
            vocab_terms.append(SimpleTerm(product, product.name, description))
        # Add an option to represent the user's decision to choose a
        # different project. Note that project names cannot be uppercase.
        vocab_terms.append(
            SimpleTerm(self.other_upstream, 'OTHER_UPSTREAM',
                       'Choose another upstream project'))
        vocab_terms.append(
            SimpleTerm(self.register_upstream, 'REGISTER_UPSTREAM',
                       'Register the upstream project'))
        upstream_vocabulary = SimpleVocabulary(vocab_terms)

        self.form_fields = Fields(
            Choice(__name__='upstream',
                   title=_('Registered upstream project'),
                   default=self.other_upstream,
                   vocabulary=upstream_vocabulary,
                   required=True))
Esempio n. 20
0
class Add(AddForm):
    """ Add widget to dashboard
    """
    form_fields = Fields(IAdd)

    template = ViewPageTemplateFile('edit.pt')

    page = "add"

    def prepare(self, data):
        """ Update data dict
        """
        data = super(Add, self).prepare(data)
        #add "multiples_" prefix so we can make a difference
        #between charts and small multiples
        data['name'] = 'multiples_' + data['name']

        voc = queryUtility(IVocabularyFactory,
                           name=u'eea.googlecharts.vocabularies.multiples')
        for term in voc(self.context):
            if term.value == data.get('name', ''):
                data['title'] = term.title
                data['path'] = term.token
        return data
Esempio n. 21
0
class Add(AddForm):
    """ Add portlet widget to dashboard
    """
    form_fields = Fields(IPortletAdd)
Esempio n. 22
0
class Add(AddForm):
    """ Add widget to dashboard
    """
    form_fields = Fields(IWidgetAdd)
Esempio n. 23
0
class Edit(EditForm):
    """ Edit view
    """
    label = _(u"Data settings")
    form_fields = Fields(IDataEdit)
    previewname = "daviz.properties.preview.png"
    message = _('Changes saved')

    @property
    def _data(self):
        """ Form data
        """
        accessor = queryAdapter(self.context, IVisualizationConfig)
        json = simplejson.dumps(dict(accessor.json), indent=2)
        utils = queryUtility(IVisualizationJsonUtils)
        return {
            'name': self.prefix,
            'json': utils.sortProperties(json, indent=2),
            'views': [view.get('name') for view in accessor.views],
            'sources': [source.get('name') for source in accessor.sources],
        }

    def setUpWidgets(self, ignore_request=False):
        """ Setup widgets
        """
        self.adapters = {}
        for key, value in self.request.form.items():
            if isinstance(value, str):
                value = value.decode('utf-8')
                self.request.form[key] = value

        self.widgets = setUpWidgets(self.form_fields,
                                    self.prefix,
                                    self.context,
                                    self.request,
                                    form=self,
                                    data=self._data,
                                    adapters=self.adapters,
                                    ignore_request=ignore_request)

    def handle_json(self, data):
        """ Handle json property
        """
        mutator = queryAdapter(self.context, IVisualizationConfig)
        old_columns = set(mutator.json.get('properties', {}).keys())

        json = data.get('json', None)
        if json is None:
            return

        try:
            json = dict(simplejson.loads(json))
        except Exception, err:
            logger.exception(err)
            self.message = "ERROR: %s" % err
            return

        properties = json.get('properties', {})
        new_columns = set(properties.keys())

        for _name, props in properties.items():
            columnType = props.get('columnType',
                                   props.get('valueType', 'text'))
            util = queryUtility(IGuessType, columnType)
            if not util:
                continue
            props['columnType'] = columnType
            props['valueType'] = util.valueType

        # Columns deleted
        for column in old_columns.difference(new_columns):
            notify(VisualizationFacetDeletedEvent(self.context, facet=column))

        mutator.json = json
        notify(ObjectModifiedEvent(self.context))
Esempio n. 24
0
class Edit(EditForm):
    """ Edit form
    """
    form_fields = Fields(INumericProperties)
Esempio n. 25
0
class Edit(EditForm):
    """ Edit tabular view
    """
    label = u"Tabular view settings"
    form_fields = Fields(IExhibitTabularEdit)
    previewname = "daviz.tabular.preview.png"
Esempio n. 26
0
class Edit(EditForm):
    """ Edit form
    """
    form_fields = Fields(IHierarchicalProperties)
Esempio n. 27
0
class Edit(EditForm):
    """ Edit map view
    """
    label = u"Map view settings"
    form_fields = Fields(IExhibitMapEdit)
    previewname = "daviz.map.preview.png"
Esempio n. 28
0
class Edit(EditForm):
    """ Edit form
    """
    form_fields = Fields(ICloudProperties)
Esempio n. 29
0
class ThemeCentreEdit(EditForm):
    """ Form for setting theme for a theme centre.
    """

    form_fields = Fields(IThemeCentreSchema, IThemeRelation)
    label = u'Promote theme centre'
Esempio n. 30
0
class DocumentEditForm(EditForm):
    form_fields = Fields(ISimpleDocument)
    label = u"Edit document"

    template = NamedTemplate('simpledocument.form')