Exemplo n.º 1
0
 def prepareRequestValue(self, values, extractor):
     resolver = ReferenceInfoResolver(
         self.request, self.form.context, self,
         multiple=True,
         message=self.referenceLabel)
     resolver.update(
         interface=self.component.schemaName,
         show_index=self.component.showIndex)
     self.items = []
     # XXX This needs to be implemented
     return {self.identifier: str(len(self.items))}
Exemplo n.º 2
0
    def update(self):
        super(ReferenceWidgetInput, self).update()
        need(IReferenceUIResources)

        resolver = ReferenceInfoResolver(
            self.request, self.form.context, self,
            multiple=False,
            message=self.referenceLabel)
        resolver.update(
            interface=self.component.schemaName,
            show_index=self.component.showIndex)
        resolver.add(value_id=self.inputValue())
Exemplo n.º 3
0
    def prepareContentValue(self, values):
        resolver = ReferenceInfoResolver(
            self.request, self.form.context, self,
            multiple=True,
            message=self.referenceLabel)
        resolver.update(
            interface=self.component.schemaName,
            show_index=self.component.showIndex)

        self.items = []
        if values is not NO_VALUE and values:
            for value in values:
                info = ValueInfo()
                resolver.add(value=value, sub_widget=info)
                self.items.append(info)

        return {self.identifier: str(len(self.items))}
Exemplo n.º 4
0
    def __init__(self, context, request, field, value):
        self.context = context
        self.request = request
        # For security
        self.__parent__ = context

        # For the widget
        self.id = field.generate_field_html_id()
        self.name = field.generate_field_key()
        self.title = field.title()
        self.multiple = bool(field.get_value('multiple'))
        self.required = bool(field.get_value('required'))

        css_class = []
        if self.multiple:
            css_class.append('field-multiple')
        if self.required:
            css_class.append('field-required')
        self.css_class = ' '.join(css_class) or None

        self.value = None
        self.value_id = None
        self.extra_values = []

        resolver = ReferenceInfoResolver(
            self.request, self.context, self,
            multiple=self.multiple,
            message=field.get_value('default_msg') or _(u"No content selected."))
        resolver.update(
            interface=field.get_interface(),
            show_index=field.get_value('show_container_index'))

        if self.multiple:
            self.values = []
            # Support for one value list from the request (string are lists...).
            if isinstance(value, basestring) or not isinstance(value, list):
                if value:
                    value = [value]
                else:
                    value = []
            # Go through each value and prepare information
            for item in value:
                info = ValueInfo()
                if isinstance(item, (basestring, int)):
                    resolver.add(value_id=item, sub_widget=info)
                else:
                    resolver.add(value=item, sub_widget=info)
                self.values.append(info)

            self.value = len(self.values) and self.values[0] or None
            self.extra_values = len(self.values) and self.values[1:] or []
        else:
            # Prepare information
            self.value = ValueInfo()
            if isinstance(value, (basestring, int)):
                resolver.add(value_id=value, sub_widget=self.value)
            else:
                resolver.add(value=value, sub_widget=self.value)

        # Shortcut for template.
        if self.value is not None:
            self.value_id = self.value.value_id
Exemplo n.º 5
0
 def updateWidget(self, value):
     resolver = ReferenceInfoResolver(self.request, self.query, self)
     resolver.update(interface=self.interface)
     resolver.add(value=value)