comparison MoinMoin/items/__init__.py @ 1662:465b22852fae

Let Item subclasses handle +show.
author Cheer Xiao <xiaqqaix@gmail.com>
date Sun, 12 Aug 2012 15:14:07 +0800
parents 07b2146ba96f
children c7cc251e08bd
comparison
equal deleted inserted replaced
1652:64fe4e3c449b 1662:465b22852fae
24 from collections import namedtuple 24 from collections import namedtuple
25 from functools import partial 25 from functools import partial
26 26
27 from flatland import Form 27 from flatland import Form
28 from flatland.validation import Validator 28 from flatland.validation import Validator
29
30 from jinja2 import Markup
29 31
30 from whoosh.query import Term, And, Prefix 32 from whoosh.query import Term, And, Prefix
31 33
32 from MoinMoin.forms import RequiredText, OptionalText, JSON, Tags, Submit 34 from MoinMoin.forms import RequiredText, OptionalText, JSON, Tags, Submit
33 35
559 first_rev_id=rev_ids and rev_ids[0], 561 first_rev_id=rev_ids and rev_ids[0],
560 last_rev_id=rev_ids and rev_ids[-1], 562 last_rev_id=rev_ids and rev_ids[-1],
561 meta_rendered='', 563 meta_rendered='',
562 data_rendered='', 564 data_rendered='',
563 ) 565 )
566
567 def do_show(self, revid):
568 show_revision = revid != CURRENT
569 show_navigation = False # TODO
570 first_rev = last_rev = None # TODO
571 return render_template(self.show_template,
572 item=self, item_name=self.name,
573 rev=self.rev,
574 contenttype=self.contenttype,
575 first_rev_id=first_rev,
576 last_rev_id=last_rev,
577 data_rendered=Markup(self.content._render_data()),
578 show_revision=show_revision,
579 show_navigation=show_navigation,
580 )
564 581
565 def do_modify(self): 582 def do_modify(self):
566 method = request.method 583 method = request.method
567 if method == 'GET': 584 if method == 'GET':
568 if isinstance(self.content, NonExistentContent): 585 if isinstance(self.content, NonExistentContent):
605 rows_meta=str(ROWS_META), cols=str(COLS), 622 rows_meta=str(ROWS_META), cols=str(COLS),
606 form=form, 623 form=form,
607 search_form=None, 624 search_form=None,
608 ) 625 )
609 626
627 show_template = 'show.html'
610 modify_template = 'modify.html' 628 modify_template = 'modify.html'
611 629
612 630
613 @register 631 @register
614 class Ticket(Contentful): 632 class Ticket(Contentful):
635 """ 653 """
636 itemtype = u'nonexistent' 654 itemtype = u'nonexistent'
637 655
638 def _convert(self, doc): 656 def _convert(self, doc):
639 abort(404) 657 abort(404)
658
659 def do_show(self, revid):
660 # First, check if the current user has the required privileges
661 if not flaskg.user.may.create(self.name):
662 return render_template('show_nonexistent.html',
663 item_name=self.name,
664 )
665 return Response(self._select_itemtype(), 404)
640 666
641 def do_modify(self): 667 def do_modify(self):
642 # First, check if the current user has the required privileges 668 # First, check if the current user has the required privileges
643 if not flaskg.user.may.create(self.name): 669 if not flaskg.user.may.create(self.name):
644 abort(403) 670 abort(403)
645 671 return self._select_itemtype()
672
673 def _select_itemtype(self):
646 # TODO Construct this list from the item_registry. Two more fields (ie. 674 # TODO Construct this list from the item_registry. Two more fields (ie.
647 # display name and description) are needed in the registry then to 675 # display name and description) are needed in the registry then to
648 # support the automatic construction. 676 # support the automatic construction.
649 ITEMTYPES = [ 677 ITEMTYPES = [
650 (u'default', u'Default', 'Wiki item'), 678 (u'default', u'Default', 'Wiki item'),