1 | # $Id: studentcontainer.py 3737 2008-10-26 19:14:17Z hraban $ |
---|
2 | import grok |
---|
3 | import os |
---|
4 | #from waeup.interfaces import IBaseContainer |
---|
5 | import waeup.basecontainer as base |
---|
6 | from waeup.students.student import Student, fromCsv |
---|
7 | from waeup.students.interfaces import IStudentContainer |
---|
8 | from waeup.utils import importexport as csv |
---|
9 | |
---|
10 | |
---|
11 | class StudentContainer(base.BaseContainer): |
---|
12 | """ |
---|
13 | The node containing the student models |
---|
14 | """ |
---|
15 | grok.implements(IStudentContainer) |
---|
16 | id = 'students' |
---|
17 | name = u"Students" |
---|
18 | childClass = Student |
---|
19 | specialActions = [u'import', u'export', u'search'] |
---|
20 | |
---|
21 | class Import(grok.View): |
---|
22 | def render(self): |
---|
23 | #XXX TODO: Make import form to choose csv-file |
---|
24 | t = [0] |
---|
25 | src = os.path.join(os.path.dirname(__file__), '..', 'tests', |
---|
26 | 'TestData','Students.csv') |
---|
27 | inputfile = file(src, "r") |
---|
28 | num = 0 |
---|
29 | headers, rows = csv.readFile(inputfile) |
---|
30 | for i in rows: |
---|
31 | s = fromCsv(i) |
---|
32 | self.context[str(num)] = s |
---|
33 | num += 1 |
---|
34 | if num > 100: |
---|
35 | break |
---|
36 | return "%s new Students added in %s" % (num, t[0]) |
---|
37 | |
---|
38 | class Export(grok.View): |
---|
39 | def render(self): |
---|
40 | #XXX TODO: Make export form to choose csv-file |
---|
41 | t = [0] |
---|
42 | result = [] |
---|
43 | for s in self.context.values(): |
---|
44 | result.append(s.getCsv()) |
---|
45 | csv.writeFile(result) |
---|
46 | return "yeah %s" % t[0] |
---|
47 | |
---|
48 | #class AddForm(base.AddForm): |
---|
49 | # form_fields = grok.AutoFields(Student) |
---|
50 | # |
---|
51 | #class EditForm(base.EditForm): |
---|
52 | # form_fields = grok.AutoFields(Student) |
---|
53 | |
---|
54 | |
---|
55 | #class Edit(base.EditViewlet): |
---|
56 | # grok.context(IStudentContainer) |
---|
57 | # |
---|
58 | # |
---|
59 | #class Add(base.AddViewlet): |
---|
60 | # grok.context(IStudentContainer) |
---|