Пример #1
0
class TextLineWidget(SchemaFieldWidget):
    template = getTemplate('textlinewidget.pt')
    defaultHtmlClass = ['field', 'field-textline']
    defaultHtmlAttributes = set([
        'readonly', 'required', 'autocomplete', 'maxlength', 'pattern',
        'placeholder', 'size', 'style', 'disabled'
    ])
Пример #2
0
class LinkFieldWidget(FieldWidget):

    template = getTemplate('linkfieldwidget.pt')

    def url(self):
        content = self.form.getContentData().getContent()
        return IURL(content, self.request)
Пример #3
0
class MultiChoiceFieldWidget(ChoiceFieldWidget):

    template = getTemplate('multichoicefieldwidget.pt')

    def __init__(self, field, value_field, form, request):
        super(MultiChoiceFieldWidget, self).__init__(field, form, request)
        self.source = value_field

    def prepareContentValue(self, value):
        form_value = []
        if value is NO_VALUE:
            return {self.identifier: form_value}
        choices = self.choices()
        for entry in value:
            try:
                term = choices.getTerm(entry)
                form_value.append(term.token)
            except LookupError:
                pass
        return {self.identifier: form_value}

    def renderableChoice(self):
        current = self.inputValue()
        base_id = self.htmlId()
        for i, choice in enumerate(self.choices()):
            yield {'token': choice.token,
                   'title': choice.title,
                   'checked': choice.token in current,
                   'id': base_id + '-' + str(i)}
Пример #4
0
class ChoiceFieldWidget(SchemaFieldWidget):

    template = getTemplate('choicefieldwidget.pt')

    def __init__(self, field, form, request):
        super(ChoiceFieldWidget, self).__init__(field, form, request)
        self.source = field
        self.__choices = None

    def lookupTerm(self, value):
        choices = self.choices()
        try:
            return choices.getTerm(value)
        except LookupError:
            # the stored value is invalid. fallback on the default one.
            default = self.component.getDefaultValue(self.form)
            if default is not NO_VALUE:
                return choices.getTerm(default)
        return None

    def valueToUnicode(self, value):
        term = self.lookupTerm(value)
        if term is not None:
            return term.token
        return u''

    def choices(self):
        if self.__choices is not None:
            return self.__choices
        # self.source is used instead of self.component in order to be
        # able to override it in subclasses.
        self.__choices = self.source.getChoices(self.form.context)
        return self.__choices
Пример #5
0
class ListObjectFieldWidget(MultiObjectFieldWidget):

    template = getTemplate('listobjectfieldwidget.pt')

    def __init__(self, field, value_field, form, request):
        super(ListObjectFieldWidget, self).__init__(
            field, value_field, form, request)
        self.allowOrdering = field.allowOrdering
Пример #6
0
class ChoiceDisplayWidget(ChoiceFieldWidget):

    template = getTemplate('choicedisplaywidget.pt')

    def valueToUnicode(self, value):
        term = self.lookupTerm(value)
        if term is not None:
            return term.title
        return u''
Пример #7
0
class MultiChoiceDisplayFieldWidget(MultiChoiceFieldWidget):
    template = getTemplate('multichoicedisplayfieldwidget.pt')

    def renderableChoice(self):
        current = self.inputValue()
        base_id = self.htmlId()
        for i, choice in enumerate(self.choices()):
            if choice.token in current:
                yield {'title': choice.title,
                       'id': base_id + '-' + str(i)}
Пример #8
0
class RadioFieldWidget(ChoiceFieldWidget):

    template = getTemplate('radiofieldwidget.pt')

    def renderableChoices(self):
        current = self.inputValue()
        base_id = self.htmlId()
        for i, choice in enumerate(self.choices()):
            yield {'token': choice.token,
                   'title': choice.title or choice.token,
                   'checked': choice.token == current and 'checked' or None,
                   'id': base_id + '-' + str(i)}
Пример #9
0
class ObjectFieldWidget(SchemaFieldWidget):

    template = getTemplate('objectfieldwidget.pt')

    def prepareContentValue(self, value):
        if value is NO_VALUE:
            return {self.identifier: []}
        return {self.identifier: value}

    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()
Пример #10
0
class PasswordWidget(SchemaFieldWidget):
    template = getTemplate('passwordwidget.pt')
    defaultHtmlClass = ['field', 'field-password']
    defaultHtmlAttributes = ['readonly', 'required', 'autocomplete',
                             'maxlength', 'pattern', 'placeholder',
                             'size', 'style']
Пример #11
0
class MultiSelectFieldWidget(MultiChoiceFieldWidget):
    template = getTemplate('multiselectfieldwidget.pt')
Пример #12
0
class TextFieldWidget(SchemaFieldWidget):
    template = getTemplate('textfieldwidget.pt')
    defaultHtmlClass = ['field']
    defaultHtmlAttributes = set(['maxlength', 'placeholder', 'required',
                                 'rows', 'warp', 'readonly', 'cols',
                                 'style'])
Пример #13
0
class TextDisplayWidget(SchemaFieldWidget):
    template = getTemplate('pre_text.pt')
    defaultHtmlAttributes = set(['style'])
Пример #14
0
class MultiObjectFieldWidget(MultiGenericFieldWidget):

    template = getTemplate('multiobjectfieldwidget.pt')

    def getFields(self):
        return self.valueField.objectFields
Пример #15
0
class MultiGenericDisplayFieldWidget(MultiGenericFieldWidget):
    template = getTemplate('multigenericdisplayfieldwidget.pt')
Пример #16
0
class MultiGenericFieldWidget(SchemaFieldWidget):

    allowAdding = True
    allowRemove = True

    template = getTemplate('multigenericfieldwidget.pt')

    def __init__(self, field, value_field, form, request):
        super(MultiGenericFieldWidget, self).__init__(field, form, request)
        self.allowAdding = field.allowAdding
        self.allowRemove = field.allowRemove
        self.valueField = value_field
        self.valueWidgets = Widgets()
        self.haveValues = False

    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 createWidget(field, form, self.request)

    def addValueWidget(self, new_identifier, value):
        widget = self.createValueWidget(new_identifier, value)
        if widget is not None:
            self.valueWidgets.append(widget)
        return widget

    def prepareContentValue(self, values):
        if values is NO_VALUE:
            return {self.identifier: '0'}
        for position, value in enumerate(values):
            # Create new widgets for each value
            self.addValueWidget(position, value)
        count = len(values)
        if count:
            self.haveValues = True
        return {self.identifier: str(count)}

    def prepareRequestValue(self, values):
        value_count = 0
        identifier_count = int(values.get(self.identifier, '0'))
        remove_something = self.identifier + '.remove' in values
        for position in range(0, identifier_count):
            value_marker = (self.identifier, position,)
            value_present = '%s.present.%d' % value_marker in values
            if not value_present:
                continue
            value_selected = '%s.checked.%d' % value_marker in values
            if remove_something and value_selected:
                continue
            self.addValueWidget(position, None)
            value_count += 1
        if self.identifier + '.add' in values:
            self.addValueWidget(identifier_count, None)
            value_count += 1
            values[self.identifier] = str(identifier_count + 1)
        if value_count:
            self.haveValues = True
        return values

    @property
    def jsonTemplateWidget(self):
        widgets = Widgets()
        widgets.append(self.createValueWidget('{identifier}', None))
        widgets.update()
        return list(widgets)[0]

    def update(self):
        super(MultiGenericFieldWidget, self).update()
        self.valueWidgets.update()

        self.jsonAddIdentifier = None
        self.jsonAddTemplate = None
        self.includeEmptyMessage = self.allowRemove
        if self.allowAdding:
            self.jsonAddIdentifier = 'id' + md5hash(self.identifier)
            widgets = Widgets()
            widgets.append(self.createValueWidget(
                    '{' + self.jsonAddIdentifier + '}', None))
            widgets.update()
            self.jsonAddTemplate = list(widgets)[0]
Пример #17
0
class CheckBoxWidget(SchemaFieldWidget):
    template = getTemplate('checkboxwidget.pt')