comparison MoinMoin/items/__init__.py @ 1420:100197cb69ab

Convert Flatland forms to contain rendering hints. Form elements are now rendered using the polymorphic forms.render macro. Ref: http://dag-flatland.readthedocs.org/en/latest/patterns/widgets/
author Cheer Xiao <xiaqqaix@gmail.com>
date Fri, 06 Jul 2012 18:50:35 +0800
parents 94dda5c633d2
children 9f36555901db
comparison
equal deleted inserted replaced
1408:94dda5c633d2 1420:100197cb69ab
27 from flatland import Form, String, Integer, Boolean, Enum 27 from flatland import Form, String, Integer, Boolean, Enum
28 from flatland.validation import Validator, Present, IsEmail, ValueBetween, URLValidator, Converted 28 from flatland.validation import Validator, Present, IsEmail, ValueBetween, URLValidator, Converted
29 29
30 from whoosh.query import Term, And, Prefix 30 from whoosh.query import Term, And, Prefix
31 31
32 from MoinMoin.util.forms import FileStorage 32 from MoinMoin.forms import RequiredText, OptionalText, File, Submit
33 33
34 from MoinMoin.security.textcha import TextCha, TextChaizedForm, TextChaValid 34 from MoinMoin.security.textcha import TextCha, TextChaizedForm, TextChaValid
35 from MoinMoin.signalling import item_modified 35 from MoinMoin.signalling import item_modified
36 from MoinMoin.util.mimetype import MimeType 36 from MoinMoin.util.mimetype import MimeType
37 from MoinMoin.util.mime import Type, type_moin_document 37 from MoinMoin.util.mime import Type, type_moin_document
629 except: 629 except:
630 return self.note_error(element, state, 'invalid_json_msg') 630 return self.note_error(element, state, 'invalid_json_msg')
631 return True 631 return True
632 632
633 633
634 class BaseChangeForm(TextChaizedForm):
635 comment = OptionalText.using(label=L_('Comment')).with_properties(placeholder=L_("Comment about your change"))
636 submit = Submit
637
638
634 class Binary(Item): 639 class Binary(Item):
635 """ An arbitrary binary item, fallback class for every item mimetype. """ 640 """ An arbitrary binary item, fallback class for every item mimetype. """
636 modify_help = """\ 641 modify_help = """\
637 There is no help, you're doomed! 642 There is no help, you're doomed!
638 """ 643 """
657 terms.append(Term(CONTENTTYPE, contenttype)) 662 terms.append(Term(CONTENTTYPE, contenttype))
658 query = And(terms) 663 query = And(terms)
659 revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None) 664 revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
660 return [rev.meta[NAME] for rev in revs] 665 return [rev.meta[NAME] for rev in revs]
661 666
662 from MoinMoin.apps.frontend.views import CommentForm 667 class ModifyForm(BaseChangeForm):
663 class ModifyForm(CommentForm):
664 """Base class for ModifyForm of Binary's subclasses.""" 668 """Base class for ModifyForm of Binary's subclasses."""
665 meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)")).validated_by(ValidJSON()) 669 meta_text = RequiredText.with_properties(placeholder=L_("MetaData (JSON)")).validated_by(ValidJSON())
666 data_file = FileStorage.using(optional=True, label=L_('Upload file:')) 670 data_file = File.using(optional=True, label=L_('Upload file:'))
667 671
668 def _load(self, item): 672 def _load(self, item):
669 self['meta_text'] = item.meta_dict_to_text(item.prepare_meta_for_modify(item.meta)) 673 self['meta_text'] = item.meta_dict_to_text(item.prepare_meta_for_modify(item.meta))
670 674
671 def _dump(self, item): 675 def _dump(self, item):