20110622

watch_tim now logs changes

watch_tim ruft jetzt lino.utils.dblogger.log_changes(). Dadurch kann man in den log-Dateien nun sehen, was er verändert hat. Statt bisher nur der Zusammenfassung “5 changes have been processed.” Checkin-Serie 20110622.

appy.pod and enumerations

Gaëtan has solved the lists in “do text from xhtml()” problem. In works on my computer, but when trying it at the customer’s site I saw another problem:

Error while evaluating the expression "html(self.body)" defined in the "from" part of a statement.
File "<string>", line 1, in <module>
File "/var/snapshots/lino/lino/utils/appy_pod.py", line 63, in html_func
return renderer.renderXhtml(html,**kw)
File "/var/snapshots/appy-current/appy/pod/renderer.py", line 238, in renderXhtml
stylesMapping, ns).run()
File "/var/snapshots/appy-current/appy/pod/xhtml2odt.py", line 493, in run
self.xhtmlParser.parse(self.xhtmlString)
File "/var/snapshots/appy-current/appy/shared/xml_parser.py", line 195, in parse
self.parser.parse(inputSource)
File "/usr/lib/python2.6/xml/sax/expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
File "/usr/lib/python2.6/xml/sax/xmlreader.py", line 123, in parse
self.feed(buffer)
File "/usr/lib/python2.6/xml/sax/expatreader.py", line 211, in feed
self._err_handler.fatalError(exc)
File "/usr/lib/python2.6/xml/sax/handler.py", line 38, in fatalError
raise exception
<class 'xml.sax._exceptions.SAXParseException'>: <unknown>:1:1: not well-formed (invalid token)

Here now also a more elegant trick to see the xml fragment that causes the problem. In appy/shared/xml_parser.py I wrapped the self.parser.parse(inputSource) call into an Exception handler that logs the fragment to the dblogger and then re-raises:

try:
    self.parser.parse(inputSource)
except Exception,e:
    from lino.utils import dblogger
    dblogger.info("Exception while parsing:-----\n%r\n-----",xml)
    raise

This creates the following log entry in the above case:

201106-22 10:22:44 INFO xml_parser : Exception while parsing:-----
u'<p><p>In Notizen haben wir jetzt den <strong>WYSIWYG-Editor</strong>.</p>\n<p>Aufz\xe4hlungen sind m\xf6glich:</p>\n<u
l>\n<li>erstens</li>\n<li>zweitens</li>\n<li>und drittens.\xa0</li>\n</ul>\n<p>Man kann nicht nur <strong>fett</strong>,
 sondern auch <em>kursiv </em>(italic) und <span style="text-decoration: underline;">unterstrichen</span> schreiben.</p>
\n<p>\xa0</p></p>'
-----

Explanation: some versions of expat parsers don’t like unicode strings. Always encode them. Solution is to have Lino’s html() template function in lino.utils.appy_pod do this:

if isinstance(html,unicode):
    html = html.encode('utf-8')

We simply hardcode UTF-8 because appy.pod currently doesn’t support anything else.

Derek Dahmer posted a similar problem on stackoverflow

Checkin 20110622b.

DoesNotExist at /api/uploads/Uploads

There was a problem when the owner of an upload no longer exists. Deleting a Person obviously does not also delete her uploads, and neither does Lino refuse to delete the Person. Probably because it is a GenericForeignKey. But worse: the server afterwards caused an exception when we wanted to display a list of all uploads. This is fixed. And the fields Upload.owner_type and Upload.owner_id are now editable again so that users can manually repair such cases.

Kleinkram

  • persons_by_user kleine Optimierungen
  • Person.get_property
  • Funktion iif in AppyBuildMethod

Checkin 20110622d.