]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/admin/ils_admin/setup/ils_data/models.py
changed file layout and settings file to support the django multiple-database layout...
[Evergreen.git] / Open-ILS / admin / ils_admin / setup / ils_data / models.py
1 from django.db import models
2 from django.db.models import signals
3 from django.dispatch import dispatcher
4
5 # ?i18n?
6 INTERVAL_HELP_TEXT = 'examples: "1 hour", "14 days", "3 months", "DD:HH:MM:SS.ms"'
7
8
9 #PG_SCHEMAS = "actor, permission, public, config"
10
11
12
13 class GrpTree(models.Model):
14     name = models.CharField(maxlength=100)
15     parent_id = models.ForeignKey('self', null=True, related_name='children', db_column='parent')
16     description = models.CharField(blank=True, maxlength=200)
17     perm_interval = models.CharField(blank=True, maxlength=100, help_text=INTERVAL_HELP_TEXT)
18     application_perm = models.CharField(blank=True, maxlength=100)
19     usergroup = models.BooleanField()
20     class Admin:
21         list_display = ('name', 'description')
22         list_filter = ['parent_id']
23         search_fields = ['name', 'description']
24     class Meta:
25         db_table = 'grp_tree'
26         ordering = ['name']
27         verbose_name = 'User Group'
28     def __str__(self):
29         return self.name
30
31 class OrgUnitType(models.Model):
32     name = models.CharField(maxlength=100)
33     opac_label = models.CharField(maxlength=100)
34     depth = models.IntegerField()
35     parent_id = models.ForeignKey('self', null=True, related_name='children', db_column='parent')
36     can_have_vols = models.BooleanField()
37     can_have_users = models.BooleanField()
38     class Meta:
39         db_table = 'org_unit_type'
40         verbose_name = 'Library Type'
41     class Admin:
42         list_display = ('name', 'depth')
43         list_filter = ['parent_id']
44         ordering = ['depth']
45     def __str__(self):
46         return self.name
47
48 class OrgUnitSetting(models.Model):
49     org_unit_id = models.ForeignKey('OrgUnit', db_column='org_unit')
50     name = models.CharField(maxlength=200)
51     value = models.CharField(maxlength=200)
52     class Admin:
53         list_display = ('org_unit_id', 'name', 'value')
54         search_fields = ['name', 'value']
55         list_filter = ['name', 'org_unit_id']
56     class Meta:
57         db_table = 'org_unit_setting'
58         ordering = ['org_unit_id', 'name']
59         verbose_name = 'Library Setting'
60     def __str__(self):
61         return "%s:%s=%s" % (self.org_unit_id.shortname, self.name, self.value)
62
63
64 class PermList(models.Model):
65     code = models.CharField(maxlength=100)
66     description = models.CharField(blank=True, maxlength=200)
67     class Admin:
68         list_display = ('code','description')
69         search_fields = ['code']
70     class Meta:
71         db_table = 'perm_list'
72         ordering = ['code']
73         verbose_name = 'Permission'
74     def __str__(self):
75         return self.code
76
77 class GrpPermMap(models.Model):
78     grp_id = models.ForeignKey(GrpTree, db_column='grp')
79     perm_id = models.ForeignKey(PermList, db_column='perm')
80     depth_id = models.ForeignKey(OrgUnitType, to_field='depth', db_column='depth')
81     grantable = models.BooleanField()
82     class Admin:
83         list_filter = ['grp_id']
84         list_display = ('perm_id', 'grp_id', 'depth_id')
85     class Meta:
86         db_table = 'grp_perm_map'
87         ordering = ['perm_id', 'grp_id']
88         verbose_name = 'Permission Setting'
89     def __str__(self):
90         return str(self.grp_id)+' -> '+str(self.perm_id)
91
92
93
94
95 """ There's no way to do user-based mangling given the size of the data without custom handling.
96       When you try to create a new permission map, it tries to load all users into a dropdown selector :(
97
98 class User(models.Model):
99    card_id = models.ForeignKey('Card', db_column='card')
100    profile_id = models.ForeignKey(GrpTree, db_column='profile')
101    usrname = models.CharField(blank=False, null=False, maxlength=200)
102    def __str__(self):
103       return "%s (%s)" % ( str(self.card_id), str(self.usrname))
104    class Meta:
105       db_table = 'usr'
106       verbose_name = 'User'
107
108 class UsrPermMap(models.Model):
109    usr_id = models.ForeignKey(User, db_column='usr')
110    perm_id = models.ForeignKey(PermList, db_column='perm')
111    depth_id = models.ForeignKey(OrgUnitType, to_field='depth', db_column='depth')
112    grantable = models.BooleanField()
113    class Admin:
114       search_fields = ['usr_id', 'perm_id']  # we need text fields to search...
115    class Meta:
116       db_table = 'usr_perm_map'
117       verbose_name = 'User Permission'
118    def __str__(self):
119       return "%s -> %s" % ( str(self.usr_id), str(self.perm_id) )
120
121
122 class Card(models.Model):
123    usr_id = models.ForeignKey(User, db_column='usr')
124    barcode = models.CharField(blank=False, null=False, maxlength=200)
125    active = models.BooleanField()
126    def __str__(self): 
127       return self.barcode
128    class Meta:
129       db_table = 'card'
130       verbose_name = 'Card'
131 """
132
133    
134
135
136 class OrgAddress(models.Model):
137     valid = models.BooleanField()
138     org_unit_id = models.ForeignKey('OrgUnit', db_column='org_unit')
139     address_type = models.CharField(blank=False, maxlength=200, default='MAILING')
140     street1 = models.CharField(blank=False, maxlength=200)
141     street2 = models.CharField(maxlength=200)
142     city = models.CharField(blank=False, maxlength=200)
143     county = models.CharField(maxlength=200)
144     state = models.CharField(blank=False, maxlength=200)
145     country = models.CharField(blank=False, maxlength=200)
146     post_code = models.CharField(blank=False, maxlength=200)
147     class Admin:
148         search_fields = ['street1', 'city', 'post_code']   
149         list_filter = ['org_unit_id']
150         list_display = ('street1', 'street2', 'city', 'county', 'state', 'post_code')
151     class Meta:
152         ordering = ['city']
153         db_table = 'org_address'
154         verbose_name = 'Library Address'
155     def __str__(self):
156         return self.street1+' '+self.city+', '+self.state+' '+self.post_code
157
158 class OrgUnit(models.Model):
159     parent_ou_id = models.ForeignKey('self', null=True, related_name='children', db_column='parent_ou')
160     ou_type_id = models.ForeignKey(OrgUnitType, db_column='ou_type')
161     shortname = models.CharField(maxlength=200)
162     name = models.CharField(maxlength=200)
163     email = models.EmailField(null=True, blank=True)
164     phone = models.CharField(maxlength=200, null=True, blank=True)
165     opac_visible = models.BooleanField(blank=True)
166     ill_address_id = models.ForeignKey(OrgAddress, 
167         db_column='ill_address', related_name='ill_addresses', null=True, blank=True)
168     holds_address_id = models.ForeignKey(OrgAddress, 
169         db_column='holds_address', related_name='holds_addresses', null=True, blank=True)
170     mailing_address_id = models.ForeignKey(OrgAddress, 
171         db_column='mailing_address', related_name='mailing_addresses', null=True, blank=True)
172     billing_address_id = models.ForeignKey(OrgAddress, 
173         db_column='billing_address', related_name='billing_addresses', null=True, blank=True)
174     class Admin:
175         search_fields = ['name', 'shortname']
176         list_display = ('shortname', 'name')
177     class Meta:
178         db_table = 'org_unit'
179         ordering = ['shortname']
180         verbose_name = 'Library'
181     def __str__(self):
182         return self.shortname
183
184
185 class RuleCircDuration(models.Model):
186     name = models.CharField(maxlength=200)
187     extended = models.CharField(maxlength=200, help_text=INTERVAL_HELP_TEXT);
188     normal = models.CharField(maxlength=200, help_text=INTERVAL_HELP_TEXT);
189     shrt = models.CharField(maxlength=200, help_text=INTERVAL_HELP_TEXT);
190     max_renewals = models.IntegerField()
191     class Admin:
192         search_fields = ['name']
193         list_display = ('name','extended','normal','shrt','max_renewals')
194     class Meta:
195         db_table = 'rule_circ_duration'
196         ordering = ['name']
197         verbose_name = 'Circ Duration Rule'
198     def __str__(self):
199         return self.name
200
201
202 class RuleMaxFine(models.Model):
203     name = models.CharField(maxlength=200)
204     amount = models.FloatField(max_digits=6, decimal_places=2)
205     class Admin:
206         search_fields = ['name']
207         list_display = ('name','amount')
208     class Meta:
209         db_table = 'rule_max_fine'
210         ordering = ['name']
211         verbose_name = 'Circ Max Fine Rule'
212     def __str__(self):
213         return self.name
214
215 class RuleRecurringFine(models.Model):
216     name = models.CharField(maxlength=200)
217     high = models.FloatField(max_digits=6, decimal_places=2)
218     normal = models.FloatField(max_digits=6, decimal_places=2)
219     low = models.FloatField(max_digits=6, decimal_places=2)
220     class Admin:
221         search_fields = ['name']
222         list_display = ('name','high', 'normal', 'low')
223     class Meta:
224         db_table = 'rule_recuring_fine'
225         ordering = ['name']
226         verbose_name = 'Circ Recurring Fine Rule'
227     def __str__(self):
228         return self.name
229
230 class IdentificationType(models.Model):
231     name = models.CharField(maxlength=200)
232     class Admin:
233         search_fields = ['name']
234     class Meta:
235         db_table = 'identification_type'
236         ordering = ['name']
237         verbose_name = 'Identification Type'
238     def __str__(self):
239         return self.name
240
241
242 class RuleAgeHoldProtect(models.Model):
243     name = models.CharField(maxlength=200)
244     age = models.CharField(blank=True, maxlength=100, help_text=INTERVAL_HELP_TEXT)
245     prox = models.IntegerField()
246     class Admin:
247         search_fields = ['name']
248     class Meta:
249         db_table = 'rule_age_hold_protect'
250         ordering = ['name']
251         verbose_name = 'Hold Age Protection Rule'
252     def __str__(self):
253         return self.name
254
255 class MetabibField(models.Model):
256     field_class_choices = (
257         ('title', 'Title'),
258         ('author', 'Author'),
259         ('subject', 'Subject'),
260         ('series', 'Series'),
261         ('keyword', 'Keyword'),
262     )
263     field_class = models.CharField(maxlength=200, choices=field_class_choices, null=False, blank=False)
264     name = models.CharField(maxlength=200, null=False, blank=False)
265     xpath = models.TextField(null=False, blank=False)
266     weight = models.IntegerField(null=False, blank=False)
267     format = models.CharField(maxlength=200, null=False, blank=False)
268     class Admin:
269         search_fields = ['name', 'format', 'field_class']
270         list_display = ('field_class', 'name', 'format')
271     class Meta:
272         db_table = 'metabib_field'
273         ordering = ['field_class', 'name']
274         verbose_name = 'Metabib Field'
275     def __str__(self):
276         return self.name
277
278
279 # register the alternate DB
280 """
281 settings.OTHER_DATABASES['main_db']['MODELS'] = [
282     'GrpTree',
283     'OrgUnitType',
284     'OrgUnitSetting',
285     'PermList',
286     'GrpPermMap',
287     'User',
288     'UsrPermMap',
289     'Card',
290     'OrgAddress',
291     'OrgUnit',
292     'RuleCircDuration',
293     'RuleMaxFine',
294     'RuleRecurringFine',
295     'IdentificationType',
296     'RuleAgeHoldProtect' ]
297 """
298