]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/admin/ils_admin/setup/models.py
updated some of the models. added some signal callbacks for setting the postgres...
[Evergreen.git] / Open-ILS / admin / ils_admin / setup / models.py
1 from django.db import models
2 from django.db.models import signals
3 from django.dispatch import dispatcher
4
5 # Create your models here.
6
7 INTERVAL_HELP_TEXT = 'examples: "1 hour", "14 days", "3 months", "DD:HH:MM:SS.ms"'
8 PG_SCHEMAS = "actor, permission, public, config"
9
10
11 # ---------------------------------------------------------------------
12 # Here we run some SQL to manually set the postgres schema search-paths
13 # ---------------------------------------------------------------------
14 def setSearchPath():
15    from django.db import connection
16    cursor = connection.cursor()
17    print "SET search_path TO %s" % PG_SCHEMAS
18    cursor.execute("SET search_path TO %s" % PG_SCHEMAS)
19 dispatcher.connect(setSearchPath, signal=signals.class_prepared)
20 dispatcher.connect(setSearchPath, signal=signals.pre_init)
21
22
23 class GrpTree(models.Model):
24    name = models.CharField(maxlength=100)
25    parent_id = models.ForeignKey('self', null=True, related_name='children', db_column='parent')
26    description = models.CharField(blank=True, maxlength=200)
27    perm_interval = models.CharField(blank=True, maxlength=100, help_text=INTERVAL_HELP_TEXT)
28    application_perm = models.CharField(blank=True, maxlength=100)
29    usergroup = models.BooleanField()
30    class Admin:
31       list_display = ('name', 'description')
32       list_filter = ['parent_id']
33       search_fields = ['name', 'description']
34    class Meta:
35       db_table = 'grp_tree'
36       ordering = ['name']
37       verbose_name = 'User Group'
38    def __str__(self):
39       return self.name
40
41 class OrgUnitType(models.Model):
42    name = models.CharField(maxlength=100)
43    opac_label = models.CharField(maxlength=100)
44    depth = models.IntegerField()
45    parent_id = models.ForeignKey('self', null=True, related_name='children', db_column='parent')
46    can_have_vols = models.BooleanField()
47    can_have_users = models.BooleanField()
48    class Meta:
49       db_table = 'org_unit_type'
50       verbose_name = 'Library Type'
51    class Admin:
52       list_display = ('name', 'depth')
53       list_filter = ['parent_id']
54       ordering = ['depth']
55    def __str__(self):
56       return self.name
57
58 class PermList(models.Model):
59    code = models.CharField(maxlength=100)
60    description = models.CharField(blank=True, maxlength=200)
61    class Admin:
62       list_display = ('code','description')
63       search_fields = ['code']
64    class Meta:
65       db_table = 'perm_list'
66       ordering = ['code']
67       verbose_name = 'Permission'
68    def __str__(self):
69       return self.code
70
71 class GrpPermMap(models.Model):
72    grp_id = models.ForeignKey(GrpTree, db_column='grp')
73    perm_id = models.ForeignKey(PermList, db_column='perm')
74    depth_id = models.ForeignKey(OrgUnitType, to_field='depth', db_column='depth')
75    grantable = models.BooleanField()
76    class Admin:
77       list_filter = ['grp_id']
78       list_display = ('perm_id', 'grp_id', 'depth_id')
79    class Meta:
80       db_table = 'grp_perm_map'
81       ordering = ['perm_id', 'grp_id']
82       verbose_name = 'Permission Setting'
83    def __str__(self):
84       return str(self.grp_id)+' -> '+str(self.perm_id)
85
86
87
88 """ There's no way to do user-based mangling given the size of the data without custom handling.
89
90 class User(models.Model):
91    card_id = models.ForeignKey('Card', db_column='card')
92    profile_id = models.ForeignKey(GrpTree, db_column='profile')
93    usrname = models.CharField(blank=False, null=False, maxlength=200)
94    def __str__(self):
95       return "%s (%s)" % ( str(self.card_id), str(self.usrname))
96    class Meta:
97       db_table = 'usr'
98       verbose_name = 'User'
99
100 class UsrPermMap(models.Model):
101    usr_id = models.ForeignKey(User, db_column='usr')
102    perm_id = models.ForeignKey(PermList, db_column='perm')
103    depth_id = models.ForeignKey(OrgUnitType, to_field='depth', db_column='depth')
104    grantable = models.BooleanField()
105    class Admin:
106       search_fields = ['usr_id', 'perm_id']  # we need text fields to search...
107    class Meta:
108       db_table = 'usr_perm_map'
109       verbose_name = 'User Permission'
110    def __str__(self):
111       return "%s -> %s" % ( str(self.usr_id), str(self.perm_id) )
112
113
114 class Card(models.Model):
115    usr_id = models.ForeignKey(User, db_column='usr')
116    barcode = models.CharField(blank=False, null=False, maxlength=200)
117    active = models.BooleanField()
118    def __str__(self): 
119       return self.barcode
120    class Meta:
121       db_table = 'card'
122       verbose_name = 'Card'
123 """
124
125    
126
127
128 class OrgAddress(models.Model):
129    valid = models.BooleanField()
130    org_unit_id = models.ForeignKey('OrgUnit', db_column='org_unit')
131    address_type = models.CharField(blank=False, maxlength=200, default='MAILING')
132    street1 = models.CharField(blank=False, maxlength=200)
133    street2 = models.CharField(maxlength=200)
134    city = models.CharField(blank=False, maxlength=200)
135    county = models.CharField(maxlength=200)
136    state = models.CharField(blank=False, maxlength=200)
137    country = models.CharField(blank=False, maxlength=200)
138    post_code = models.CharField(blank=False, maxlength=200)
139    class Admin:
140       search_fields = ['street1', 'city', 'post_code']   
141       list_filter = ['org_unit_id']
142       list_display = ('street1', 'street2', 'city', 'county', 'state', 'post_code')
143    class Meta:
144       ordering = ['city']
145       db_table = 'org_address'
146       verbose_name = 'Library Address'
147    def __str__(self):
148       return self.street1+' '+self.city+', '+self.state+' '+self.post_code
149
150 class OrgUnit(models.Model):
151    parent_ou_id = models.ForeignKey('self', null=True, related_name='children', db_column='parent_ou')
152    ou_type_id = models.ForeignKey(OrgUnitType, db_column='ou_type')
153    shortname = models.CharField(maxlength=200)
154    name = models.CharField(maxlength=200)
155    email = models.EmailField(null=True, blank=True)
156    phone = models.CharField(maxlength=200, null=True, blank=True)
157    ill_address_id = models.ForeignKey(OrgAddress, db_column='ill_address', null=True, blank=True)
158    holds_address_id = models.ForeignKey(OrgAddress, db_column='holds_address', null=True, blank=True)
159    mailing_address_id = models.ForeignKey(OrgAddress, db_column='mailing_address', null=True, blank=True)
160    billing_address_id = models.ForeignKey(OrgAddress, db_column='billing_address', null=True, blank=True)
161    class Admin:
162       search_fields = ['name', 'shortname']
163       #list_filter = ['parent_ou_id'] # works, but shows all libs as options, so ruins the point
164       list_display = ('shortname', 'name')
165    class Meta:
166       db_table = 'org_unit'
167       ordering = ['shortname']
168       verbose_name = 'Library'
169    def __str__(self):
170       return self.shortname
171
172
173 class RuleCircDuration(models.Model):
174    name = models.CharField(maxlength=200)
175    extended = models.CharField(maxlength=200, help_text=INTERVAL_HELP_TEXT);
176    normal = models.CharField(maxlength=200, help_text=INTERVAL_HELP_TEXT);
177    shrt = models.CharField(maxlength=200, help_text=INTERVAL_HELP_TEXT);
178    max_renewals = models.IntegerField()
179    class Admin:
180       search_fields = ['name']
181       list_display = ('name','extended','normal','shrt','max_renewals')
182    class Meta:
183       db_table = 'rule_circ_duration'
184       ordering = ['name']
185       verbose_name = 'Circ Duration Rule'
186    def __str__(self):
187       return self.name
188
189
190 class RuleMaxFine(models.Model):
191    name = models.CharField(maxlength=200)
192    amount = models.FloatField(max_digits=6, decimal_places=2)
193    class Admin:
194       search_fields = ['name']
195       list_display = ('name','amount')
196    class Meta:
197       db_table = 'rule_max_fine'
198       ordering = ['name']
199       verbose_name = 'Circ Max Fine Rule'
200    def __str__(self):
201       return self.name
202
203 class RuleRecurringFine(models.Model):
204    name = models.CharField(maxlength=200)
205    high = models.FloatField(max_digits=6, decimal_places=2)
206    normal = models.FloatField(max_digits=6, decimal_places=2)
207    low = models.FloatField(max_digits=6, decimal_places=2)
208    class Admin:
209       search_fields = ['name']
210       list_display = ('name','high', 'normal', 'low')
211    class Meta:
212       db_table = 'rule_recuring_fine'
213       ordering = ['name']
214       verbose_name = 'Circ Recurring Fine Rule'
215    def __str__(self):
216       return self.name
217
218 class IdentificationType(models.Model):
219    name = models.CharField(maxlength=200)
220    class Admin:
221       search_fields = ['name']
222    class Meta:
223       db_table = 'identification_type'
224       ordering = ['name']
225       verbose_name = 'Identification Type'
226    def __str__(self):
227       return self.name
228
229
230 class RuleAgeHoldProtect(models.Model):
231    name = models.CharField(maxlength=200)
232    age = models.CharField(blank=True, maxlength=100, help_text=INTERVAL_HELP_TEXT)
233    prox = models.IntegerField()
234    class Admin:
235       search_fields = ['name']
236    class Meta:
237       db_table = 'rule_age_hold_protect'
238       ordering = ['name']
239       verbose_name = 'Hold Age Protection Rule'
240    def __str__(self):
241       return self.name
242