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

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

Adding and editing of all objects works now. Templates enhanced (not only for debugging). Still no tests. Added SVN-IDs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1# $Id: studentcontainer.py 3737 2008-10-26 19:14:17Z hraban $
2import grok
3import os
4#from waeup.interfaces import IBaseContainer
5import waeup.basecontainer as base
6from waeup.students.student import Student, fromCsv
7from waeup.students.interfaces import IStudentContainer
8from waeup.utils import importexport as csv
9
10
11class 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
21class 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
38class 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)
Note: See TracBrowser for help on using the repository browser.