1 from django.db import models
2 from django.db.models import signals
3 from django.dispatch import dispatcher
6 INTERVAL_HELP_TEXT = 'examples: "1 hour", "14 days", "3 months", "DD:HH:MM:SS.ms"'
9 #PG_SCHEMAS = "actor, permission, public, config"
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()
21 list_display = ('name', 'description')
22 list_filter = ['parent_id']
23 search_fields = ['name', 'description']
27 verbose_name = 'User Group'
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()
39 db_table = 'org_unit_type'
40 verbose_name = 'Library Type'
42 list_display = ('name', 'depth')
43 list_filter = ['parent_id']
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)
53 list_display = ('org_unit_id', 'name', 'value')
54 search_fields = ['name', 'value']
55 list_filter = ['name', 'org_unit_id']
57 db_table = 'org_unit_setting'
58 ordering = ['org_unit_id', 'name']
59 verbose_name = 'Library Setting'
61 return "%s:%s=%s" % (self.org_unit_id.shortname, self.name, self.value)
64 class PermList(models.Model):
65 code = models.CharField(maxlength=100)
66 description = models.CharField(blank=True, maxlength=200)
68 list_display = ('code','description')
69 search_fields = ['code']
71 db_table = 'perm_list'
73 verbose_name = 'Permission'
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()
83 list_filter = ['grp_id']
84 list_display = ('perm_id', 'grp_id', 'depth_id')
86 db_table = 'grp_perm_map'
87 ordering = ['perm_id', 'grp_id']
88 verbose_name = 'Permission Setting'
90 return str(self.grp_id)+' -> '+str(self.perm_id)
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 :(
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)
103 return "%s (%s)" % ( str(self.card_id), str(self.usrname))
106 verbose_name = 'User'
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()
114 search_fields = ['usr_id', 'perm_id'] # we need text fields to search...
116 db_table = 'usr_perm_map'
117 verbose_name = 'User Permission'
119 return "%s -> %s" % ( str(self.usr_id), str(self.perm_id) )
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()
130 verbose_name = 'Card'
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)
148 search_fields = ['street1', 'city', 'post_code']
149 list_filter = ['org_unit_id']
150 list_display = ('street1', 'street2', 'city', 'county', 'state', 'post_code')
153 db_table = 'org_address'
154 verbose_name = 'Library Address'
156 return self.street1+' '+self.city+', '+self.state+' '+self.post_code
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)
175 search_fields = ['name', 'shortname']
176 list_display = ('shortname', 'name')
178 db_table = 'org_unit'
179 ordering = ['shortname']
180 verbose_name = 'Library'
182 return self.shortname
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()
192 search_fields = ['name']
193 list_display = ('name','extended','normal','shrt','max_renewals')
195 db_table = 'rule_circ_duration'
197 verbose_name = 'Circ Duration Rule'
202 class RuleMaxFine(models.Model):
203 name = models.CharField(maxlength=200)
204 amount = models.FloatField(max_digits=6, decimal_places=2)
206 search_fields = ['name']
207 list_display = ('name','amount')
209 db_table = 'rule_max_fine'
211 verbose_name = 'Circ Max Fine Rule'
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)
221 search_fields = ['name']
222 list_display = ('name','high', 'normal', 'low')
224 db_table = 'rule_recuring_fine'
226 verbose_name = 'Circ Recurring Fine Rule'
230 class IdentificationType(models.Model):
231 name = models.CharField(maxlength=200)
233 search_fields = ['name']
235 db_table = 'identification_type'
237 verbose_name = 'Identification Type'
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()
247 search_fields = ['name']
249 db_table = 'rule_age_hold_protect'
251 verbose_name = 'Hold Age Protection Rule'
255 class MetabibField(models.Model):
256 field_class_choices = (
258 ('author', 'Author'),
259 ('subject', 'Subject'),
260 ('series', 'Series'),
261 ('keyword', 'Keyword'),
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)
269 search_fields = ['name', 'format', 'field_class']
270 list_display = ('field_class', 'name', 'format')
272 db_table = 'metabib_field'
273 ordering = ['field_class', 'name']
274 verbose_name = 'Metabib Field'
279 # register the alternate DB
281 settings.OTHER_DATABASES['main_db']['MODELS'] = [
295 'IdentificationType',
296 'RuleAgeHoldProtect' ]