Changeset 3566 for waeup/branches
- Timestamp:
- 8 Jul 2008, 22:06:42 (16 years ago)
- Location:
- waeup/branches/hraban/src/waeup
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/hraban/src/waeup/app.py
r3557 r3566 4 4 from setup import app_setup 5 5 from waeup.viewlets import MainArea 6 from basecontainer import BaseContainer 6 7 7 class University(grok.Application, grok.Container):8 class University(grok.Application, BaseContainer): 8 9 grok.implements(IUniversity) 9 10 10 def __init__(self, name=u'Unnamed',**kw):11 def __init__(self, **kw): 11 12 super(University, self).__init__(**kw) 12 self. name = name13 self.__dict__.update(kw) 13 14 app_setup.setup(self) 14 15 15 class Content(grok.Viewlet): 16 grok.viewletmanager(MainArea) 17 grok.context(IUniversity) 18 19 20 class Edit(grok.EditForm): 21 grok.context(University) 22 grok.AutoFields(IUniversity) 16 #class Content(grok.Viewlet): 17 # grok.viewletmanager(MainArea) 18 # grok.context(IUniversity) 19 # grok.template('basecontainer_templates/content.pt') 20 # 21 # 22 #class Edit(grok.EditForm): 23 # grok.context(University) 24 # grok.AutoFields(IUniversity) -
waeup/branches/hraban/src/waeup/app_templates/content.pt
r3530 r3566 1 <h1>Congratulations!</h1>2 3 <h2>Your faculties:</h2>4 5 1 <ul> 6 2 <li tal:repeat="fac context/values"> -
waeup/branches/hraban/src/waeup/basecontainer.py
r3562 r3566 2 2 import os 3 3 from waeup.interfaces import IBaseContainer 4 #from waeup.baseitem import BaseItem 5 from waeup.viewlets import MainArea, Index, Add, Edit 4 import waeup.viewlets as vw 6 5 from zope.component import getMultiAdapter 7 6 … … 9 8 """ 10 9 The base container. This is a stub for now. It can have 11 base methods a nd templates attached to it10 base methods attached to it 12 11 """ 13 12 grok.implements(IBaseContainer) 13 id = 'base' 14 14 name = u"BaseContainer" 15 15 childClass = None 16 16 specialActions = [] 17 18 def __init__(self, **kwargs): 19 super(BaseContainer, self).__init__() 20 self.__dict__.update(kwargs) 17 21 18 22 class Content(grok.Viewlet): … … 20 24 Base viewlet 21 25 """ 22 grok.viewletmanager( MainArea)23 grok.view( Index)26 grok.viewletmanager(vw.MainArea) 27 grok.view(vw.Index) 24 28 #grok.order(1) 25 29 … … 35 39 obj = self.context.childClass(**data) 36 40 try: 37 name = data['name'].lower().replace(' ', '_')38 self.context[ name] = obj41 id = data['id'].lower() 42 self.context[id] = obj 39 43 except Exception, ex: 40 44 print ex 41 45 print data 42 self.redirect(self.url()) 46 raise ex 47 self.redirect(self.url('.')) 43 48 44 class Add(grok.Viewlet): 45 grok.viewletmanager(MainArea) 49 class EditForm(grok.EditForm): 50 template = grok.PageTemplate(filename=os.path.join('basecontainer_templates', 'edit_form.pt')) 51 52 def update(self): 53 self.form_fields = grok.AutoFields(self.context) 54 grok.EditForm.update(self) 55 56 def handle_edit_action(self, **data): 57 grok.EditForm.handle_edit_action(self, **data) 58 self.redirect(self.url('@@index')) 59 60 class AddViewlet(grok.Viewlet): 61 grok.viewletmanager(vw.MainArea) 46 62 grok.context(IBaseContainer) 47 grok.view(Add) 63 grok.view(vw.Add) 64 #grok.name('add') 48 65 #grok.order(2) 49 66 50 67 def update(self): 51 self.form = getMultiAdapter((self.context, self.request), 52 name='addform') 68 self.form = getMultiAdapter((self.context, self.request), name='addform') 53 69 self.form.update_form() 54 70 55 71 def render(self): 56 72 return self.form.render() 73 74 class EditViewlet(grok.Viewlet): 75 grok.viewletmanager(vw.MainArea) 76 grok.context(IBaseContainer) 77 grok.view(vw.Edit) 78 #grok.name('edit') 79 #grok.order(2) 80 81 def update(self): 82 self.form = getMultiAdapter((self.context, self.request), name='editform') 83 self.form.update_form() 84 85 def render(self): 86 return self.form.render() -
waeup/branches/hraban/src/waeup/basecontainer_templates/content.pt
r3562 r3566 2 2 <ul> 3 3 <li><a href="" tal:attributes="href python:view.url(context.__parent__)">Up</a></li> 4 <li><a href="" tal:attributes="href python:view.url(context, '@@edit')">Edit </a>5 <li ><a href="" tal:attributes="href python:view.url(context, '@@add')">Add</a>4 <li><a href="" tal:attributes="href python:view.url(context, '@@edit')">Edit <span tal:replace="context/name">Object</span></a></li> 5 <li tal:condition="exists:context/childClass/name"><a href="" tal:attributes="href python:view.url(context, '@@add')" >Add <span tal:replace="context/childClass/name">Child</span></a></li> 6 6 <li tal:repeat="action context/specialActions"> 7 7 <a href="" tal:attributes="href python:view.url(context, action)" … … 12 12 13 13 <h2 tal:content="context/name">Objects</h2> 14 <table class="datatable"> 15 <tr> 16 <th>Name</th> 17 </tr> 18 <tr tal:repeat="item context/values"> 19 <td tal:repeat="prop item/items"> 20 <a href="" tal:content="prop" 21 tal:attributes="href python:view.url(item)"></a> 22 </td> 23 <!-- 24 <td><a href="" tal:content="item/name" 25 tal:attributes="href python:view.url(item)"></a></td> 26 --> 27 </tr> 28 </table> 14 <ul> 15 <li tal:repeat="item context/values"><a tal:condition="exists:item/name" href="" tal:attributes="href python:view.url(item)" tal:content="item/name">Item</a></li> 16 </ul> -
waeup/branches/hraban/src/waeup/basecontainer_templates/edit_form.pt
r3562 r3566 17 17 </div> 18 18 --> 19 <div tal:content="context"></div> 19 20 <div class="form-fields"> 20 21 <tal:block repeat="widget view/widgets"> -
waeup/branches/hraban/src/waeup/baseitem.py
r3562 r3566 2 2 import os 3 3 import grok 4 from waeup.viewlets import MainArea, Index, Add, Edit 4 import waeup.viewlets as vw 5 5 from waeup.interfaces import IBaseItem 6 6 from zope.component import getMultiAdapter … … 11 11 """ 12 12 grok.implements(IBaseItem) 13 14 def __init__(self, **kwargs): 15 super(BaseItem, self).__init__() 16 self.__dict__.update(kwargs) 13 17 14 18 class Index(grok.Viewlet): 15 grok.viewletmanager( MainArea)19 grok.viewletmanager(vw.MainArea) 16 20 #grok.context(IBaseItem) 17 21 #grok.order(1) … … 29 33 def add(self, **data): 30 34 obj = self.context.childClass(**data) 31 name = data['name'].lower().replace(' ', '_') 32 self.context[name] = obj 35 id = data['id'].lower() 36 self.context[id] = obj 37 self.redirect(self.url('@@index')) 33 38 34 39 class EditForm(grok.EditForm): … … 36 41 37 42 def update(self): 38 self.form_fields = grok.AutoFields(self.context .childClass)43 self.form_fields = grok.AutoFields(self.context) 39 44 grok.EditForm.update(self) 45 46 def handle_edit_action(self, **data): 47 grok.EditForm.handle_edit_action(self, **data) 48 self.redirect(self.url('..')) 40 49 41 @grok.action('Edit item') 42 def edit(self, **data): 43 obj = self.context.childClass(**data) 44 name = data['name'].lower().replace(' ', '_') 45 self.context[name] = obj 46 47 class Add(grok.Viewlet): 48 grok.viewletmanager(MainArea) 50 class AddViewlet(grok.Viewlet): 51 grok.viewletmanager(vw.MainArea) 49 52 grok.context(IBaseItem) 50 grok.view(Add) 53 grok.view(vw.Add) 54 #grok.name('add') 51 55 #grok.order(2) 52 56 … … 60 64 61 65 62 class Edit (grok.Viewlet):63 grok.viewletmanager( MainArea)66 class EditViewlet(grok.Viewlet): 67 grok.viewletmanager(vw.MainArea) 64 68 grok.context(IBaseItem) 65 grok.view(Edit) 69 grok.view(vw.Edit) 70 #grok.name('edit') 66 71 #grok.order(2) 67 72 -
waeup/branches/hraban/src/waeup/hostel/__init__.py
r3526 r3566 1 from interfaces import IHostel 2 from hostelcontainer import HostelContainer 3 from hostel import Hostel -
waeup/branches/hraban/src/waeup/hostel/hostel.py
r3557 r3566 1 1 import grok 2 from waeup.baseitem import BaseItem 2 import waeup.baseitem as base 3 3 from waeup.hostel.interfaces import IHostel 4 4 5 5 6 class Hostel( BaseItem):6 class Hostel(base.BaseItem): 7 7 """This is a hostel record. 8 8 """ 9 9 grok.implements(IHostel) 10 11 def __init__(self, name=u'Unnamed Hostel', **kw): 12 super(Hostel, self).__init__(**kw) 13 self.name = name 10 name = u'Hostel' 11 #childClass = ? 12 13 14 #class Add(base.AddViewlet): 15 # grok.context(IHostel) 16 # 17 #class Edit(base.EditViewlet): 18 # grok.context(IHostel) 19 # 20 #class EditForm(base.EditForm): 21 # pass 22 # 23 #class AddForm(base.AddForm): 24 # pass -
waeup/branches/hraban/src/waeup/hostel/hostelcontainer.py
r3527 r3566 1 import grok 2 from waeup.interfaces import IBaseContainer 1 3 from waeup.basecontainer import BaseContainer 2 4 from hostel import Hostel 3 5 4 6 class HostelContainer(BaseContainer): 7 grok.implements(IBaseContainer) 5 8 name = u"Hostels" 6 9 childClass = Hostel -
waeup/branches/hraban/src/waeup/hostel/interfaces.py
r3557 r3566 2 2 ## interfaces.py 3 3 import grok 4 import re 4 5 from zope import schema 6 from waeup.interfaces import IBaseContainer 5 7 6 class IHostel( grok.interfaces.IContainer):8 class IHostel(IBaseContainer): 7 9 """Representation of a hostel (AKA hall). 8 10 """ 11 id = schema.ASCIILine( 12 title = u'ID of Hostel', 13 default = '1', 14 required = True, 15 constraint = (re.compile('^\w+$').match) 16 ) 9 17 name = schema.TextLine( 10 18 title = u'Name of Hostel', -
waeup/branches/hraban/src/waeup/interfaces.py
r3562 r3566 2 2 ## interfaces.py 3 3 import grok 4 #from zope.interface import Interface4 import re 5 5 from zope import schema 6 from zope.interface import Interface 6 7 7 8 class IBaseContainer(grok.interfaces.IContainer): 9 """ 10 ID is something that can be used in an URL and as an index, e.g. 11 faculty/department codes 12 """ 13 id = schema.ASCIILine( 14 title = u'ID of Container', 15 default = 'x', 16 required = True, 17 constraint = (re.compile('^\w+$').match) 18 ) 8 19 name = schema.TextLine( 9 20 title = u'Name of Container', … … 13 24 14 25 15 class IBaseItem(grok.interfaces.IContainer): 26 class IBaseItem(Interface): #(grok.interfaces.IContainer): 27 """ 28 ID is something that can be used in an URL and as an index, e.g. 29 course code, student ID 30 """ 31 id = schema.ASCIILine( 32 title = u'ID of Item', 33 default = 'x', 34 required = True, 35 constraint = (re.compile('^\w+$').match) 36 ) 16 37 name = schema.TextLine( 17 38 title = u'Name of Item', … … 20 41 ) 21 42 22 class IUniversity(IBaseContainer): 43 44 class IUniversity(grok.interfaces.IContainer): 23 45 """Representation of a university. 24 46 """ 47 id = schema.ASCIILine( 48 title = u'ID of University', 49 default = 'base', 50 required = False, 51 readonly = True 52 ) 25 53 name = schema.TextLine( 26 54 title = u'Name of University', -
waeup/branches/hraban/src/waeup/students/interfaces.py
r3563 r3566 2 2 ## interfaces.py 3 3 import grok 4 import re 4 5 from zope import schema 5 6 from waeup.interfaces import IBaseItem … … 43 44 default = '', 44 45 required = False, 45 constraint=(re.compile("^ [A-Z]\d{6}$").match)46 constraint=(re.compile("^([A-Z]\d{6})?$").match) 46 47 ) 47 48 lga = schema.TextLine( … … 63 64 default = '', 64 65 required = False, 65 constraint=re.compile("^ [A-Z]{3}\d{7}$").match66 constraint=re.compile("^([A-Z]{3}\d{7})?$").match 66 67 ) 67 68 sex = schema.ASCIILine( # Choice! 68 69 title = u'Sex', 69 default = u'M',70 default = 'M', 70 71 required = True, 71 72 constraint=(re.compile("^[MF]$").match) 72 73 ) 73 phone = schema. TextLine(74 phone = schema.ASCIILine( 74 75 title = u'Phone', 75 default = u'',76 default = '', 76 77 required = False, 77 constraint=re.compile(u"^ [\d-,]{5,}$").match,78 constraint=re.compile(u"^([\d-]{5,},?)?$").match, 78 79 description = u'if multiple, separate with comma' 79 80 ) … … 88 89 default = '', 89 90 required = False, 90 constraint=(re.compile("^ [A-Z]{3,8}$").match)91 constraint=(re.compile("^([A-Z]{3,8})?$").match) 91 92 ) 92 93 mode = schema.ASCIILine( # Choice? … … 99 100 default = '', 100 101 required = False, 101 constraint=(re.compile("^ [A-Z]{3}$").match)102 constraint=(re.compile("^([A-Z]{3})?$").match) 102 103 ) 103 104 department = schema.ASCIILine( # Choice … … 105 106 default = '', 106 107 required = False, 107 constraint=(re.compile("^ [A-Z]{3}$").match)108 constraint=(re.compile("^([A-Z]{3})?$").match) 108 109 ) 109 110 verdict = schema.ASCIILine( … … 126 127 default = '', 127 128 required = True, 128 constraint=(re.compile("^ [\w\.]+@(\w+\.)+\w{2,}$").match)129 constraint=(re.compile("^([\w\.]+@(\w+\.)+\w{2,})?$").match) 129 130 ) -
waeup/branches/hraban/src/waeup/students/student.py
r3557 r3566 1 1 import grok 2 import waeup.baseitem as base 2 3 from interfaces import IStudent 3 from waeup.baseitem import BaseItem4 4 5 5 def fromCsv(a): … … 15 15 return student 16 16 17 class Student( BaseItem):17 class Student(base.BaseItem): 18 18 """This is a student record. 19 19 """ 20 20 grok.implements(IStudent) 21 name = u'Student' 21 22 22 23 #TODO: REFACTOR TO SCHEMA … … 42 43 "email" 43 44 ] 44 45 def __init__(self, name):46 """47 TODO: REFACTOR TO IMPORT METHOD48 Fields:49 entry_mode,50 end_level,51 name,52 jamb_reg_no,53 level,54 id,55 lga,56 entry_session,57 matric_no,58 sex,59 phone,60 session,61 course,62 mode,63 faculty,64 department,65 verdict,66 review_state,67 perm_address,68 email69 70 """71 self.name = name72 45 73 46 … … 76 49 return [getattr(self, field, u"") for field in self.fields] 77 50 51 52 class Add(base.AddViewlet): 53 grok.context(IStudent) 54 55 class Edit(base.EditViewlet): 56 grok.context(IStudent) -
waeup/branches/hraban/src/waeup/students/studentcontainer.py
r3557 r3566 1 1 import grok 2 2 import os 3 from waeup.basecontainer import BaseContainer 3 from waeup.interfaces import IBaseContainer 4 import waeup.basecontainer as base 4 5 from student import Student, fromCsv 5 6 from waeup.utils import importexport as csv 6 7 7 class StudentContainer(BaseContainer): 8 9 class StudentContainer(base.BaseContainer): 8 10 """ 9 11 The node containing the student models … … 11 13 name = u"Students" 12 14 childClass = Student 13 specialActions = [u "import", u"export"]15 specialActions = [u'import', u'export', u'search'] 14 16 15 17 class Import(grok.View): … … 39 41 csv.writeFile(result) 40 42 return "yeah %s" % t[0] 43 44 45 class Edit(base.EditViewlet): 46 grok.context(IBaseContainer) -
waeup/branches/hraban/src/waeup/university/__init__.py
r3521 r3566 1 from interfaces import IFaculty, IDepartment 2 from facultycontainer import FacultyContainer 3 from faculty import Faculty 4 from department import Department -
waeup/branches/hraban/src/waeup/university/course.py
r3526 r3566 1 import grok 2 import waeup.baseitem as base 3 from waeup.university.interfaces import ICourse 4 5 class Department(base.BaseItem): 6 grok.implements(ICourse) 7 name = u'Course' -
waeup/branches/hraban/src/waeup/university/department.py
r3526 r3566 1 import grok 2 import waeup.basecontainer as base 3 from waeup.university.interfaces import IDepartment 4 from waeup.university.course import Course 5 6 class Department(base.BaseContainer): 7 grok.implements(IDepartment) 8 childClass = Course 9 name = u'Department' 10 11 class Add(base.AddViewlet): 12 grok.context(IDepartment) 13 14 15 #class Edit(base.EditViewlet): 16 # grok.context(IDepartment) -
waeup/branches/hraban/src/waeup/university/faculty.py
r3557 r3566 1 1 import grok 2 from waeup.basecontainer import BaseContainer 2 import waeup.basecontainer as base 3 3 from waeup.university.interfaces import IFaculty 4 from waeup.university.department import Department 4 5 5 class Faculty(BaseContainer): 6 class Faculty(base.BaseContainer): 7 """ 8 This is a Faculty (part of University, contains Departments) 9 """ 6 10 grok.implements(IFaculty) 11 childClass = Department 12 name = u'Faculty' 7 13 8 def __init__(self, name=u'Unnamed Faculty', **kw): 9 super(Faculty, self).__init__(**kw) 10 self.name = name 14 #class Add(base.AddViewlet): 15 # grok.context(IFaculty) 11 16 12 class Index(grok.DisplayForm): 13 form_fields = grok.AutoFields(IFaculty) 14 15 17 #class Edit(base.Edit): 18 # grok.context(IFaculty) -
waeup/branches/hraban/src/waeup/university/facultycontainer.py
r3557 r3566 5 5 6 6 class FacultyContainer(BaseContainer): 7 #grok.implements( grok.interfaces.IContainer)7 #grok.implements(IBaseContainer) 8 8 name = u'Faculties' 9 9 childClass = Faculty -
waeup/branches/hraban/src/waeup/university/interfaces.py
r3557 r3566 1 1 import grok 2 import re 2 3 from zope import schema 4 from waeup.interfaces import IBaseContainer 3 5 4 class IFaculty( grok.interfaces.IContainer):6 class IFaculty(IBaseContainer): 5 7 """Representation of a university faculty. 6 8 """ 9 id = schema.ASCIILine( 10 title = u'ID of Faculty', 11 default = 'XXX', 12 required = True, 13 constraint = (re.compile('^[A-Z]{3}$').match) 14 ) 15 title = schema.TextLine( 16 title = u'Title of Faculty', 17 default = u'Faculty of', 18 required = True 19 ) 7 20 name = schema.TextLine( 8 21 title = u'Name of Faculty', … … 10 23 required = True, 11 24 ) 25 26 27 class IDepartment(IBaseContainer): 28 """Representation of a university department. 29 """ 30 id = schema.ASCIILine( 31 title = u'ID of Department', 32 default = 'XXX', 33 required = True, 34 constraint = (re.compile('^[A-Z]{3}$').match) 35 ) 36 title = schema.TextLine( 37 title = u'Title of Department', 38 default = u'Department of', 39 required = True 40 ) 41 name = schema.TextLine( 42 title = u'Name of Department', 43 default = u'Unnamed', 44 required = True, 45 ) 46 47 48 class ICourse(IBaseContainer): 49 """Representation of a study course, provided by a department. 50 """ 51 id = schema.ASCIILine( 52 title = u'ID of Course', 53 default = 'XXX', 54 required = True, 55 constraint = (re.compile('^[A-Z]{3,8}$').match) 56 ) 57 name = schema.TextLine( 58 title = u'Name of Course', 59 default = u'Unnamed', 60 required = True, 61 ) -
waeup/branches/hraban/src/waeup/viewlets.py
r3562 r3566 8 8 grok.context(Interface) 9 9 10 class Index(grok.View):10 class MainView(grok.View): 11 11 """main structure for all pages""" 12 12 grok.template('master') 13 13 14 14 def __init__(self, context, request): 15 super( Index, self).__init__(context, request)15 super(MainView, self).__init__(context, request) 16 16 17 17 def getSite(self): 18 18 return grok.getSite() 19 19 20 class Edit(Index):20 class Index(MainView): 21 21 pass 22 22 23 class Add(Index): 23 class Edit(MainView): 24 pass 25 26 class Add(MainView): 24 27 pass 25 28 … … 60 63 """display the current user's name""" 61 64 grok.viewletmanager(LeftSidebar) 62 grok.view( Index)65 grok.view(MainView) 63 66 grok.order(1) 64 67
Note: See TracChangeset for help on using the changeset viewer.