set form fields manually.

svn path=/plone.app.discussion/trunk/; revision=28325
This commit is contained in:
Timo Stollenwerk 2009-08-02 17:32:41 +00:00
parent 424d1c79ed
commit 2e2f6fc690
2 changed files with 12 additions and 36 deletions

View File

@ -56,6 +56,7 @@ from plone.z3cform.fieldsets import extensible
from Products.Five.browser import BrowserView from Products.Five.browser import BrowserView
from zope.schema.fieldproperty import FieldProperty
class View(BrowserView): class View(BrowserView):
"""Comment View """Comment View
@ -72,8 +73,8 @@ class View(BrowserView):
class Comment(object): class Comment(object):
implements(IComment, IAttributeAnnotatable) implements(IComment, IAttributeAnnotatable)
portal_type = u"" portal_type = u""
#__parent__ = u"" __parent__ = None
#__name__ = u"" __name__ = None
comment_id = u"" comment_id = u""
in_reply_to = u"" in_reply_to = u""
title = u"" title = u""
@ -87,39 +88,20 @@ class Comment(object):
author_email = u"" author_email = u""
class CommentForm(extensible.ExtensibleForm, form.Form): class CommentForm(extensible.ExtensibleForm, form.Form):
fields = field.Fields(IComment)
ignoreContext = True # don't use context to get widget data ignoreContext = True # don't use context to get widget data
label = u"Add a comment" label = u"Add a comment"
# NOT WORKING !!!
name = "foooooo"
method = "get"
action = "foo"
# hide certain fields
#fields['__parent__'].mode = interfaces.HIDDEN_MODE
#fields['__name__'].mode = interfaces.HIDDEN_MODE
fields['portal_type'].mode = interfaces.HIDDEN_MODE
fields['comment_id'].mode = interfaces.HIDDEN_MODE
fields['in_reply_to'].mode = interfaces.HIDDEN_MODE
fields['mime_type'].mode = interfaces.HIDDEN_MODE
fields['creator'].mode = interfaces.HIDDEN_MODE
fields['creation_date'].mode = interfaces.HIDDEN_MODE
fields['modification_date'].mode = interfaces.HIDDEN_MODE
fields['author_username'].mode = interfaces.HIDDEN_MODE
fields['author_name'].mode = interfaces.HIDDEN_MODE
fields['author_email'].mode = interfaces.HIDDEN_MODE
@button.buttonAndHandler(u'Post comment') @button.buttonAndHandler(u'Post comment')
def handleApply(self, action): def handleApply(self, action):
data, errors = self.extractData() data, errors = self.extractData()
print data['title'] # ... or do stuff print data['title'] # ... or do stuff
@property
#@property def fields(self):
#def fields(self): title = FieldProperty(IComment['title'])
# TODO !!! text = FieldProperty(IComment['text'])
# return fields return field.Fields(title, text)
class ViewletFormWrapper(ViewletBase, layout.FormWrapper): class ViewletFormWrapper(ViewletBase, layout.FormWrapper):
@ -127,8 +109,7 @@ class ViewletFormWrapper(ViewletBase, layout.FormWrapper):
form = CommentForm form = CommentForm
label = 'Add Comment' label = 'Add Comment'
name = 'foo'
formname = 'bar'
index = ViewPageTemplateFile('comments.pt') index = ViewPageTemplateFile('comments.pt')
#def index(self): #def index(self):
@ -154,11 +135,6 @@ class ViewletFormWrapper(ViewletBase, layout.FormWrapper):
def render_form(self): def render_form(self):
#z2.switch_on(self, request_layer=self.request_layer) #z2.switch_on(self, request_layer=self.request_layer)
# XXX: NOT WORKING !!!
self.form_instance.formname = "foo"
self.form_instance.name = "foooooo"
self.form_instance.method = "get"
self.form_instance.action = "foo"
self.form.update(self.form_instance) self.form.update(self.form_instance)
return self.form.render(self.form_instance) return self.form.render(self.form_instance)
#return self.form_instance() #return self.form_instance()

View File

@ -133,8 +133,8 @@ class IComment(Interface):
portal_type = schema.ASCIILine(title=_(u"Portal type"), default="Discussion Item") portal_type = schema.ASCIILine(title=_(u"Portal type"), default="Discussion Item")
#__parent__ = schema.Object(title=_(u"Conversation"), schema=Interface) __parent__ = schema.Object(title=_(u"Conversation"), schema=Interface)
#__name__ = schema.TextLine(title=_(u"Name")) __name__ = schema.TextLine(title=_(u"Name"))
comment_id = schema.Int(title=_(u"A comment id unique to this conversation")) comment_id = schema.Int(title=_(u"A comment id unique to this conversation"))
in_reply_to = schema.Int(title=_(u"Id of comment this comment is in reply to"), required=False) in_reply_to = schema.Int(title=_(u"Id of comment this comment is in reply to"), required=False)