~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: me at id
  • Date: 2009-01-15 04:31:23 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1156
ivle.database: Add Subject, Semester and Offering.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import datetime
29
29
 
30
30
from storm.locals import create_database, Store, Int, Unicode, DateTime, \
31
 
                         Reference
 
31
                         Reference, Bool
32
32
 
33
33
import ivle.conf
34
34
import ivle.caps
35
35
 
 
36
def _kwarg_init(self, **kwargs):
 
37
    for k,v in kwargs.items():
 
38
        if k.startswith('_') or not hasattr(self, k):
 
39
            raise TypeError("%s got an unexpected keyword argument '%s'"
 
40
                % self.__class__.__name__, k)
 
41
        setattr(self, k, v)
 
42
 
36
43
def get_conn_string():
37
44
    """
38
45
    Returns the Storm connection string, generated from the conf file.
80
87
        self.rolenm = unicode(value)
81
88
    role = property(_get_role, _set_role)
82
89
 
83
 
    def __init__(self, **kwargs):
84
 
        """
85
 
        Create a new User object. Supply any columns as a keyword argument.
86
 
        """
87
 
        for k,v in kwargs.items():
88
 
            if k.startswith('_') or not hasattr(self, k):
89
 
                raise TypeError("User got an unexpected keyword argument '%s'"
90
 
                    % k)
91
 
            setattr(self, k, v)
 
90
    __init__ = _kwarg_init
92
91
 
93
92
    def __repr__(self):
94
93
        return "<%s '%s'>" % (type(self).__name__, self.login)
131
130
        login.
132
131
        """
133
132
        return store.find(cls, cls.login == unicode(login)).one()
 
133
 
 
134
class Subject(object):
 
135
    __storm_table__ = "subject"
 
136
 
 
137
    id = Int(primary=True, name="subjectid")
 
138
    code = Unicode(name="subj_code")
 
139
    name = Unicode(name="subj_name")
 
140
    short_name = Unicode(name="subj_short_name")
 
141
    url = Unicode()
 
142
 
 
143
    __init__ = _kwarg_init
 
144
 
 
145
    def __repr__(self):
 
146
        return "<%s '%s'>" % (type(self).__name__, self.short_name)
 
147
 
 
148
class Semester(object):
 
149
    __storm_table__ = "semester"
 
150
 
 
151
    id = Int(primary=True, name="semesterid")
 
152
    year = Unicode()
 
153
    semester = Unicode()
 
154
    active = Bool()
 
155
 
 
156
    __init__ = _kwarg_init
 
157
 
 
158
    def __repr__(self):
 
159
        return "<%s %s/%s>" % (type(self).__name__, self.year, self.semester)
 
160
 
 
161
class Offering(object):
 
162
    __storm_table__ = "offering"
 
163
 
 
164
    id = Int(primary=True, name="offeringid")
 
165
    subject_id = Int(name="subject")
 
166
    subject = Reference(subject_id, Subject.id)
 
167
    semester_id = Int(name="semesterid")
 
168
    semester = Reference(semester_id, Semester.id)
 
169
    groups_student_permissions = Unicode()
 
170
 
 
171
    __init__ = _kwarg_init
 
172
 
 
173
    def __repr__(self):
 
174
        return "<%s %r in %r>" % (type(self).__name__, self.subject,
 
175
                                  self.semester)