def toWidgetValue(self, value): """See interfaces.IDataConverter""" if value is self.field.missing_value: return [''] if isinstance(value, six.string_types): return [util.toUnicode(value)] return [util.toUnicode(v) for v in value if v]
def getTerm(self, value): try: return self.vocabulary.getTerm(value) except LookupError: # all form widgets are called when using plone.formwidget.masterselect on a form field # this is done as anonymous and the vocabulary is then empty # it's not necessary here to render the correct term # see z3c.form.term if '++widget++' in self.context.REQUEST.get('URL', ''): return SimpleTerm(value, util.createCSSId(util.toUnicode(value)), title=_zf(u'Missing: ${value}', mapping=dict(value=util.toUnicode(value)))) raise
def src(self): site = hooks.getSite() src = util.toUnicode( zope.traversing.api.traverse(site, '++resource++' + self.field.image, request=self.request)()) return src
def _makeMissingTerm(self, value): """Return a term that should be displayed for the missing token""" uvalue = util.toUnicode(value) return vocabulary.SimpleTerm(value, self._makeToken(value), title=_(u'Missing: ${value}', mapping=dict(value=uvalue)))
def items(self): if self.terms is None: return () registry = getUtility(IRegistry) urls = registry.get(self.links_record) items = [] for term in self.terms: checked = self.isChecked(term) id = '%s-%s' % (self.id, term.value) if ITitledTokenizedTerm.providedBy(term): label = translate(term.title, context=self.request, default=term.title) else: label = util.toUnicode(term.value) items.append({ 'id': id, 'name': self.name + ':list', 'value': term.token, 'label': label, 'checked': checked, 'url': urls.get(term.value).get('url') }) return items
def items(self): bookable = self.bookable_items if not bookable: return results = [] for count, term in enumerate(self.bookable_items): checked = self.isChecked(term) id = "%s-%i" % (self.id, count) if zope.schema.interfaces.ITitledTokenizedTerm.providedBy(term): label = translate( term.title, context=self.request, default=term.title ) else: label = util.toUnicode(term.value) results.append( { "id": id, "name": self.name, "value": term.token, "label": label, "checked": checked, "index": count, } ) return results
def items(self): # TODO: check if we should cache the return list if self.terms is None: # update() not yet called return () vocab = getUtility( IVocabularyFactory, "org.bccvl.site.algorithm_category_vocab")(self.context) items = OrderedDict((cat.value, []) for cat in chain((SimpleTerm(None),), vocab)) for count, term in enumerate(self.terms): alg = term.brain.getObject() # skip algorithm without category # if alg.algorithm_category is None or alg.algorithm_category not in items: # continue itemList = items[alg.algorithm_category] checked = self.isChecked(term) id = '%s-%i' % (self.id, count) if ITitledTokenizedTerm.providedBy(term): label = translate( term.title, context=self.request, default=term.title) else: label = util.toUnicode(term.value) catterm = SimpleTerm(None) if alg.algorithm_category in vocab: catterm = vocab.getTerm(alg.algorithm_category) itemList.append({'id': id, 'name': self.name + ':list', 'value': term.token, 'label': label, 'checked': checked, 'subject': term.brain.Subject, 'description': term.brain.Description, 'category': catterm, 'pos': len(itemList)}) return items.values()
def toWidgetValueTextLinesFix(self, value): """Convert from text lines to HTML representation.""" # if the value is the missing value, then an empty list is produced. if value is self.field.missing_value: return u"" if not value: return u"" return u"\n".join(util.toUnicode(v) for v in value)
def ImageFieldWidget(field, request): image = FieldWidget(field, ImageWidget(request)) image.value = field.title # Get the full resource URL for the image: site = hooks.getSite() image.src = util.toUnicode(zope.traversing.api.traverse( site, '++resource++' + field.image, request=request)()) return image
def __init__(self, context, request, form, field, widget, results): self.context = context self.request = request self.form = form self.field = field self.widget = widget ids = set([z3c_form_util.toUnicode(elem['ga:pagePath']) for elem in results]) terms = [SimpleTerm(value=id, token=id, title=u"") for id in ids] self.terms = SimpleVocabulary(terms)
def render_default_title(self, item, value): """Render the default title colum with the term's title.""" term = self.terms.getTerm(item) if ITitledTokenizedTerm.providedBy(term): label = translate(term.title, context=self.request, default=term.title) else: label = util.toUnicode(term.value) return label
def render_default_title(self, item, value): """Render the default title colum with the term's title.""" if isinstance(item, NullObject): return _(u'label_none', default=u'None') term = self.terms.getTerm(item) if ITitledTokenizedTerm.providedBy(term): label = translate(term.title, context=self.request, default=term.title) else: label = util.toUnicode(term.value) return label
def items(self): if self.terms is None: return for count, term in enumerate(self.terms): checked = self.isChecked(term) id = '%s-%i' % (self.id, count) if zope.schema.interfaces.ITitledTokenizedTerm.providedBy(term): label = translate(term.title, context=self.request, default=term.title) else: label = util.toUnicode(term.value) yield {'id': id, 'name': self.name, 'value': term.token, 'label': label, 'checked': checked}
def update(self): """See z3c.form.interfaces.IWidget.""" super(CheckBoxWidget, self).update() widget.addFieldClass(self) self.items = [] for count, term in enumerate(self.terms): checked = self.isChecked(term) id = '%s-%i' % (self.id, count) label = util.toUnicode(term.value) if zope.schema.interfaces.ITitledTokenizedTerm.providedBy(term): label = translate(term.title, context=self.request, default=term.title) self.items.append( {'id':id, 'name':self.name + ':list', 'value':term.token, 'label':label, 'checked':checked})
def update(self): """See z3c.form.interfaces.IWidget.""" super(CheckBoxWidget, self).update() widget.addFieldClass(self) self.items = [] for count, term in enumerate(self.terms): checked = self.isChecked(term) id = '%s-%i' % (self.id, count) if zope.schema.interfaces.ITitledTokenizedTerm.providedBy(term): label = translate(term.title, context=self.request, default=term.title) else: label = util.toUnicode(term.value) self.items.append( {'id':id, 'name':self.name + ':list', 'value':term.token, 'label':label, 'checked':checked})
def items(self): # TODO: check if we should cache the return list if self.terms is None: # update() not yet called return () items = [] for count, term in enumerate(self.terms): checked = self.isChecked(term) id = '%s-%i' % (self.id, count) if ITitledTokenizedTerm.providedBy(term): label = translate(term.title, context=self.request, default=term.title) else: label = util.toUnicode(term.value) items.append ({'id': id, 'name': self.name + ':list', 'value':term.token, 'label':label, 'checked': checked, 'subject': term.brain.Subject}) return items
def items(self): bookable = self.bookable_items if not bookable: return results = [] for count, term in enumerate(self.bookable_items): checked = self.isChecked(term) id = '%s-%i' % (self.id, count) if zope.schema.interfaces.ITitledTokenizedTerm.providedBy(term): label = translate(term.title, context=self.request, default=term.title) else: label = util.toUnicode(term.value) results.append({'id': id, 'name': self.name, 'value': term.token, 'label': label, 'checked': checked, 'index': count}) return results
def items(self): items = [] current_blocked = self.analytics_moderation.block_results headers = self.headers() for count, result in enumerate(self.results): value = result['ga:pagePath'] checked = current_blocked and value in current_blocked auto_blocked = result not in self.filtered_results id = '%s-%i' % (self.id, count) label = z3c_form_util.toUnicode(value) item = {'id': id, 'name': self.name + ':list', 'value': value, 'label': label, 'checked': checked, 'auto_blocked': auto_blocked} for header in headers: item[header] = result[header] items.append(item) return items
def update(self): """See z3c.form.interfaces.IWidget.""" super(CheckBoxWidget, self).update() widget.addFieldClass(self) # XXX: this is to early for setup items. See select widget how this # sould be done. Setup the items here doens't allow to override the # widget.value in updateWidgets, ri self.items = [] for count, term in enumerate(self.terms): checked = self.isChecked(term) id = '%s-%i' % (self.id, count) if zope.schema.interfaces.ITitledTokenizedTerm.providedBy(term): label = translate(term.title, context=self.request, default=term.title) else: label = util.toUnicode(term.value) self.items.append( {'id':id, 'name':self.name + ':list', 'value':term.token, 'label':label, 'checked':checked})
def items(self): if self.terms is None: return for count, term in enumerate(self.terms): checked = self.isChecked(term) id = '%s-%i' % (self.id, count) if zope.schema.interfaces.ITitledTokenizedTerm.providedBy(term): label = translate(term.title, context=self.request, default=term.title) else: label = util.toUnicode(term.value) yield { 'id': id, 'name': self.name, 'value': term.token, 'label': label, 'checked': checked }
def items(self): # TODO: check if we should cache the return list if self.terms is None: # update() not yet called return () vocab = getUtility(IVocabularyFactory, "org.bccvl.site.algorithm_category_vocab")( self.context) items = OrderedDict( (cat.value, []) for cat in chain((SimpleTerm(None), ), vocab)) for count, term in enumerate(self.terms): alg = term.brain.getObject() # skip algorithm without category # if alg.algorithm_category is None or alg.algorithm_category not in items: # continue itemList = items[alg.algorithm_category] checked = self.isChecked(term) id = '%s-%i' % (self.id, count) if ITitledTokenizedTerm.providedBy(term): label = translate(term.title, context=self.request, default=term.title) else: label = util.toUnicode(term.value) catterm = SimpleTerm(None) if alg.algorithm_category in vocab: catterm = vocab.getTerm(alg.algorithm_category) itemList.append({ 'id': id, 'name': self.name + ':list', 'value': term.token, 'label': label, 'checked': checked, 'subject': term.brain.Subject, 'description': term.brain.Description, 'category': catterm, 'pos': len(itemList) }) return items.values()
def items(self): # TODO: check if we should cache the return list if self.terms is None: # update() not yet called return () items = [] for count, term in enumerate(self.terms): checked = self.isChecked(term) id = '%s-%i' % (self.id, count) if ITitledTokenizedTerm.providedBy(term): label = translate(term.title, context=self.request, default=term.title) else: label = util.toUnicode(term.value) items.append({ 'id': id, 'name': self.name + ':list', 'value': term.token, 'label': label, 'checked': checked, 'subject': term.brain.Subject }) return items
def update(self): if self.request.REQUEST_METHOD == 'GET': # add fields subscriber = self.context details = subscriber.get_details() phones = details.get("phone_numbers", "").split(", ") first_name = schema.TextLine( __name__="first_name", title=_(u'label_first_name', default=u'Name'), description=_(u'help_first_name', default=u'Enter your first name.'), required=False, default=util.toUnicode(details.get("first_name", ""))) last_name = schema.TextLine( __name__="last_name", title=_(u'label_last_name', default=u'Family name'), description=_(u'help_last_name', default=u'Enter your last name.'), required=False, default=util.toUnicode(details.get("last_name", ""))) phone_numbers = schema.List(__name__="phone_numbers", title=_(u'label_phone_numbers', default=u'Phone numbers'), description=_( u'help_phone_numbers', default=u'Fill in phone numbers.'), value_type=schema.TextLine(), required=False, default=phones) institution = schema.TextLine( __name__="institution", title=_(u'label_institution', default=u'Organisation'), description=_(u'help_institution', default=u'Fill in the organisation'), required=False, default=util.toUnicode(details.get("institution", ""))) position = schema.TextLine( __name__="position", title=_(u'label_position', default=u'Position'), description=_( u'help_position', default=u'Fill in your position within your Organisation'), required=False, default=util.toUnicode(details.get("position", ""))) from_country = schema.TextLine( __name__="from_country", title=_(u'label_from_country', default=u'Country'), description=_(u'help_from_country', default=u'Fill in your country.'), required=False, default=util.toUnicode(details.get("from_country", ""))) from_city = schema.TextLine( __name__="from_city", title=_(u'label_from_city', default=u'City'), description=_(u'help_from_city', default=u'Fill in your city.'), required=False, default=util.toUnicode(details.get("from_city", ""))) self.form.fields += Fields(first_name, last_name, phone_numbers, institution, position, from_country, from_city) if self.request.REQUEST_METHOD == 'POST': # save values if 'form.buttons.save' in self.request.form: prefix = 'form.widgets.' userid = self.request.form.get('form.widgets.userid') member = api.user.get(userid=userid) member.setMemberProperties( mapping={ "first_name": self.request.form.get(prefix + 'first_name'), "last_name": self.request.form.get(prefix + 'last_name'), "phone_numbers": self.request.form.get(prefix + 'phone_numbers').split("\r\n"), "institution": self.request.form.get(prefix + 'institution'), "position": self.request.form.get(prefix + 'position'), "from_country": self.request.form.get(prefix + 'from_country'), "from_city": self.request.form.get(prefix + 'from_city'), })
def _makeMissingTerm(self, value): """Return a term that should be displayed for the missing token""" uvalue = util.toUnicode(value) return vocabulary.SimpleTerm( value, self._makeToken(value), title=_(u'Missing: ${value}', mapping=dict(value=uvalue)))
def src(self): site = hooks.getSite() src = util.toUnicode(zope.traversing.api.traverse( site, '++resource++' + self.field.image, request=self.request)()) return src
def toWidgetValue(self, value): """See interfaces.IDataConverter""" if value is self.field.missing_value: return u'' return util.toUnicode(value)
def _makeToken(self, value): """create a unique valid ASCII token""" return util.createCSSId(util.toUnicode(value))
def toWidgetValue(self, value): """Convert from text lines to HTML representation.""" # if the value is the missing value, then an empty list is produced. if value is self.field.missing_value: return u'' return u'\n'.join(util.toUnicode(v) for v in value)
def update(self): if self.request.REQUEST_METHOD == 'GET': # add fields subscriber = self.context details = subscriber.get_details() phones = details.get("phone_numbers", "").split(", ") first_name = schema.TextLine( __name__="first_name", title=_(u'label_first_name', default=u'Name'), description=_(u'help_first_name', default=u'Enter your first name.'), required=False, default=util.toUnicode(details.get("first_name", "")) ) last_name = schema.TextLine( __name__="last_name", title=_(u'label_last_name', default=u'Surname'), description=_(u'help_last_name', default=u'Enter your last name (family name).'), required=False, default=util.toUnicode(details.get("last_name", "")) ) phone_numbers = schema.List( __name__="phone_numbers", title=_(u'label_phone_numbers', default=u'Phone numbers'), description=_(u'help_phone_numbers', default=u'Fill in phone numbers.'), value_type=schema.TextLine(), required=False, default=phones ) institution = schema.TextLine( __name__="institution", title=_(u'label_institution', default=u'Institution'), description=_(u'help_institution', default=u'Fill in the institution'), required=False, default=util.toUnicode(details.get("institution", "")) ) position = schema.TextLine( __name__="position", title=_(u'label_position', default=u'Position'), description=_( u'help_position', default=u'Fill in your position within your Institution'), required=False, default=util.toUnicode(details.get("position", "")) ) from_country = schema.TextLine( __name__="from_country", title=_(u'label_from_country', default=u'From country'), description=_(u'help_from_country', default=u'Fill in the From country'), required=False, default=util.toUnicode(details.get("from_country", "")) ) from_city = schema.TextLine( __name__="from_city", title=_(u'label_from_city', default=u'From city'), description=_(u'help_from_city', default=u'Fill in the From city'), required=False, default=util.toUnicode(details.get("from_city", "")) ) address = schema.Text( __name__="address", title=_(u'label_address', default=u'Address'), description=_(u'help_address', default=u'Fill in the address'), required=False, default=util.toUnicode(details.get("address", "")) ) self.form.fields += Fields( first_name, last_name, phone_numbers, institution, position, from_country, from_city, address) if self.request.REQUEST_METHOD == 'POST': # save values if 'form.buttons.save' in self.request.form: prefix = 'form.widgets.' userid = self.request.form.get('form.widgets.userid') member = api.user.get(userid=userid) member.setMemberProperties(mapping={ "first_name": self.request.form.get( prefix + 'first_name'), "last_name": self.request.form.get( prefix + 'last_name'), "phone_numbers": self.request.form.get( prefix + 'phone_numbers').split("\r\n"), "institution": self.request.form.get( prefix + 'institution'), "position": self.request.form.get( prefix + 'position'), "from_country": self.request.form.get( prefix + 'from_country'), "from_city": self.request.form.get( prefix + 'from_city'), "address": self.request.form.get( prefix + 'address') })
def toWidgetValue(self, value): if value is self.field.missing_value: return u'' value = util.toUnicode(value) return value.replace('<br/>', '\r\n')