source: waeup/branches/hraban/src/waeup/students/studentcontainer.py @ 3557

Last change on this file since 3557 was 3557, checked in by hraban, 16 years ago

display viewlets work, forms don't

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1import grok
2import os
3from waeup.basecontainer import BaseContainer
4from student import Student, fromCsv
5from waeup.utils import importexport as csv
6
7class StudentContainer(BaseContainer):
8    """
9    The node containing the student models
10    """
11    name = u"Students"
12    childClass = Student
13    specialActions = [u"import", u"export"]   
14
15class Import(grok.View):
16    def render(self):
17        #XXX TODO: Make import form to choose csv-file
18        t = [0]
19        src = os.path.join(os.path.dirname(__file__), '..', 'tests',
20                           'TestData','Students.csv')
21        inputfile = file(src, "r")
22        num = 0
23        headers, rows = csv.readFile(inputfile)
24        for i in rows:
25             s = fromCsv(i)
26             self.context[str(num)] = s
27             num += 1
28             if num > 100:
29                 break
30        return "%s new Students added in %s" % (num, t[0])
31
32class Export(grok.View):   
33    def render(self):
34        #XXX TODO: Make export form to choose csv-file
35        t = [0]
36        result = []
37        for s in self.context.values():
38             result.append(s.getCsv())
39        csv.writeFile(result)
40        return "yeah %s" % t[0]
Note: See TracBrowser for help on using the repository browser.