Changeset 3527 for waeup


Ignore:
Timestamp:
30 Jun 2008, 15:30:23 (16 years ago)
Author:
adiwidjaja
Message:

Base management structures.

Location:
waeup/trunk/src/waeup
Files:
9 added
7 edited

Legend:

Unmodified
Added
Removed
  • waeup/trunk/src/waeup/basecontainer.py

    r3526 r3527  
    66    base methods and templates attached to it
    77    """
     8   
     9    name = u"BaseContainer"
     10    childClass = None
     11   
     12class Index(grok.View):
     13    """
     14    Base view
     15    """
     16   
     17class Add(grok.AddForm):
     18    #form_fields = grok.AutoFields(self.context.childClass)
     19#DOESN'T WORK    grok.template("../basecontainer_templates/add.pt")
     20
     21    def update(self):
     22        self.form_fields = grok.AutoFields(self.context.childClass)
     23        grok.AddForm.update(self)
     24
     25    @grok.action('Add Item')
     26    def addItem(self, name, *args, **kw):
     27        item = self.context.childClass(name=name)
     28        self.context[name] = item
     29        self.redirect(self.url(item))
  • waeup/trunk/src/waeup/catalog.py

    r3526 r3527  
    3535        return result
    3636   
    37 class ImportStudents(grok.View):
    38     grok.context(University)
    39 
    40     def render(self):
    41         t = [0]
    42         src = os.path.join(os.path.dirname(__file__), 'tests',
    43                            'results2.csv')
    44         inputfile = file(src, "r")
    45         num = 0
    46         headers, rows = readFile(inputfile)
    47         for i in rows:
    48              s = Student(i)
    49              self.context[str(num)] = s
    50              num += 1
    51         return "%s new Students added in %s" % (num, t[0])
    52 
    53 class ListView(grok.View):
    54     grok.context(University)
    55 
    56     def render(self):
    57         result = []
    58         for s in self.context.values():
    59             result.append(getattr(s,'name', 'Error'+str(type(s))))
    60         return "\n".join(result)
    61 
    62 class ExportStudents(grok.View):
    63     grok.context(University)
    64    
    65     def render(self):
    66         t = [0]
    67         result = []
    68         for s in self.context.values():
    69              result.append(s.getCsv())
    70         writeFile(result)
    71         return "yeah %s" % t[0]
    72        
    73 
    74 def readFile(f):
    75     """read a CSV file"""
    76     headers = []
    77     rows = []
    78     f = csv.reader(f)
    79     headers = f.next()
    80     for line in f:
    81         rows.append(line)
    82     return (headers, rows)
    83 
    84 def writeFile(data):
    85     writer = csv.writer(open("export.csv", "wb"))
    86     writer.writerows(data)
    87 
  • waeup/trunk/src/waeup/hostel/hostel.py

    r3526 r3527  
     1import grok
     2
     3class Hostel(grok.Model):
     4    pass
  • waeup/trunk/src/waeup/hostel/hostelcontainer.py

    r3526 r3527  
    11from waeup.basecontainer import BaseContainer
     2from hostel import Hostel
    23
    34class HostelContainer(BaseContainer):
    45    name = u"Hostels"
     6    childClass = Hostel
  • waeup/trunk/src/waeup/students/student.py

    r3526 r3527  
    88    grok.implements(IStudent)
    99
    10     def __init__(self, a):
     10    def __init__(self, name):
    1111        """
    1212        TODO: REFACTOR TO IMPORT METHOD
     
    3434
    3535        """
     36        self.name = name
     37       
     38    def fromCsv(self, a):
    3639        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
    3740
  • waeup/trunk/src/waeup/students/studentcontainer.py

    r3526 r3527  
    22
    33from waeup.basecontainer import BaseContainer
     4from student import Student
     5from waeup.utils import csv
    46
    57class StudentContainer(BaseContainer):
     
    810    """
    911    name = u"Students"
     12    childClass = Student
     13   
     14
     15class Import(grok.View):
     16    def render(self):
     17        t = [0]
     18        src = os.path.join(os.path.dirname(__file__), 'tests',
     19                           'results2.csv')
     20        inputfile = file(src, "r")
     21        num = 0
     22        headers, rows = csv.readFile(inputfile)
     23        for i in rows:
     24             s = Student(i)
     25             self.context[str(num)] = s
     26             num += 1
     27        return "%s new Students added in %s" % (num, t[0])
     28
     29class Export(grok.View):   
     30    def render(self):
     31        t = [0]
     32        result = []
     33        for s in self.context.values():
     34             result.append(s.getCsv())
     35        csv.writeFile(result)
     36        return "yeah %s" % t[0]
  • waeup/trunk/src/waeup/university/facultycontainer.py

    r3526 r3527  
    22from waeup.basecontainer import BaseContainer
    33from interfaces import IFaculty
     4from faculty import Faculty
    45
    56class FacultyContainer(BaseContainer):
    67   
    78    name = u'Faculties'
    8 
    9 class AddFaculty(grok.AddForm):
    10     form_fields = grok.AutoFields(IFaculty)
    11 
    12     @grok.action('Add Faculty')
    13     def addFaculty(self, name, *args, **kw):
    14         new_fac = Faculty(name=name)
    15         self.context[name] = new_fac
    16         self.redirect(self.url(new_fac))
     9    childClass = Faculty
Note: See TracChangeset for help on using the changeset viewer.