Changeset 3529 for waeup/trunk


Ignore:
Timestamp:
30 Jun 2008, 16:24:45 (16 years ago)
Author:
adiwidjaja
Message:

Working import/export.

Location:
waeup/trunk/src/waeup
Files:
1 deleted
7 edited
1 moved

Legend:

Unmodified
Added
Removed
  • waeup/trunk/src/waeup/app_templates/index.pt

    r3526 r3529  
    2121  </div>
    2222
    23   <div>
    24     <a href="@@importstudents">Import Students</a>
    25   </div>
    2623</body>
    2724</html>
  • waeup/trunk/src/waeup/basecontainer.py

    r3527 r3529  
    11import grok
     2from baseitem import BaseItem
    23
    3 class BaseContainer(grok.Container):
     4class BaseContainer(BaseItem, grok.Container):
    45    """
    56    The base container. This is a stub for now. It can have
     
    910    name = u"BaseContainer"
    1011    childClass = None
     12    specialActions = []
    1113   
    1214class Index(grok.View):
  • waeup/trunk/src/waeup/basecontainer_templates/index.pt

    r3527 r3529  
    1717    </table>
    1818    <a href="" tal:attributes="href python:view.url(context, 'add')">Add</a>
     19    <a href=""
     20        tal:repeat="action context/specialActions"
     21        tal:attributes="href python:view.url(context, action)"
     22        tal:content="action">Add</a>
    1923</body>
    2024</html>
  • waeup/trunk/src/waeup/hostel/hostel.py

    r3527 r3529  
    1 import grok
     1from waeup.baseitem import BaseItem
    22
    3 class Hostel(grok.Model):
     3class Hostel(BaseItem):
    44    pass
  • waeup/trunk/src/waeup/students/student.py

    r3528 r3529  
    55from waeup.baseitem import BaseItem
    66
     7def fromCsv(a):
     8    #Factory method
     9    student = Student("Dummy")
     10    student.entry_mode, student.end_level, student.name, student.jamb_reg_no, student.level, student.id, student.lga, student.entry_session, student.matric_no, student.sex, student.phone, student.session, student.course, student.mode, student.faculty, student.department, student.verdict, student.review_state,  student.perm_address, student.email = a
     11    return student
     12
    713class Student(BaseItem):
    814    """This is a student record.
    915    """
    1016    grok.implements(IStudent)
     17
     18    #TODO: REFACTOR TO SCHEMA
     19    fields = [   "entry_mode",
     20                 "end_level",
     21                 "name",
     22                 "jamb_reg_no",
     23                 "level",
     24                 "id",
     25                 "lga",
     26                 "entry_session",
     27                 "matric_no",
     28                 "sex",
     29                 "phone",
     30                 "session",
     31                 "course",
     32                 "mode",
     33                 "faculty",
     34                 "department",
     35                 "verdict",
     36                 "review_state",
     37                 "perm_address",
     38                 "email"
     39            ]
    1140
    1241    def __init__(self, name):
     
    3867        self.name = name
    3968       
    40     def fromCsv(self, a):
    41         self.entry_mode, self.end_level, self.name, self.jamb_reg_no, self.level, self.id, self.lga, self.entry_session, self.matric_no, self.sex, self.phone, self.session, self.course, self.mode, self.faculty, self.department, self.verdict, self.review_state,  self.perm_address, self.email = a
    4269
    4370    def getCsv(self):
    44         return self.entry_mode, self.end_level, self.name, self.jamb_reg_no, self.level, self.id, self.lga, self.entry_session, self.matric_no, self.sex, self.phone, self.session, self.course, self.mode, self.faculty, self.department, self.verdict, self.review_state,  self.perm_address, self.email
     71        #return self.entry_mode, self.end_level, self.name, self.jamb_reg_no, self.level, self.id, self.lga, self.entry_session, self.matric_no, self.sex, self.phone, self.session, self.course, self.mode, self.faculty, self.department, self.verdict, self.review_state,  self.perm_address, self.email
     72        return [getattr(self, field, u"") for field in self.fields]
     73
  • waeup/trunk/src/waeup/students/studentcontainer.py

    r3527 r3529  
    11import grok
     2import os
    23
    34from waeup.basecontainer import BaseContainer
    4 from student import Student
    5 from waeup.utils import csv
     5from student import Student, fromCsv
     6from waeup.utils import importexport as csv
    67
    78class StudentContainer(BaseContainer):
     
    1112    name = u"Students"
    1213    childClass = Student
    13    
     14    specialActions = [u"import", u"export"]   
    1415
    1516class Import(grok.View):
    1617    def render(self):
    1718        t = [0]
    18         src = os.path.join(os.path.dirname(__file__), 'tests',
     19        src = os.path.join(os.path.dirname(__file__), '..', 'tests',
    1920                           'results2.csv')
    2021        inputfile = file(src, "r")
     
    2223        headers, rows = csv.readFile(inputfile)
    2324        for i in rows:
    24              s = Student(i)
     25             s = fromCsv(i)
    2526             self.context[str(num)] = s
    2627             num += 1
     28             if num > 100:
     29                 break
    2730        return "%s new Students added in %s" % (num, t[0])
    2831
  • waeup/trunk/src/waeup/university/faculty.py

    r3526 r3529  
    11import grok
     2from waeup.basecontainer import BaseContainer
    23from interfaces import IFaculty
    34
    4 class Faculty(grok.Container):
     5class Faculty(BaseContainer):
    56    grok.implements(IFaculty)
    67
Note: See TracChangeset for help on using the changeset viewer.