Ejemplo n.º 1
0
 def update(self):
     super(ObjectFieldWidget, self).update()
     value = self.component.dataManager(self.inputValue())
     form = cloneFormData(self.form, value, self.identifier)
     self.objectWidgets = Widgets(form=form, request=self.request)
     self.objectWidgets.extend(self.component.objectFields)
     self.objectWidgets.update()
Ejemplo n.º 2
0
 def extract(self):
     value = self.request.form.get(self.identifier, NO_VALUE)
     if value is not NO_VALUE:
         try:
             value = int(value)
         except ValueError:
             return (None, u"Invalid internal input")
         collectedValues = []
         collectedErrors = Errors(identifier=self.identifier)
         for position in range(0, value):
             value_present = '%s.present.%d' % (
                 self.identifier, position) in self.request.form
             if not value_present:
                 # This value have been removed
                 continue
             field = self.valueField.clone(new_identifier=str(position))
             form = cloneFormData(self.form, prefix=self.identifier)
             data, errors = form.extractData(Fields(field))
             if errors:
                 collectedErrors.extend(errors)
             else:
                 collectedValues.append(data[field.identifier])
         if collectedErrors:
             return (None, collectedErrors)
         value = self.component.collectionType(collectedValues)
     return (value, None)
Ejemplo n.º 3
0
 def createValueWidget(self, new_identifier, value):
     field = self.valueField.clone(new_identifier=str(new_identifier))
     form = cloneFormData(self.form, prefix=self.identifier)
     if value is not None:
         form.ignoreContent = False
         form.setContentData(NoneDataManager(value))
     else:
         form.ignoreRequest = False
         form.ignoreContent = True
     return form.widgetFactory.widget(field)
Ejemplo n.º 4
0
 def extract(self):
     is_present = self.request.form.get(self.identifier, NO_VALUE)
     if is_present is NO_VALUE:
         return (NO_VALUE, None)
     value = None
     form = cloneFormData(self.form, None, self.identifier)
     data, errors = form.extractData(self.component.objectFields)
     if not errors:
         factory = self.component.getObjectFactory()
         # Create an object with values
         value = factory(**dict(filter(
                     lambda (k, v): not isinstance(v, Marker),
                     data.items())))
         return (value, None)
     return (value, Errors(*errors, identifier=self.identifier))
    def updateLines(self, mark_selected=False):
        self.lines = []
        self.lineWidgets = []
        manager = IRolePermissionManager(self.getContent())

        for position, item in enumerate(self.getItems()):
            prefix = '%s.line-%d' % (self.prefix, position)
            form = cloneFormData(
                self, content=PermissionWrapper(item, manager), prefix=prefix)
            form.selected = False

            titleField = SchemaField(TextLine(
                __name__="title",
                title=u"title",                
                default=u""))
    
            titleField.mode = DISPLAY
            titleField.ignoreRequest = True
            titleField.ignoreContent = True
            titleField.readonly = True
            titleField.defaultValue = item.title
            
            lineWidget = Widgets(form=form, request=self.request)

            # Checkbox to select the line
            selectedField = SelectField(identifier=position)

            if mark_selected:
                # Mark selected lines
                selectedExtractor = getWidgetExtractor(
                    selectedField, form, self.request)
                if selectedExtractor is not None:
                    value, error = selectedExtractor.extract()
                    if value:
                        form.selected = True

            lineWidget.extend(selectedField)
            lineWidget.extend(titleField)
            self.lines.append(form)
            self.lineWidgets.append(lineWidget)
Ejemplo n.º 6
0
    def updateLines(self, mark_selected=False):
        self.lines = []
        self.lineWidgets = []
        self.batching = None
        items = self.getItems()
        if self.batchSize:
            items = self.batchFactory(
                items,
                name=self.prefix,
                factory=self.batchItemFactory,
                count=self.batchSize,
                request=self.request)
            self.batching = queryMultiAdapter(
                (self.getFormForTable(), items, self.request), IBatching)()
        for position, item in enumerate(items):
            prefix = '%s.line-%s' % (self.prefix,
                self.getItemIdentifier(item, position))
            form = cloneFormData(self, content=item, prefix=prefix)
            form.selected = False

            # Checkbox to select the line
            form.selectedField = self.createSelectedField(item)

            if mark_selected:
                # Mark selected lines
                selectedExtractor = form.widgetFactory.extractor(
                    form.selectedField)
                if selectedExtractor is not None:
                    value, error = selectedExtractor.extract()
                    if value:
                        form.selected = True

            lineWidget = Widgets(form=form, request=self.request)
            lineWidget.extend(form.selectedField)
            self.lines.append(form)
            self.lineWidgets.append(lineWidget)