Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

text: fix edit form

  • Loading branch information...
commit d40cc27bca397b07b4d2c18529ecdbb077a010eb 1 parent e2ae8f6
nicolasderam nicolasderam authored J. David Ibáñez committed

Showing 2 changed files with 19 additions and 13 deletions. Show diff stats Hide diff stats

  1. +2 1  text.py
  2. +17 12 text_views.py
3  text.py
@@ -32,6 +32,7 @@
32 32 from itools.xmlfile import XMLFile
33 33
34 34 # Import from ikaaro
  35 +from autoform import MultilineWidget
35 36 from database import Database
36 37 from file import File
37 38 from file_views import File_Edit
@@ -63,7 +64,7 @@ class Text(File):
63 64 class_icon48 = 'icons/48x48/text.png'
64 65 class_views = ['view', 'edit', 'externaledit', 'commit_log']
65 66 # Fields
66   - data = File.data(class_handler=TextFile)
  67 + data = File.data(class_handler=TextFile, widget=MultilineWidget)
67 68
68 69
69 70 def get_content_type(self):
29 text_views.py
@@ -23,12 +23,13 @@
23 23 # Import from itools
24 24 from itools.datatypes import Integer, String, Unicode
25 25 from itools.gettext import MSG
  26 +from itools.handlers import TextFile
26 27 from itools.web import STLView, INFO
27 28
28 29 # Import from ikaaro
29 30 from autoform import AutoForm, EditAreaWidget, get_default_widget
30 31 from buttons import Button, Remove_BrowseButton
31   -from fields import Textarea_Field
  32 +from fields import File_Field
32 33 from file_views import File_Edit
33 34 import messages
34 35 from views import BrowseForm
@@ -41,29 +42,32 @@ class Text_Edit(File_Edit):
41 42
42 43 fields = ['title', 'data', 'file', 'description', 'subject', 'share']
43 44
44   - data = Textarea_Field(title=MSG(u'Content'))
45   -
46 45
47 46 def get_value(self, resource, context, name, datatype):
48 47 if name == 'data':
49   - return resource.handler.to_str()
50   - return File_Edit.get_value(self, resource, context, name, datatype)
  48 + data = resource.get_value('data')
  49 + if data is None:
  50 + return ''
  51 + return data.to_str()
  52 + proxy = super(Text_Edit, self)
  53 + return proxy.get_value(resource, context, name, datatype)
51 54
52 55
53 56 def set_value(self, resource, context, name, form):
54 57 if name == 'data':
55 58 if form.get('file'):
56 59 return False
57   - handler = resource.handler
58   - old_value = handler.to_str()
59   - data = form['data']
60   - if old_value == data:
  60 + old_data = resource.get_value('data')
  61 + old_value = old_data.to_str()
  62 + value = form['data']
  63 + if old_value == value:
61 64 return False
62   - handler.load_state_from_string(data)
  65 + # Save new text
  66 + old_data.load_state_from_string(value)
63 67 context.database.change_resource(resource)
64 68 return False
65 69
66   - return File_Edit.set_value(self, resource, context, name, form)
  70 + return super(Text_Edit, self).set_value(resource, context, name, form)
67 71
68 72
69 73
@@ -88,7 +92,8 @@ class CSS_Edit(Text_Edit):
88 92
89 93 title = "Edit CSS file"
90 94
91   - data = Text_Edit.data(widget=EditAreaWidget)
  95 + data = File_Field(required=True, class_handler=TextFile,
  96 + widget=EditAreaWidget)
92 97
93 98
94 99

0 comments on commit d40cc27

Please sign in to comment.
Something went wrong with that request. Please try again.