Changeset 3855 for waeup/branches/ulif-rewrite/src
- Timestamp:
- 16 Jan 2009, 12:28:18 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/app.py
r3832 r3855 1 1 import grok 2 from grok import index 3 from zope.component import getUtility 2 import re 3 from zope.component import getUtility, getMultiAdapter 4 4 from zope.interface import Interface 5 5 6 6 from waeup.interfaces import (IUniversity, IStudentContainer, IHostelContainer, 7 7 IFacultyContainer) 8 from waeup.viewlets import MainArea 8 from waeup.viewlets import MainArea, LeftSidebar, Index, Manage 9 9 10 10 class University(grok.Application, grok.Container): … … 13 13 grok.implements(IUniversity) 14 14 15 def __init__(self, name=u' Unnamed', **kw):15 def __init__(self, name=u'Sample University', **kw): 16 16 super(University, self).__init__(**kw) 17 17 self.name = name … … 22 22 self["hostels"] = getUtility(IHostelContainer) 23 23 self["faculties"] = getUtility(IFacultyContainer) 24 24 25 25 class Manage(grok.EditForm): 26 27 class ManageForm(grok.EditForm): 26 28 """Manage the basic properties of a `University` instance. 27 29 """ … … 41 43 42 44 @grok.action('Cancel') 43 def cancel(self ):45 def cancel(self, **data): 44 46 self.redirect(self.url(self.context)) 45 47 return 46 48 49 class ManageUniversity(grok.Viewlet): 50 """A viewlet that renders the `ManageForm`. 51 """ 52 grok.viewletmanager(MainArea) 53 grok.context(IUniversity) 54 grok.view(Manage) 55 grok.require('waeup.manageUniversity') 56 57 def update(self): 58 self.form = getMultiAdapter((self.context, self.request), 59 name='manageform') 60 self.form.update_form() 61 if self.request.method == 'POST': 62 #app = get_application(self.context) 63 #self.__parent__.redirect(self.__parent__.url(obj=app)) 64 pass 65 66 def render(self): 67 result = self.form.render() 68 try: 69 # strip all except the form part... 70 result = re.match('^.+\(<form[^\>]+>.*</form>).+$', result, 71 re.DOTALL).groups()[0] 72 except: 73 # except there is no such part... 74 pass 75 return result 76 return self.form.render() 77 78 79 47 80 class Content(grok.Viewlet): 48 81 grok.viewletmanager(MainArea) 49 82 grok.context(IUniversity) 50 83 grok.view(Index) 51 84 52 85 class Edit(grok.EditForm): 53 86 grok.context(University) 54 87 grok.AutoFields(IUniversity) 88 89 class ManageLink(grok.Viewlet): 90 grok.viewletmanager(LeftSidebar) 91 grok.context(IUniversity) 92 grok.view(Index) 93 grok.order(5) 94 # This is so cool! This link is only displayed, when the user is 95 # allowed to use it! 96 grok.require('waeup.manageUniversity') 97 98 def render(self): 99 return u'<div class="portlet"><a href="manage">Settings</a></div>'
Note: See TracChangeset for help on using the changeset viewer.