def applicationNavigation(ctx, translator, navigation): """ Horizontal, primary-only navigation view. For the navigation element currently being viewed, copies of the I{selected-app-tab} and I{selected-tab-contents} patterns will be loaded from the tag. For all other navigation elements, copies of the I{app-tab} and I{tab-contents} patterns will be loaded. For either case, the former pattern will have its I{name} slot filled with the name of the navigation element and its I{tab-contents} slot filled with the latter pattern. The latter pattern will have its I{href} slot filled with a link to the corresponding navigation element. The I{tabs} slot on the tag will be filled with all the I{selected-app-tab} or I{app-tab} pattern copies. @type ctx: L{nevow.context.WebContext} @type translator: L{IWebTranslator} provider @type navigation: L{list} of L{Tab} @rtype: {nevow.stan.Tag} """ setTabURLs(navigation, translator) selectedTab = getSelectedTab(navigation, url.URL.fromContext(ctx)) getp = IQ(ctx.tag).onePattern tabs = [] for tab in navigation: if tab == selectedTab or selectedTab in tab.children: p = 'selected-app-tab' contentp = 'selected-tab-contents' else: p = 'app-tab' contentp = 'tab-contents' childTabs = [] for subtab in tab.children: try: subtabp = getp("subtab") except NodeNotFound: continue childTabs.append( dictFillSlots(subtabp, { 'name': subtab.name, 'href': subtab.linkURL, 'tab-contents': getp("subtab-contents") })) tabs.append(dictFillSlots( getp(p), {'name': tab.name, 'tab-contents': getp(contentp).fillSlots( 'href', tab.linkURL), 'subtabs': childTabs})) ctx.tag.fillSlots('tabs', tabs) return ctx.tag
def form(self, request, tag): """ Render the inputs for a form. @param tag: A tag with: - I{form} and I{description} slots - I{liveform} and I{subform} patterns, to fill the I{form} slot - An I{inputs} slot, to fill with parameter views - L{IParameterView.patternName}I{-input-container} patterns for each parameter type in C{self.parameters} """ patterns = PatternDictionary(self.docFactory) inputs = [] for parameter in self.parameters: view = parameter.viewFactory(parameter, None) if view is not None: view.setDefaultTemplate( tag.onePattern(view.patternName + '-input-container')) setFragmentParent = getattr(view, 'setFragmentParent', None) if setFragmentParent is not None: setFragmentParent(self) inputs.append(view) else: inputs.append(_legacySpecialCases(self, patterns, parameter)) if self.subFormName is None: pattern = tag.onePattern('liveform') else: pattern = tag.onePattern('subform') return dictFillSlots( tag, dict(form=pattern.fillSlots('inputs', inputs), description=self._getDescription()))
def fillSlots(tabs): for tab in tabs: if tab.children: kids = getp('subtabs').fillSlots('kids', fillSlots(tab.children)) else: kids = '' yield dictFillSlots( getp('tab'), dict(href=tab.linkURL, name=tab.name, kids=kids))
def fillSlots(tabs): for tab in tabs: if tab.children: kids = getp('subtabs').fillSlots('kids', fillSlots(tab.children)) else: kids = '' yield dictFillSlots(getp('tab'), dict(href=tab.linkURL, name=tab.name, kids=kids))
def _legacySpecialCases(form, patterns, parameter): """ Create a view object for the given parameter. This function implements the remaining view construction logic which has not yet been converted to the C{viewFactory}-style expressed in L{_LiveFormMixin.form}. @type form: L{_LiveFormMixin} @param form: The form fragment which contains the given parameter. @type patterns: L{PatternDictionary} @type parameter: L{Parameter}, L{ChoiceParameter}, or L{ListParameter}. """ p = patterns[parameter.type + '-input-container'] if parameter.type == TEXTAREA_INPUT: p = dictFillSlots(p, dict(label=parameter.label, name=parameter.name, value=parameter.default or '')) elif parameter.type == MULTI_TEXT_INPUT: subInputs = list() for i in xrange(parameter.count): subInputs.append(dictFillSlots(patterns['input'], dict(name=parameter.name + '_' + str(i), type='text', value=parameter.defaults[i]))) p = dictFillSlots(p, dict(label=parameter.label or parameter.name, inputs=subInputs)) else: if parameter.default is not None: value = parameter.default else: value = '' if parameter.type == CHECKBOX_INPUT and parameter.default: inputPattern = 'checked-checkbox-input' else: inputPattern = 'input' p = dictFillSlots( p, dict(label=parameter.label or parameter.name, input=dictFillSlots(patterns[inputPattern], dict(name=parameter.name, type=parameter.type, value=value)))) p(**{'class' : 'liveform_'+parameter.name}) if parameter.description: description = patterns['description'].fillSlots( 'description', parameter.description) else: description = '' return dictFillSlots( patterns['parameter-input'], dict(input=p, description=description))
def viewPane(self, request, tag): attrs = tag.attributes iq = inevow.IQ(self.docFactory) if "open" in attrs: paneBodyPattern = "open-pane-body" else: paneBodyPattern = "pane-body" paneBodyPattern = iq.onePattern(paneBodyPattern) return dictFillSlots( iq.onePattern("view-pane"), {"name": attrs["name"], "pane-body": paneBodyPattern.fillSlots("renderer", T.directive(attrs["renderer"]))}, )
def constructRows(self, modelData): rowPattern = self.patterns['row'] cellPattern = self.patterns['cell'] for idx, row in enumerate(modelData): cells = [] for cview in self.columnViews: value = row.get(cview.attributeID) cellContents = cview.stanFromValue( idx, row['__item__'], value) if hasattr(cellContents, 'setFragmentParent'): cellContents.setFragmentParent(self) handler = cview.onclick(idx, row['__item__'], value) cellStan = dictFillSlots(cellPattern, {'value': cellContents, 'onclick': handler, 'class': cview.typeHint}) cells.append(cellStan) yield dictFillSlots(rowPattern, {'cells': cells, 'class': 'tdb-row-%s' % (idx,)})
def viewPane(self, request, tag): attrs = tag.attributes iq = inevow.IQ(self.docFactory) if 'open' in attrs: paneBodyPattern = 'open-pane-body' else: paneBodyPattern = 'pane-body' paneBodyPattern = iq.onePattern(paneBodyPattern) return dictFillSlots(iq.onePattern('view-pane'), {'name': attrs['name'], 'pane-body': paneBodyPattern.fillSlots( 'renderer', T.directive(attrs['renderer']))})
def render_compose(self, ctx, data): """ Only fill in the C{from} and C{message-body} slots with anything useful - the stuff that L{ComposeFragment} puts in the rest of slots will be apparent from the L{MessageDetail} fragment we put in C{message-body} """ return dictFillSlots(ctx.tag, {'to': '', 'from': self._formatFromAddressSelection(self._getFromAddresses()), 'subject': '', 'message-body': self._getMessageBody(), 'cc': '', 'bcc': '', 'attachments': ''})
def render_compose(self, ctx, data): iq = inevow.IQ(self.docFactory) bodyPattern = iq.onePattern('message-body') subjectPattern = iq.onePattern('subject') attachmentPattern = iq.patternGenerator('attachment') slotData = self.slotData() slotData['from'] = self._formatFromAddressSelection(slotData['from']) slotData['subject'] = subjectPattern.fillSlots('subject', slotData['subject']) slotData['message-body'] = bodyPattern.fillSlots('body', slotData['message-body']) slotData['attachments'] = [ attachmentPattern.fillSlots('id', d['id']).fillSlots('name', d['name'] or 'No Name') for d in slotData['attachments']] return dictFillSlots(ctx.tag, slotData)
def _currentPage(self): patterns = PatternDictionary(self.docFactory) self.items = list(d['__item__'] for d in self.tdm.currentPage()) lastMessageID = None imageClasses = itertools.cycle(('gallery-image', 'gallery-image-alt')) if 0 < len(self.items): for (i, image) in enumerate(self.items): if 0 < i and i % self.itemsPerRow == 0: yield patterns['row-separator']() message = image.message if message.storeID != lastMessageID: imageClass = imageClasses.next() lastMessageID = message.storeID imageURL = (self.translator.linkTo(message.storeID) + '/attachments/' + self.translator.toWebID(image.part) + '/' + image.part.getFilename()) thumbURL = '/private/thumbnails/' + self.translator.toWebID( image) person = self.organizer.personByEmailAddress(message.sender) if person is None: personStan = SenderPersonFragment(message) else: personStan = people.PersonFragment(person) personStan.page = self.page yield dictFillSlots( patterns['image'], { 'image-url': imageURL, 'thumb-url': thumbURL, 'message-url': self.translator.linkTo(message.storeID), 'message-subject': message.subject, 'sender-stan': personStan, 'class': imageClass }) else: yield patterns['no-images']()
def _currentPage(self): patterns = PatternDictionary(self.docFactory) self.items = list(d['__item__'] for d in self.tdm.currentPage()) lastMessageID = None imageClasses = itertools.cycle(('gallery-image', 'gallery-image-alt')) if 0 < len(self.items): for (i, image) in enumerate(self.items): if 0 < i and i % self.itemsPerRow == 0: yield patterns['row-separator']() message = image.message if message.storeID != lastMessageID: imageClass = imageClasses.next() lastMessageID = message.storeID imageURL = (self.translator.linkTo(message.storeID) + '/attachments/' + self.translator.toWebID(image.part) + '/' + image.part.getFilename()) thumbURL = '/private/thumbnails/' + self.translator.toWebID(image) person = self.organizer.personByEmailAddress(message.sender) if person is None: personStan = SenderPersonFragment(message) else: personStan = people.PersonFragment(person) personStan.page = self.page yield dictFillSlots(patterns['image'], {'image-url': imageURL, 'thumb-url': thumbURL, 'message-url': self.translator.linkTo(message.storeID), 'message-subject': message.subject, 'sender-stan': personStan, 'class': imageClass}) else: yield patterns['no-images']()
def render_messages(self, *junk): iq = inevow.IQ(self.docFactory) msgpatt = iq.patternGenerator('message') newpatt = iq.patternGenerator('unread-message') content = [] addresses = set(self.person.store.query( people.EmailAddress, people.EmailAddress.person == self.person).getColumn('address')) wt = ixmantissa.IWebTranslator(self.person.store) link = lambda href, text: tags.a(href=href, style='display: block')[text] displayName = self.person.getDisplayName() for m in self.messageLister.mostRecentMessages(self.person): if m.sender in addresses: sender = displayName else: sender = 'Me' if m.read: patt = msgpatt else: patt = newpatt if not m.subject or m.subject.isspace(): subject = '<no subject>' else: subject = m.subject url = wt.linkTo(m.storeID) content.append(dictFillSlots(patt, dict(sender=link(url, sender), subject=link(url, subject), date=link(url, m.receivedWhen.asHumanly())))) if 0 < len(content): return iq.onePattern('messages').fillSlots('messages', content) return iq.onePattern('no-messages')
def render_senderPerson(self, ctx, data): return dictFillSlots( ctx.tag, dict(name=self.email.anyDisplayName(), identifier=self.email.email))
def applicationNavigation(ctx, translator, navigation): """ Horizontal, primary-only navigation view. For the navigation element currently being viewed, copies of the I{selected-app-tab} and I{selected-tab-contents} patterns will be loaded from the tag. For all other navigation elements, copies of the I{app-tab} and I{tab-contents} patterns will be loaded. For either case, the former pattern will have its I{name} slot filled with the name of the navigation element and its I{tab-contents} slot filled with the latter pattern. The latter pattern will have its I{href} slot filled with a link to the corresponding navigation element. The I{tabs} slot on the tag will be filled with all the I{selected-app-tab} or I{app-tab} pattern copies. @type ctx: L{nevow.context.WebContext} @type translator: L{IWebTranslator} provider @type navigation: L{list} of L{Tab} @rtype: {nevow.stan.Tag} """ setTabURLs(navigation, translator) selectedTab = getSelectedTab(navigation, url.URL.fromContext(ctx)) getp = IQ(ctx.tag).onePattern tabs = [] for tab in navigation: if tab == selectedTab or selectedTab in tab.children: p = 'selected-app-tab' contentp = 'selected-tab-contents' else: p = 'app-tab' contentp = 'tab-contents' childTabs = [] for subtab in tab.children: try: subtabp = getp("subtab") except NodeNotFound: continue childTabs.append( dictFillSlots( subtabp, { 'name': subtab.name, 'href': subtab.linkURL, 'tab-contents': getp("subtab-contents") })) tabs.append( dictFillSlots( getp(p), { 'name': tab.name, 'tab-contents': getp(contentp).fillSlots( 'href', tab.linkURL), 'subtabs': childTabs })) ctx.tag.fillSlots('tabs', tabs) return ctx.tag
def _legacySpecialCases(form, patterns, parameter): """ Create a view object for the given parameter. This function implements the remaining view construction logic which has not yet been converted to the C{viewFactory}-style expressed in L{_LiveFormMixin.form}. @type form: L{_LiveFormMixin} @param form: The form fragment which contains the given parameter. @type patterns: L{PatternDictionary} @type parameter: L{Parameter}, L{ChoiceParameter}, or L{ListParameter}. """ p = patterns[parameter.type + '-input-container'] if parameter.type == TEXTAREA_INPUT: p = dictFillSlots( p, dict(label=parameter.label, name=parameter.name, value=parameter.default or '')) elif parameter.type == MULTI_TEXT_INPUT: subInputs = list() for i in xrange(parameter.count): subInputs.append( dictFillSlots( patterns['input'], dict(name=parameter.name + '_' + str(i), type='text', value=parameter.defaults[i]))) p = dictFillSlots( p, dict(label=parameter.label or parameter.name, inputs=subInputs)) else: if parameter.default is not None: value = parameter.default else: value = '' if parameter.type == CHECKBOX_INPUT and parameter.default: inputPattern = 'checked-checkbox-input' else: inputPattern = 'input' p = dictFillSlots( p, dict(label=parameter.label or parameter.name, input=dictFillSlots( patterns[inputPattern], dict(name=parameter.name, type=parameter.type, value=value)))) p(**{'class': 'liveform_' + parameter.name}) if parameter.description: description = patterns['description'].fillSlots( 'description', parameter.description) else: description = '' return dictFillSlots(patterns['parameter-input'], dict(input=p, description=description))