Changeset 3566 for waeup/branches


Ignore:
Timestamp:
8 Jul 2008, 22:06:42 (16 years ago)
Author:
hraban
Message:

still problems with inheritance and interfaces; works partly; still no tests, sorry...

Location:
waeup/branches/hraban/src/waeup
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/hraban/src/waeup/app.py

    r3557 r3566  
    44from setup import app_setup
    55from waeup.viewlets import MainArea
     6from basecontainer import BaseContainer
    67
    7 class University(grok.Application, grok.Container):
     8class University(grok.Application, BaseContainer):
    89    grok.implements(IUniversity)
    910
    10     def __init__(self, name=u'Unnamed', **kw):
     11    def __init__(self, **kw):
    1112        super(University, self).__init__(**kw)
    12         self.name = name
     13        self.__dict__.update(kw)
    1314        app_setup.setup(self)
    1415
    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 
    51  <ul>
    62    <li tal:repeat="fac context/values">
  • waeup/branches/hraban/src/waeup/basecontainer.py

    r3562 r3566  
    22import os
    33from waeup.interfaces import IBaseContainer
    4 #from waeup.baseitem import BaseItem
    5 from waeup.viewlets import MainArea, Index, Add, Edit
     4import waeup.viewlets as vw
    65from zope.component import getMultiAdapter
    76
     
    98    """
    109    The base container. This is a stub for now. It can have
    11     base methods and templates attached to it
     10    base methods attached to it
    1211    """
    1312    grok.implements(IBaseContainer)
     13    id = 'base'
    1414    name = u"BaseContainer"
    1515    childClass = None
    1616    specialActions = []
     17   
     18    def __init__(self, **kwargs):
     19        super(BaseContainer, self).__init__()
     20        self.__dict__.update(kwargs)
    1721   
    1822class Content(grok.Viewlet):
     
    2024    Base viewlet
    2125    """
    22     grok.viewletmanager(MainArea)
    23     grok.view(Index)
     26    grok.viewletmanager(vw.MainArea)
     27    grok.view(vw.Index)
    2428    #grok.order(1)
    2529
     
    3539        obj = self.context.childClass(**data)
    3640        try:
    37             name = data['name'].lower().replace(' ', '_')
    38             self.context[name] = obj
     41            id = data['id'].lower()
     42            self.context[id] = obj
    3943        except Exception, ex:
    4044            print ex
    4145            print data
    42         self.redirect(self.url())
     46            raise ex
     47        self.redirect(self.url('.'))
    4348
    44 class Add(grok.Viewlet):
    45     grok.viewletmanager(MainArea)
     49class 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
     60class AddViewlet(grok.Viewlet):
     61    grok.viewletmanager(vw.MainArea)
    4662    grok.context(IBaseContainer)
    47     grok.view(Add)
     63    grok.view(vw.Add)
     64    #grok.name('add')
    4865    #grok.order(2)
    4966
    5067    def update(self):
    51         self.form = getMultiAdapter((self.context, self.request),
    52                                     name='addform')
     68        self.form = getMultiAdapter((self.context, self.request), name='addform')
    5369        self.form.update_form()
    5470
    5571    def render(self):
    5672        return self.form.render()
     73
     74class 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  
    22        <ul>
    33                <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>
    66                <li tal:repeat="action context/specialActions">
    77                        <a href="" tal:attributes="href python:view.url(context, action)"
     
    1212
    1313<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  
    1717    </div>
    1818    -->
     19        <div tal:content="context"></div>
    1920    <div class="form-fields">
    2021        <tal:block repeat="widget view/widgets">
  • waeup/branches/hraban/src/waeup/baseitem.py

    r3562 r3566  
    22import os
    33import grok
    4 from waeup.viewlets import MainArea, Index, Add, Edit
     4import waeup.viewlets as vw
    55from waeup.interfaces import IBaseItem
    66from zope.component import getMultiAdapter
     
    1111    """
    1212    grok.implements(IBaseItem)
     13   
     14    def __init__(self, **kwargs):
     15        super(BaseItem, self).__init__()
     16        self.__dict__.update(kwargs)
    1317
    1418class Index(grok.Viewlet):
    15     grok.viewletmanager(MainArea)
     19    grok.viewletmanager(vw.MainArea)
    1620    #grok.context(IBaseItem)
    1721    #grok.order(1)
     
    2933    def add(self, **data):
    3034        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'))
    3338
    3439class EditForm(grok.EditForm):
     
    3641   
    3742    def update(self):
    38         self.form_fields = grok.AutoFields(self.context.childClass)
     43        self.form_fields = grok.AutoFields(self.context)
    3944        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('..'))
    4049
    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)
     50class AddViewlet(grok.Viewlet):
     51    grok.viewletmanager(vw.MainArea)
    4952    grok.context(IBaseItem)
    50     grok.view(Add)
     53    grok.view(vw.Add)
     54    #grok.name('add')
    5155    #grok.order(2)
    5256
     
    6064
    6165
    62 class Edit(grok.Viewlet):
    63     grok.viewletmanager(MainArea)
     66class EditViewlet(grok.Viewlet):
     67    grok.viewletmanager(vw.MainArea)
    6468    grok.context(IBaseItem)
    65     grok.view(Edit)
     69    grok.view(vw.Edit)
     70    #grok.name('edit')
    6671    #grok.order(2)
    6772
  • waeup/branches/hraban/src/waeup/hostel/__init__.py

    r3526 r3566  
     1from interfaces import IHostel
     2from hostelcontainer import HostelContainer
     3from hostel import Hostel
  • waeup/branches/hraban/src/waeup/hostel/hostel.py

    r3557 r3566  
    11import grok
    2 from waeup.baseitem import BaseItem
     2import waeup.baseitem as base
    33from waeup.hostel.interfaces import IHostel
    44
    55
    6 class Hostel(BaseItem):
     6class Hostel(base.BaseItem):
    77    """This is a hostel record.
    88    """   
    99    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  
     1import grok
     2from waeup.interfaces import IBaseContainer
    13from waeup.basecontainer import BaseContainer
    24from hostel import Hostel
    35
    46class HostelContainer(BaseContainer):
     7    grok.implements(IBaseContainer)
    58    name = u"Hostels"
    69    childClass = Hostel
  • waeup/branches/hraban/src/waeup/hostel/interfaces.py

    r3557 r3566  
    22## interfaces.py
    33import grok
     4import re
    45from zope import schema
     6from waeup.interfaces import IBaseContainer
    57
    6 class IHostel(grok.interfaces.IContainer):
     8class IHostel(IBaseContainer):
    79    """Representation of a hostel (AKA hall).
    810    """
     11    id = schema.ASCIILine(
     12        title = u'ID of Hostel',
     13        default = '1',
     14        required = True,
     15        constraint = (re.compile('^\w+$').match)
     16        )
    917    name = schema.TextLine(
    1018        title = u'Name of Hostel',
  • waeup/branches/hraban/src/waeup/interfaces.py

    r3562 r3566  
    22## interfaces.py
    33import grok
    4 #from zope.interface import Interface
     4import re
    55from zope import schema
     6from zope.interface import Interface
    67
    78class 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        )
    819    name = schema.TextLine(
    920        title = u'Name of Container',
     
    1324   
    1425
    15 class IBaseItem(grok.interfaces.IContainer):
     26class 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        )
    1637    name = schema.TextLine(
    1738        title = u'Name of Item',
     
    2041        )
    2142
    22 class IUniversity(IBaseContainer):
     43
     44class IUniversity(grok.interfaces.IContainer):
    2345    """Representation of a university.
    2446    """
     47    id = schema.ASCIILine(
     48        title = u'ID of University',
     49        default = 'base',
     50        required = False,
     51        readonly = True
     52        )
    2553    name = schema.TextLine(
    2654        title = u'Name of University',
  • waeup/branches/hraban/src/waeup/students/interfaces.py

    r3563 r3566  
    22## interfaces.py
    33import grok
     4import re
    45from zope import schema
    56from waeup.interfaces import IBaseItem
     
    4344        default = '',
    4445        required = False,
    45         constraint=(re.compile("^[A-Z]\d{6}$").match)
     46        constraint=(re.compile("^([A-Z]\d{6})?$").match)
    4647        )
    4748    lga = schema.TextLine(
     
    6364        default = '',
    6465        required = False,
    65         constraint=re.compile("^[A-Z]{3}\d{7}$").match
     66        constraint=re.compile("^([A-Z]{3}\d{7})?$").match
    6667        )
    6768    sex = schema.ASCIILine( # Choice!
    6869        title = u'Sex',
    69         default = u'M',
     70        default = 'M',
    7071        required = True,
    7172        constraint=(re.compile("^[MF]$").match)
    7273        )
    73     phone = schema.TextLine(
     74    phone = schema.ASCIILine(
    7475        title = u'Phone',
    75         default = u'',
     76        default = '',
    7677        required = False,
    77         constraint=re.compile(u"^[\d-,]{5,}$").match,
     78        constraint=re.compile(u"^([\d-]{5,},?)?$").match,
    7879        description = u'if multiple, separate with comma'
    7980        )
     
    8889        default = '',
    8990        required = False,
    90         constraint=(re.compile("^[A-Z]{3,8}$").match)
     91        constraint=(re.compile("^([A-Z]{3,8})?$").match)
    9192        )
    9293    mode = schema.ASCIILine( # Choice?
     
    99100        default = '',
    100101        required = False,
    101         constraint=(re.compile("^[A-Z]{3}$").match)
     102        constraint=(re.compile("^([A-Z]{3})?$").match)
    102103        )
    103104    department = schema.ASCIILine( # Choice
     
    105106        default = '',
    106107        required = False,
    107         constraint=(re.compile("^[A-Z]{3}$").match)
     108        constraint=(re.compile("^([A-Z]{3})?$").match)
    108109        )
    109110    verdict = schema.ASCIILine(
     
    126127        default = '',
    127128        required = True,
    128         constraint=(re.compile("^[\w\.]+@(\w+\.)+\w{2,}$").match)
     129        constraint=(re.compile("^([\w\.]+@(\w+\.)+\w{2,})?$").match)
    129130        )
  • waeup/branches/hraban/src/waeup/students/student.py

    r3557 r3566  
    11import grok
     2import waeup.baseitem as base
    23from interfaces import IStudent
    3 from waeup.baseitem import BaseItem
    44
    55def fromCsv(a):
     
    1515    return student
    1616
    17 class Student(BaseItem):
     17class Student(base.BaseItem):
    1818    """This is a student record.
    1919    """
    2020    grok.implements(IStudent)
     21    name = u'Student'
    2122
    2223    #TODO: REFACTOR TO SCHEMA
     
    4243                 "email"
    4344            ]
    44 
    45     def __init__(self, name):
    46         """
    47         TODO: REFACTOR TO IMPORT METHOD
    48         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                  email
    69 
    70         """
    71         self.name = name
    7245       
    7346
     
    7649        return [getattr(self, field, u"") for field in self.fields]
    7750
     51
     52class Add(base.AddViewlet):
     53    grok.context(IStudent)
     54
     55class Edit(base.EditViewlet):
     56    grok.context(IStudent)
  • waeup/branches/hraban/src/waeup/students/studentcontainer.py

    r3557 r3566  
    11import grok
    22import os
    3 from waeup.basecontainer import BaseContainer
     3from waeup.interfaces import IBaseContainer
     4import waeup.basecontainer as base
    45from student import Student, fromCsv
    56from waeup.utils import importexport as csv
    67
    7 class StudentContainer(BaseContainer):
     8
     9class StudentContainer(base.BaseContainer):
    810    """
    911    The node containing the student models
     
    1113    name = u"Students"
    1214    childClass = Student
    13     specialActions = [u"import", u"export"]   
     15    specialActions = [u'import', u'export', u'search']   
    1416
    1517class Import(grok.View):
     
    3941        csv.writeFile(result)
    4042        return "yeah %s" % t[0]
     43
     44
     45class Edit(base.EditViewlet):
     46    grok.context(IBaseContainer)
  • waeup/branches/hraban/src/waeup/university/__init__.py

    r3521 r3566  
     1from interfaces import IFaculty, IDepartment
     2from facultycontainer import FacultyContainer
     3from faculty import Faculty
     4from department import Department
  • waeup/branches/hraban/src/waeup/university/course.py

    r3526 r3566  
     1import grok
     2import waeup.baseitem as base
     3from waeup.university.interfaces import ICourse
     4
     5class Department(base.BaseItem):
     6    grok.implements(ICourse)
     7    name = u'Course'
  • waeup/branches/hraban/src/waeup/university/department.py

    r3526 r3566  
     1import grok
     2import waeup.basecontainer as base
     3from waeup.university.interfaces import IDepartment
     4from waeup.university.course import Course
     5
     6class Department(base.BaseContainer):
     7    grok.implements(IDepartment)
     8    childClass = Course
     9    name = u'Department'
     10
     11class 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  
    11import grok
    2 from waeup.basecontainer import BaseContainer
     2import waeup.basecontainer as base
    33from waeup.university.interfaces import IFaculty
     4from waeup.university.department import Department
    45
    5 class Faculty(BaseContainer):
     6class Faculty(base.BaseContainer):
     7    """
     8    This is a Faculty (part of University, contains Departments)
     9    """
    610    grok.implements(IFaculty)
     11    childClass = Department
     12    name = u'Faculty'
    713
    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)
    1116
    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  
    55
    66class FacultyContainer(BaseContainer):
    7     #grok.implements(grok.interfaces.IContainer)
     7    #grok.implements(IBaseContainer)
    88    name = u'Faculties'
    99    childClass = Faculty
  • waeup/branches/hraban/src/waeup/university/interfaces.py

    r3557 r3566  
    11import grok
     2import re
    23from zope import schema
     4from waeup.interfaces import IBaseContainer
    35
    4 class IFaculty(grok.interfaces.IContainer):
     6class IFaculty(IBaseContainer):
    57    """Representation of a university faculty.
    68    """
     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        )
    720    name = schema.TextLine(
    821        title = u'Name of Faculty',
     
    1023        required = True,
    1124        )
     25
     26
     27class 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
     48class 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  
    88grok.context(Interface)
    99
    10 class Index(grok.View):
     10class MainView(grok.View):
    1111    """main structure for all pages"""
    1212    grok.template('master')
    1313   
    1414    def __init__(self, context, request):
    15         super(Index, self).__init__(context, request)
     15        super(MainView, self).__init__(context, request)
    1616   
    1717    def getSite(self):
    1818        return grok.getSite()
    1919
    20 class Edit(Index):
     20class Index(MainView):
    2121    pass
    2222
    23 class Add(Index):
     23class Edit(MainView):
     24    pass
     25
     26class Add(MainView):
    2427    pass
    2528
     
    6063    """display the current user's name"""
    6164    grok.viewletmanager(LeftSidebar)
    62     grok.view(Index)
     65    grok.view(MainView)
    6366    grok.order(1)
    6467
Note: See TracChangeset for help on using the changeset viewer.