def changes_rss(self, num=10, REQUEST=None): """ Provide an RSS feed showing this wiki's recently edited pages. This is not the same as all recent edits. """ pages = self.pages(sort_on='last_edit_time', sort_order='reverse', sort_limit=num, isBoring=0) if len(pages) > 0: last_mod = pages[0].getObject().lastEditTime() else: last_mod = DateTime() if self.handle_modified_headers(last_mod=last_mod, REQUEST=REQUEST): return '' feedtitle = self.folder().title_or_id() + ' changed pages' feeddescription = feedtitle feedlanguage = 'en' feeddate = self.folder().bobobase_modification_time().rfc822() wikiurl = self.wikiUrl() REQUEST.RESPONSE.setHeader('Content-Type','text/xml; charset=utf-8') t = """\ <rss version="2.0"> <channel> <title>%(feedtitle)s</title> <link>%(feedurl)s</link> <description>%(feeddescription)s</description> <language>%(feedlanguage)s</language> <pubDate>%(feeddate)s</pubDate> """ % { 'feedtitle':self.title_quote(feedtitle), 'feeddescription':html_quote(feeddescription), 'feedurl':wikiurl, 'feedlanguage':feedlanguage, 'feeddate':feeddate, } for p in pages: pobj = p.getObject() t += """\ <item> <title>%(title)s</title> <link>%(wikiurl)s/%(id)s</link> <guid>%(wikiurl)s/%(id)s</guid> <description>%(last_log)s</description> <pubDate>%(last_edit_time)s</pubDate> </item> """ % { 'title':'[%s] %s' % (self.title_quote(p.Title),self.title_quote(p.last_log)), 'wikiurl':wikiurl, 'id':p.id, 'last_log':html_quote(pobj.textDiff()), 'last_edit_time':pobj.lastEditTime().rfc822(), # be robust here } t += """\ </channel> </rss> """ return t
def inputwidget(self, name, value=None, type_=None, class_=None, options=None, **kw): """ Return the input part as a chunk of HTML. Most cases it's just an <input /> tag but this can be different depending on the value of type_. For example, if type_=='textarea' return a <textarea> tags etc. """ unicode_encoding = kw.get('unicode_encoding', getattr(self, 'UNICODE_ENCODING', 'UTF-8')) # If the name passed to this function is 'title:latin1:ustring' # or 'price:float', create a new variable called name_full and change # the original variable name. name_full = name if name.find(':') > -1: name_full = name name = name_full.split(':')[0] if len(name_full.split(':')) == 2 and name_full.split(':')[1] in ('ustring','utext'): # lazy! You didn't include the encoding name_full = name_full.split(':')[0] + ':%s:' % unicode_encoding + name_full.split(':')[1] # special case magic which saves a lot of typing the template code if value is None: # assume that they mean the REQUEST object value = self.REQUEST if hasattr(value, 'has_key') and hasattr(value, 'get'): # this means that the actual value wasn't given to us. # We were given a dictionary which we can dig through # ourselfs. If we end up here, it's quite likely that the # user called inputwidget() like this: # here.inputwidget('first_name', request) if value.get(name) is not None: # I know this looks odd but it makes perfect sense :) value = value[name] else: # the variable wasn't available in this dictionary. The # default value will now depend on the type_ if type_ in (None, u'text', u'textarea', u'password', u'file', u'hidden'): # assume string value = '' elif type_ == 'checkbox': value = False elif type_ == 'radio': value = '' else: raise InputwidgetTypeError, \ "Invalid type_. Can't guess default value" # Now that we've fixed the value for the lazy people who just # send a dict we can do some ... # ...some basic validation if name.strip() != name: raise InputwidgetNameError, "Name not stripped" if not name.strip(): raise InputwidgetNameError, "Name blank" if type_ in (u'radio',): # the value can't be a list if isinstance(value, (list, tuple)): raise InputwidgetValueError, \ "For radio input you can't make the value a list" # you can't have a multiple parameter to these if kw.get('multiple'): raise InputwidgetTypeError, "Can't have multiple on type_ radio" # check that the type_ is a recognized one if type_ not in (None, u'text', u'password', u'file', u'hidden', u'radio', u'checkbox', u'textarea', u'select'): raise InputwidgetTypeError, "Unrecognized type_ option %r" % type_ ## ## Before we start rendering it, we might want to make things ## smoother by being clever. Hopefully the code speaks for itself. ## if not kw.has_key(u'size') and not options: if type_ in (None, 'text') and len(unicode(value)) < 5: if isinstance(value, (int, float)): kw[u'size'] = 5 if type_ == u'textarea': if not kw.has_key(u'rows'): kw[u'rows'] = 10 if not kw.has_key(u'cols'): kw[u'cols'] = 70 if type_ == u'checkbox': if niceboolean(value): value = "1" kw[u'checked'] = u'checked' else: value = "1" # Check for submiterrors error_message = '' if self.REQUEST.get('submiterrors', {}).get(name): class_ = u"inputerror" message = self.REQUEST.get('submiterrors').get(name) error_message = u'<span class="submiterror">%s</span><br/>'%\ html_quote(message) if class_ is not None: kw[u'class'] = class_ if kw.get(u'class') and isinstance(kw.get(u'class'), (list, tuple)): kw[u'class'] = ' '.join(kw[u'class']) # Decide and populate the right template if options and isinstance(options, (list, tuple)) and type_ not in ('radio','checkbox'): template = u'<select name="%(name)s" id="%(nameid)s" ' html = template % dict(name=name_full, nameid=self._name2nameID(name)) elif type_ == 'checkbox' and options and isinstance(options, (list, tuple)): html = '' elif type_ in (None, u'text', u'password', u'file', u'hidden', u'checkbox'): template = u'<input type="%(type)s" id="%(nameid)s" name="%(name)s" value="%(value)s" ' if type_ is None: type_ = u'text' html = template % dict(type=type_, name=name_full, value=value, nameid=self._name2nameID(name)) elif type_ == u'textarea': template = u'<textarea name="%(name)s" id="%(nameid)s" ' html = template % dict(name=name_full, nameid=self._name2nameID(name)) elif type_ == 'radio': html = '' if kw.get(u'pretext'): html = safe_unicode(kw.get(u'pretext')) + html kw.pop(u'pretext') if 'readonly' in kw: # to allow this to be None which can happen if you do this: # <td tal:content="structure python:here.inputwidget(..., # readonly=test(here.check_readonly())) if kw.get('readonly'): kw['readonly'] = 'readonly' else: del kw['readonly'] if type_ != 'radio': for key, value_ in kw.items(): if key.endswith('__'): # special continue if key == u'posttext': continue if key == 'multiple': value_ = 'multiple' html += u'%s="%s" ' % (key, value_) def isEqual(x, y): """ compare x and y and be aware of the careful_int_match__ """ if x == y: return True if kw.get('careful_int_match__'): try: return int(x) == int(y) except ValueError, TypeError: pass if kw.get('careful_float_match__'): try: return float(x) == float(y) except ValueError, TypeError: pass
pass if kw.get('careful_float_match__'): try: return float(x) in [float(e) for e in yyy] except ValueError, TypeError: pass return False # wrap up if type_ == u'textarea': html = html.strip()+ u'>' html += html_quote(value) html += u'</textarea>' elif type_ in ('radio','checkbox') and options and isinstance(options, (list, tuple)): c = 0 for option in options: valueid = self._name2nameID(name)+'_%s' % c c += 1 if isinstance(option, (tuple, list)): option, label = option elif isinstance(option, dict): option, label = option['key'], option['value'] else: option, label = option, option if isEqual(option, value): template = u'<input type="%(type_)s" name="%(name)s" id="%(valueid)s" value="%(value)s" checked="checked" '