Alessandro Molina avatar Alessandro Molina committed e25999a

This should improve compatibility with TW2

Comments (0)

Files changed (1)


     from tw2.forms import FileField
     from formencode.validators import FieldStorageUploadConverter
+    from tw2.core import Deferred
 except ImportError:
     from tw.forms import FileField
     from tw.forms.validators import FieldStorageUploadConverter
+    def Deferred(f):
+        return f
 from tgext.datahelpers.validators import SQLAEntityConverter
 from tgext.pluggable import plug_url, primary_key, app_model
 from webhelpers import html
+def _get_current_user():
+    return getattr(request.identity['user'], primary_key(app_model.User).key)
 class PhotosController(EasyCrudRestController):
     allow_only = predicates.in_group('photos')
     title = "Manage Photos"
         '__hide_fields__' : ['uid', 'author', 'gallery'],
         '__field_widget_types__' : {'image':FileField},
         '__field_validator_types__' : {'image':FieldStorageUploadConverter},
-        '__field_widget_args__' : {'author':{'default':lambda:getattr(request.identity['user'],
-                                                                      primary_key(app_model.User).key)}}
+        '__field_widget_args__' : {'author':{'default':_get_current_user,
+                                             'value':Deferred(_get_current_user)}}
     __table_options__ = {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.