One bug less

The following traceback happened when user left the job field of a contract empty:

File "l:\snapshots\django\django\core\handlers\base.py", line 111, in get_response
  response = callback(request, *callback_args, **callback_kwargs)

File "t:\hgwork\lino\lino\ui\extjs3\ext_ui.py", line 983, in api_list_view
  return self.form2obj_and_save(request,rh,request.POST,instance,True)

File "t:\hgwork\lino\lino\ui\extjs3\ext_ui.py", line 855, in form2obj_and_save

File "t:\hgwork\lino\lino\modlib\jobs\models.py", line 417, in full_clean
  self.hourly_rate = self.job.hourly_rate

File "l:\snapshots\django\django\db\models\fields\related.py", line 302, in __get__
  raise self.field.rel.to.DoesNotExist

UnicodeError while saving uploaded files with non-ascii chars

I continued the work started 2 weeks ago for the (d) UnicodeEncodeError at /api/uploads/UploadsByOwner.

Here is again our traceback:

File "/var/snapshots/django/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/var/snapshots/lino/lino/ui/extjs3/ext_ui.py" in api_list_view
  982.                 rh.report.handle_uploaded_files(request,instance)
File "/var/snapshots/lino/lino/reports.py" in f
  715.         return m(obj,request)
File "/var/snapshots/lino/lino/mixins/uploadable.py" in handle_uploaded_files
  85.         ff.save(uf.name,uf,save=False)
File "/var/snapshots/django/django/db/models/fields/files.py" in save
  90.         self.name = self.storage.save(name, content)
File "/var/snapshots/django/django/core/files/storage.py" in save
  48.         name = self.get_available_name(name)
File "/var/snapshots/django/django/core/files/storage.py" in get_available_name
  74.         while self.exists(name):
File "/var/snapshots/django/django/core/files/storage.py" in exists
  233.         return os.path.exists(self.path(name))
File "/usr/lib/python2.6/genericpath.py" in exists
  18.         st = os.stat(path)


One problem is that Django doesn’t recognize our POST request as is_ajax and thus the traceback is difficult to see.

Tried to add a headers: { 'HTTP_X_REQUESTED_WITH' : 'XMLHttpRequest'} to the panel.form.submit() call… without success. But okay, let’s concentrate on the error itself.

Here is again some code that tries to reproduce the effect:

import os
from django.utils._os import safe_join

fn = u'\xfc'
fn = safe_join('foo',fn)
fn = os.path.normpath(fn)
print repr(fn)
print os.path.exists(fn)
print os.stat(fn)

Result: negative. This code runs without problem. Hm…

New feature “out-of-the-box doctemplates”

Opened ticket docs/tickets/46 because this was not trivial and I thought to let this ticket wait until real need grows. Later I changed my mind and did it right now.

The only but important advantage of this change is that Lino applications can now provide “default templates”.

I removed EditTemplateAction : this functionality anyway didnt work yet, and now it would be even more difficult to implement this feature.

When upgrading, the local doctemplates directory needs to be moved from media/webdav to config. Add a symbolic link to it in the webdav directory for keeping the files editable through webdav. And then it must also get a structure lifting:

  • rename directories contracts to jobs.Contact, notes to notes.Note and persons to contact.Person.

  • Instead of one directory per language I opted for the foo_xx.odt solution: If a template foo.odt exists, then a file foo_fr.odt means “the french version of foo.odt”. Note that the default template foo.odt must exist, otherwise Lino will consider a file foo_fr.odt itself a default template.

Check-in wegen Feierabend.