def _renderTag(self, ctx, key, value, readonly): tag = T.invisible() ta = T.textarea(name=key, id=render_cssid(key), cols=self.cols, rows=self.rows)[value or ""] if readonly: ta(class_="readonly", readonly="readonly") tag[ta] if not readonly: try: import docutils except ImportError: raise else: form = iformal.IForm(ctx) srcId = render_cssid(key) previewDiv = render_cssid(key, "preview-div") frameId = render_cssid(key, "preview-frame") targetURL = widgetResourceURLFromContext(ctx, form.name).child(key).child(srcId) tag[T.br()] onclick = ["return Forms.Util.previewShow('", previewDiv, "', '", frameId, "', '", targetURL, "');"] tag[T.button(onclick=onclick)["Preview ..."]] tag[ T.div(id=previewDiv, class_="preview-hidden")[ T.iframe(class_="preview-frame", name=frameId, id=frameId), T.br(), T.button(onclick=["return Forms.Util.previewHide('", previewDiv, "');"])["Close"], ] ] return tag
def _renderTag(self, ctx, tparser, tvalue, namer, readonly): tag=T.invisible() if len(self.parsers) > 1: tp = T.select(name=namer('tparser'),id=render_cssid(namer('tparser'))) if readonly: tp(class_='disabled', disabled='disabled') for k,v in self.parsers: if k == tparser: tp[T.option(selected='selected',value=k)[ v ]] else: tp[T.option(value=k)[ v ]] else: tp = T.input(type='hidden',name=namer('tparser'),id=render_cssid(namer('tparser')),value=self.parsers[0][0]) tag[tp] if self.itemTypes is not None: tag[ T.input(type='hidden',class_="itemTypes",name=namer('itemTypes'),id=render_cssid(namer('itemTypes')),value=encodeTypes(self.itemTypes)) ] if self.itemTemplates is not None: tag[ T.input(type='hidden',class_="itemTemplates",name=namer('itemTemplates'),id=render_cssid(namer('itemTemplates')),value=','.join(self.itemTemplates)) ] ta=T.textarea(name=namer('tvalue'), id=render_cssid(namer('tvalue')), cols=self.cols, rows=self.rows)[tvalue or ''] if readonly: ta(class_='readonly', readonly='readonly') tag[ [T.br,ta ]] return tag
def renderImmutable(self, ctx, key, args, errors): values = ('', '') return [ T.input(type='password', name=key, id=render_cssid(key), value=values[0], class_='readonly', readonly='readonly'), T.br, T.label(for_=render_cssid(key, 'confirm'))[' Confirm '], T.input(type='password', name=key, id=render_cssid(key, 'confirm'), value=values[1], class_='readonly', readonly='readonly') ]
def render_field(self, ctx, data): # The field we're rendering field = self.field # Get stuff from the context formData = iformal.IFormData(ctx) formErrors = iformal.IFormErrors(ctx, None) # Find any error if formErrors is None: error = None else: error = formErrors.getFieldError(field.key) # Build the error message if error is None: message = '' else: message = T.div(class_='message')[error.message] # Create the widget (it's created in __init__ as a hack) widget = self.widget # Build the list of CSS classes classes = [ 'field', field.type.__class__.__name__.lower(), widget.__class__.__name__.lower(), ] if field.type.required: classes.append('required') if field.cssClass: classes.append(field.cssClass) if error: classes.append('error') # Create the widget and decide the method that should be called if field.type.immutable: render = widget.renderImmutable else: render = widget.render # Fill the slots tag = ctx.tag tag.fillSlots('id', util.render_cssid(field.key)) tag.fillSlots('fieldId', [util.render_cssid(field.key), '-field']) tag.fillSlots('class', ' '.join(classes)) tag.fillSlots('label', field.label) tag.fillSlots('inputs', render(ctx, field.key, formData, formErrors)) tag.fillSlots('message', message) tag.fillSlots('description', T.div(class_='description')[field.description or '']) return ctx.tag
def render(self, ctx, key, args, errors): if errors and not errors.getFieldError(key): values = args.get(key) else: values = ('', '') return [ T.input(type='password', name=key, id=render_cssid(key), value=values[0]), T.br, T.label(for_=render_cssid(key, 'confirm'))[' Confirm '], T.input(type='password', name=key, id=render_cssid(key, 'confirm'), value=values[1]), ]
def _renderTag(self, ctx, key, value, disabled): tag = T.input(type='checkbox', name=key, id=render_cssid(key), value='True') if value == 'True': tag(checked='checked') if disabled: tag(class_='disabled', disabled='disabled') return tag
def _renderTag(self, ctx, key, value, readonly): html = [] tag = T.textarea(name=key, id=render_cssid(key), cols=self.cols, rows=self.rows)[value or ''] if readonly: tag(class_='readonly', readonly='readonly') html.append(tag) if self.values is None: return html def renderOptions(ctx, options): for value, label in options: yield T.option(value=value)[label] selecttrigger = T.select(name='%s__selecttrigger' % key, data=self.values)[renderOptions] form = iformal.IForm(ctx) js = T.xml( "var x = document.getElementById('%(form)s');x.%(key)s.value += x.%(key)s__selecttrigger.options[x.%(key)s__selecttrigger.options.selectedIndex].value + "\\n";" % { 'key': key, 'form': form.name }) aonclick = T.a(onclick=js)['add'] html.append(T.div(class_="add")[selecttrigger, aonclick]) return html
def _renderTag(self, ctx, key, value, converter, disabled): def renderOptions(ctx, data): if self.noneOption is not None: yield T.option( value=iformal.IKey(self.noneOption).key())[iformal.ILabel( self.noneOption).label()] if data is None: return for item in data: optValue = iformal.IKey(item).key() optLabel = iformal.ILabel(item).label() optValue = converter.fromType(optValue) option = T.option(value=optValue)[optLabel] if value and optValue in value: option = option(selected='selected') yield option tag = T.select(name=key, id=render_cssid(key), data=self.options, multiple="multiple")[renderOptions] if disabled: tag(class_='disabled', disabled='disabled') return tag
def render_group(self, ctx, data): # Get a reference to the group, for simpler code. group = self.group # Build the CSS class string cssClass = ['group'] if group.cssClass is not None: cssClass.append(group.cssClass) cssClass = ' '.join(cssClass) # Fill the slots tag = ctx.tag tag.fillSlots('id', util.render_cssid(group.key)) tag.fillSlots('cssClass', cssClass) tag.fillSlots('label', group.label) tag.fillSlots('description', group.description or '') slots = [] for item in group.items: if (type(item) == list or type(item) == stan.Tag): slots.append(item) else: slots.append(inevow.IRenderer(item)) tag.fillSlots('items', slots) return ctx.tag
def _render(self, ctx, key, args, errors, immutable): charset = util.getPOSTCharset(ctx) converter = iformal.IStringConvertible(self.original) if errors: value = self._valueFromRequestArgs(charset, key, args) else: value = converter.fromType(args.get(key)) if value is None: value = iformal.IKey(self.noneOption).key() if immutable: template = inevow.IQ(self.template).onePattern('immutable') else: template = inevow.IQ(self.template).onePattern('editable') optionGen = template.patternGenerator('option') selectedOptionGen = template.patternGenerator('selectedOption') optionTags = [] selectOther = True if self.noneOption is not None: noneValue = iformal.IKey(self.noneOption).key() if value == noneValue: tag = selectedOptionGen() selectOther = False else: tag = optionGen() tag.fillSlots('value', noneValue) tag.fillSlots('label', iformal.ILabel(self.noneOption).label()) optionTags.append(tag) if self.options is not None: for item in self.options: if value == item: tag = selectedOptionGen() selectOther = False else: tag = optionGen() tag.fillSlots('value', item) tag.fillSlots('label', item) optionTags.append(tag) if selectOther: tag = selectedOptionGen() otherValue = value else: tag = optionGen() otherValue = '' tag.fillSlots('value', self.otherOption[0]) tag.fillSlots('label', self.otherOption[1]) optionTags.append(tag) tag = template tag.fillSlots('key', key) tag.fillSlots('id', render_cssid(key)) tag.fillSlots('options', optionTags) tag.fillSlots('otherValue', otherValue) return tag
def renderOption(ctx, itemKey, itemLabel, num, selected): cssid = render_cssid(key, num) tag = T.input(name=key, type='radio', id=cssid, value=itemKey) if selected: tag = tag(checked='checked') if disabled: tag = tag(disabled='disabled') return tag, ' ', T.label(for_=cssid)[itemLabel], T.br
def render(self, ctx, key, args, errors): if errors: value = args.get(key, ['']) if isinstance(value, list): value = value[0] else: value = iformal.IStringConvertible(self.original).fromType(args.get(key)) return T.input(type=self.inputType, name=key, id=render_cssid(key), value=value)
def _renderTag(self, ctx, key, value, readonly): tag = T.textarea(name=key, id=render_cssid(key), cols=self.cols, rows=self.rows)[value or ''] if readonly: tag(class_='readonly', readonly='readonly') return tag
def _renderTag(self, ctx, key, value, readonly): tag = T.input(type=self.inputType, name=key, id=render_cssid(key), value=value) if readonly: tag(class_='readonly', readonly='readonly') return tag
def render(self, ctx, key, args, errors): """ Render the data. This either renders a link to the original file, if specified, and no new file has been uploaded. Or a link to the uploaded file. The request to get the data should be routed to the getResouce method. """ form = iformal.IForm(ctx) namer = self._namer(key) resourceIdName = namer('resource_id') originalIdName = namer('original_id') # get the resource id first from the resource manager # then try the request resourceId = form.resourceManager.getResourceId(key) if resourceId is None: resourceId = self._getFromArgs(args, resourceIdName) resourceId = self._blankField(resourceId) # Get the original key from a hidden field in the request, # then try the request file.data initial data. originalKey = self._getFromArgs(args, originalIdName) if not errors and not originalKey: originalKey = args.get(key) originalKey = self._blankField(originalKey) if resourceId: # Have an uploaded file, so render a URL to the uploaded file tmpURL = widgetResourceURL(form.name).child(key).child( self.FROM_RESOURCE_MANAGER).child(resourceId) yield T.p[T.img(src=tmpURL)] elif originalKey: # The is no uploaded file, but there is an original, so render a # URL to it if self.originalKeyIsURL: tmpURL = originalKey else: tmpURL = widgetResourceURL(form.name).child(key).child( self.FROM_CONVERTIBLE).child(originalKey) yield T.p[T.img(src=tmpURL)] else: # No uploaded file, no original yield T.p[T.strong['Nothing uploaded']] yield T.input(name=key, id=render_cssid(key), type='file') # Id of uploaded file in the resource manager yield T.input(name=resourceIdName, value=resourceId, type='hidden') if originalKey: # key of the original that can be used to get a file later yield T.input(name=originalIdName, value=originalKey, type='hidden')
def render(self, ctx, key, args, errors): charset = util.getPOSTCharset(ctx) converter = iformal.IStringConvertible(self.original) if errors: value = self._valueFromRequestArgs(charset, key, args) else: value = converter.fromType(args.get(key)) if value is None: value = iformal.IKey(self.noneOption).key() optionGen = inevow.IQ(self.template).patternGenerator('option') selectedOptionGen = inevow.IQ(self.template).patternGenerator('selectedOption') optionTags = [] selectOther = True if self.noneOption is not None: noneValue = iformal.IKey(self.noneOption).key() if value == noneValue: tag = selectedOptionGen() selectOther = False else: tag = optionGen() tag.fillSlots('value', noneValue) tag.fillSlots('label', iformal.ILabel(self.noneOption).label()) optionTags.append(tag) if self.options is not None: for item in self.options: if value == item: tag = selectedOptionGen() selectOther = False else: tag = optionGen() tag.fillSlots('value', item) tag.fillSlots('label', item) optionTags.append(tag) if selectOther: tag = selectedOptionGen() otherValue = value else: tag = optionGen() otherValue = '' tag.fillSlots('value', self.otherOption[0]) tag.fillSlots('label', self.otherOption[1]) optionTags.append(tag) tag = T.invisible[self.template.load(ctx)] tag.fillSlots('key', key) tag.fillSlots('id', render_cssid(key)) tag.fillSlots('options', optionTags) tag.fillSlots('otherValue', otherValue) return tag
def _renderTag(self, ctx, tparser, tvalue, namer, readonly): tag=T.invisible() if len(self.parsers) > 1: tp = T.select(name=namer('tparser'),id=render_cssid(namer('tparser'))) if readonly: tp(class_='disabled', disabled='disabled') for k,v in self.parsers: if k == tparser: tp[T.option(selected='selected',value=k)[ v ]] else: tp[T.option(value=k)[ v ]] else: tp = T.input(type='hidden',name=namer('tparser'),id=render_cssid(namer('tparser')),value=self.parsers[0][0]) ta=T.textarea(name=namer('tvalue'), id=render_cssid(namer('tvalue')), cols=self.cols, rows=self.rows)[tvalue or ''] if readonly: ta(class_='readonly', readonly='readonly') tag[tp,T.br,ta] return tag
def render(self, ctx, key, args, errors): """ Render the data. This either renders a link to the original file, if specified, and no new file has been uploaded. Or a link to the uploaded file. The request to get the data should be routed to the getResouce method. """ form = iformal.IForm( ctx ) namer = self._namer( key ) resourceIdName = namer( 'resource_id' ) originalIdName = namer( 'original_id' ) # get the resource id first from the resource manager # then try the request resourceId = form.resourceManager.getResourceId( key ) if resourceId is None: resourceId = self._getFromArgs( args, resourceIdName ) resourceId = self._blankField( resourceId ) # Get the original key from a hidden field in the request, # then try the request file.data initial data. originalKey = self._getFromArgs( args, originalIdName ) if not errors and not originalKey: originalKey = args.get( key ) originalKey = self._blankField( originalKey ) if resourceId: # Have an uploaded file, so render a URL to the uploaded file tmpURL = widgetResourceURL(form.name).child(key).child( self.FROM_RESOURCE_MANAGER ).child(resourceId) yield T.p[T.img(src=tmpURL)] elif originalKey: # The is no uploaded file, but there is an original, so render a # URL to it if self.originalKeyIsURL: tmpURL = originalKey else: tmpURL = widgetResourceURL(form.name).child(key).child( self.FROM_CONVERTIBLE ).child( originalKey ) yield T.p[T.img(src=tmpURL)] else: # No uploaded file, no original yield T.p[T.strong['Nothing uploaded']] yield T.input(name=key, id=render_cssid(key),type='file') # Id of uploaded file in the resource manager yield T.input(name=resourceIdName,value=resourceId,type='hidden') if originalKey: # key of the original that can be used to get a file later yield T.input(name=originalIdName,value=originalKey,type='hidden')
def renderer(ctx, options): # loops through checkbox options and renders for n,item in enumerate(options): optValue = converter.fromType(iformal.IKey(item).key()) optLabel = iformal.ILabel(item).label() optid = render_cssid(key, n) checkbox = T.input(type='checkbox', name=key, value=optValue, id=optid) if optValue in values: checkbox = checkbox(checked='checked') if disabled: checkbox = checkbox(class_='disabled', disabled='disabled') yield checkbox, T.label(for_=optid)[optLabel], T.br()
def renderer(ctx, options): # loops through checkbox options and renders for n,item in enumerate(options): optValue = iformal.IKey(item).key() optLabel = iformal.ILabel(item).label() optValue = converter.fromType(optValue) optid = render_cssid(key, n) checkbox = T.input(type='checkbox', name=key, value=optValue, id=optid) if optValue in values: checkbox = checkbox(checked='checked') if disabled: checkbox = checkbox(class_='disabled', disabled='disabled') yield checkbox, T.label(for_=optid)[optLabel], T.br()
def _renderTag(self, ctx, key, values, converter, disabled): def renderOptions(ctx, options): # loops through checkbox options and renders for item in options: optValue = converter.fromType(iformal.IKey(item).key()) optLabel = iformal.ILabel(item).label() option = T.option(value=optValue)[optLabel] if optValue in values: option = option(selected='selected') yield option tag=T.select(name=key, id=render_cssid(key), data=self.options, multiple='multiple', size=self.size)[renderOptions] if disabled: tag(class_='disabled', disabled='disabled') return tag
def _renderTag(self, ctx, key, value, readonly): tag = T.invisible() ta = T.textarea(name=key, id=render_cssid(key), cols=self.cols, rows=self.rows)[value or ''] if readonly: ta(class_='readonly', readonly='readonly') tag[ta] if not readonly: try: import docutils except ImportError: raise else: form = iformal.IForm(ctx) srcId = render_cssid(key) previewDiv = render_cssid(key, 'preview-div') frameId = render_cssid(key, 'preview-frame') targetURL = widgetResourceURLFromContext( ctx, form.name).child(key).child(srcId) tag[T.br()] onclick = [ "return Forms.Util.previewShow('", previewDiv, "', '", frameId, "', '", targetURL, "');" ] tag[T.button(onclick=onclick)['Preview ...']] tag[T.div(id=previewDiv, class_="preview-hidden")[ T.iframe(class_="preview-frame", name=frameId, id=frameId), T.br(), T.button(onclick=[ "return Forms.Util.previewHide('", previewDiv, "');" ])['Close']]] return tag
def _renderTag(self, ctx, key, value, namer, disabled): name = self.fileHandler.getUrlForFile(value) if name: if self.preview == 'image': yield T.p[value,T.img(src=self.fileHandler.getUrlForFile(value))] else: yield T.p[value] else: yield T.p[T.strong['nothing uploaded']] yield T.input(name=namer('value'),value=value,type='hidden') tag=T.input(name=key, id=render_cssid(key),type='file') if disabled: tag(class_='disabled', disabled='disabled') yield tag
def render_group(self, ctx, data): group = self.group # Build the CSS class string cssClass = ['group', 'submit-group'] if group.cssClass is not None: cssClass.append(group.cssClass) cssClass = ' '.join(cssClass) # Fill the slots ctx.tag.fillSlots('id', util.render_cssid(group.key)) ctx.tag.fillSlots('cssClass', cssClass) items = [inevow.IRenderer(item) for item in group.items] items.append(T.span(_class='submit-group-clear')) ctx.tag.fillSlots('items', items) return ctx.tag
def render_group(self, ctx, data): # Get a reference to the group, for simpler code. group = self.group # Build the CSS class string cssClass = ['group'] if group.cssClass is not None: cssClass.append(group.cssClass) cssClass = ' '.join(cssClass) # Fill the slots ctx.tag.fillSlots('id', util.render_cssid(group.key)) ctx.tag.fillSlots('cssClass', cssClass) ctx.tag.fillSlots('label', group.label) ctx.tag.fillSlots('description', group.description or '') ctx.tag.fillSlots('items', [inevow.IRenderer(item) for item in group.items]) return ctx.tag
def _renderTag(self, ctx, key, value, converter, disabled): def renderOptions(ctx, data): if self.noneOption is not None: yield T.option(value=iformal.IKey(self.noneOption).key())[iformal.ILabel(self.noneOption).label()] if data is None: return for item in data: optValue = iformal.IKey(item).key() optLabel = iformal.ILabel(item).label() optValue = converter.fromType(optValue) option = T.option(value=optValue)[optLabel] if optValue == value: option = option(selected='selected') yield option tag=T.select(name=key, id=render_cssid(key), data=self.options)[renderOptions] if disabled: tag(class_='disabled', disabled='disabled') return tag
def _renderTag(self, ctx, key, value, readonly): html = [] tag=T.textarea(name=key, id=render_cssid(key), cols=self.cols, rows=self.rows)[value or ''] if readonly: tag(class_='readonly', readonly='readonly') html.append(tag) if self.values is None: return html def renderOptions(ctx,options): for value,label in options: yield T.option(value=value)[label] selecttrigger = T.select(name='%s__selecttrigger'%key, data=self.values)[ renderOptions ] form = iformal.IForm( ctx ) js = T.xml("var x = document.getElementById('%(form)s');x.%(key)s.value += x.%(key)s__selecttrigger.options[x.%(key)s__selecttrigger.options.selectedIndex].value + "\\n";"%{'key':key,'form':form.name}) aonclick = T.a(onclick=js)[ 'add' ] html.append(T.div(class_="add")[selecttrigger,aonclick]) return html
def render_group(self, ctx, data): group = self.group # Build the CSS class string cssClass = ['group'] if self.group.collapsible: cssClass.append('collapsible-group') if group.cssClass is not None: cssClass.append(group.cssClass) cssClass = ' '.join(cssClass) # Fill the slots ctx.tag.fillSlots('id', util.render_cssid(group.key)) ctx.tag.fillSlots('cssClass', cssClass) ctx.tag.fillSlots('label', group.label) ctx.tag.fillSlots('description', group.description or '') if self.group.summary is not None: ctx.tag.fillSlots('summary', self.group.summary) else: ctx.tag.fillSlots('summary', _default_summary_clicktoexpand) ctx.tag.fillSlots('items', [inevow.IRenderer(item) for item in group.items]) return ctx.tag
def _renderTag(self, ctx, key, disabled): tag=T.input(name=key, id=render_cssid(key),type='file') if disabled: tag(class_='disabled', disabled='disabled') return tag
def _renderTag(self, ctx, key, value, readonly): tag=T.input(type=self.inputType, name=key, id=render_cssid(key), value=value) if readonly: tag(class_='readonly', readonly='readonly') return tag
def _renderTag(self, ctx, key, value, readonly): tag=T.textarea(name=key, id=render_cssid(key), cols=self.cols, rows=self.rows)[value or ''] if readonly: tag(class_='readonly', readonly='readonly') return tag
def render(self, ctx, key, args, errors): """ Render the data. This either renders a link to the original file, if specified, and no new file has been uploaded. Or a link to the uploaded file. The request to get the data should be routed to the getResouce method. """ form = iformal.IForm( ctx ) namer = self._namer( key ) resourceIdName = namer( 'resource_id' ) originalIdName = namer( 'original_id' ) # get the resource id first from the resource manager # then try the request resourceId = form.resourceManager.getResourceId( key ) if resourceId is None: resourceId = self._getFromArgs( args, resourceIdName ) resourceId = self._blankField( resourceId ) # Get the original key from a hidden field in the request, # then try the request file.data initial data. originalKey = self._getFromArgs( args, originalIdName ) if not errors and not originalKey: originalKey = args.get( key ) originalKey = self._blankField( originalKey ) # if we have a removeable attribute, generate the html if self.removeable is True: checkbox = T.input(type='checkbox', name='%s_remove'%key, id=render_cssid('%s_remove'%key),class_='upload-checkbox-remove',value='remove') if args.get('%s_remove'%key, [None])[0] is not None: checkbox = checkbox = checkbox(checked='checked') removeableHtml = T.p[ 'check to remove', checkbox] else: removeableHtml = '' if resourceId: # Have an uploaded file, so render a link to the uploaded file tmpURL = widgetResourceURL(form.name).child(key).child( self.FROM_RESOURCE_MANAGER ).child(resourceId) value = form.resourceManager.getResourceForWidget( key ) yield [ T.p[T.a(href=tmpURL)[value[2]]], removeableHtml] elif originalKey: # The is no uploaded file, but there is an original, so render a # URL to it if self.originalKeyIsURL: tmpURL = originalKey yield [ T.p[T.img(src=tmpURL)], removeableHtml ] else: # Copy the data to the resource manager and render from there resourceId = self._storeInResourceManager(ctx, key, originalKey) tmpURL = widgetResourceURL(form.name).child(key).child( self.FROM_RESOURCE_MANAGER ).child(resourceId) yield [ T.p[T.a(href=tmpURL)[originalKey[2]]], removeableHtml] else: # No uploaded file, no original yield T.p[T.strong['Nothing uploaded']] yield T.input(name=key, id=render_cssid(key),type='file') # Id of uploaded file in the resource manager yield T.input(name=resourceIdName,value=resourceId,type='hidden') if originalKey and self.originalKeyIsURL: # key of the original that can be used to get a file later yield T.input(name=originalIdName,value=originalKey,type='hidden')
def _renderTag(self, ctx, key, disabled): tag = T.input(name=key, id=render_cssid(key), type='file') if disabled: tag(class_='disabled', disabled='disabled') return tag