1 from django.db import models
2 from django.db.models import signals
3 from django.dispatch import dispatcher
5 # Create your models here.
7 INTERVAL_HELP_TEXT = 'examples: "1 hour", "14 days", "3 months", "DD:HH:MM:SS.ms"'
8 PG_SCHEMAS = "actor, permission, public, config"
11 # ---------------------------------------------------------------------
12 # Here we run some SQL to manually set the postgres schema search-paths
13 # ---------------------------------------------------------------------
15 from django.db import connection
16 cursor = connection.cursor()
17 cursor.execute("SET search_path TO %s" % PG_SCHEMAS)
18 dispatcher.connect(setSearchPath, signal=signals.class_prepared)
19 dispatcher.connect(setSearchPath, signal=signals.pre_init)
22 class GrpTree(models.Model):
23 name = models.CharField(maxlength=100)
24 parent_id = models.ForeignKey('self', null=True, related_name='children', db_column='parent')
25 description = models.CharField(blank=True, maxlength=200)
26 perm_interval = models.CharField(blank=True, maxlength=100, help_text=INTERVAL_HELP_TEXT)
27 application_perm = models.CharField(blank=True, maxlength=100)
28 usergroup = models.BooleanField()
30 list_display = ('name', 'description')
31 list_filter = ['parent_id']
32 search_fields = ['name', 'description']
36 verbose_name = 'User Group'
40 class OrgUnitType(models.Model):
41 name = models.CharField(maxlength=100)
42 opac_label = models.CharField(maxlength=100)
43 depth = models.IntegerField()
44 parent_id = models.ForeignKey('self', null=True, related_name='children', db_column='parent')
45 can_have_vols = models.BooleanField()
46 can_have_users = models.BooleanField()
48 db_table = 'org_unit_type'
49 verbose_name = 'Library Type'
51 list_display = ('name', 'depth')
52 list_filter = ['parent_id']
57 class OrgUnitSetting(models.Model):
58 org_unit_id = models.ForeignKey('OrgUnit', db_column='org_unit')
59 name = models.CharField(maxlength=200)
60 value = models.CharField(maxlength=200)
62 list_display = ('org_unit_id', 'name', 'value')
63 search_fields = ['name', 'value']
64 list_filter = ['name', 'org_unit_id']
66 db_table = 'org_unit_setting'
67 ordering = ['org_unit_id', 'name']
68 verbose_name = 'Library Setting'
70 return "%s:%s=%s" % (self.org_unit_id.shortname, self.name, self.value)
73 class PermList(models.Model):
74 code = models.CharField(maxlength=100)
75 description = models.CharField(blank=True, maxlength=200)
77 list_display = ('code','description')
78 search_fields = ['code']
80 db_table = 'perm_list'
82 verbose_name = 'Permission'
86 class GrpPermMap(models.Model):
87 grp_id = models.ForeignKey(GrpTree, db_column='grp')
88 perm_id = models.ForeignKey(PermList, db_column='perm')
89 depth_id = models.ForeignKey(OrgUnitType, to_field='depth', db_column='depth')
90 grantable = models.BooleanField()
92 list_filter = ['grp_id']
93 list_display = ('perm_id', 'grp_id', 'depth_id')
95 db_table = 'grp_perm_map'
96 ordering = ['perm_id', 'grp_id']
97 verbose_name = 'Permission Setting'
99 return str(self.grp_id)+' -> '+str(self.perm_id)
104 """ There's no way to do user-based mangling given the size of the data without custom handling.
105 When you try to create a new permission map, it tries to load all users into a dropdown selector :(
107 class User(models.Model):
108 card_id = models.ForeignKey('Card', db_column='card')
109 profile_id = models.ForeignKey(GrpTree, db_column='profile')
110 usrname = models.CharField(blank=False, null=False, maxlength=200)
112 return "%s (%s)" % ( str(self.card_id), str(self.usrname))
115 verbose_name = 'User'
117 class UsrPermMap(models.Model):
118 usr_id = models.ForeignKey(User, db_column='usr')
119 perm_id = models.ForeignKey(PermList, db_column='perm')
120 depth_id = models.ForeignKey(OrgUnitType, to_field='depth', db_column='depth')
121 grantable = models.BooleanField()
123 search_fields = ['usr_id', 'perm_id'] # we need text fields to search...
125 db_table = 'usr_perm_map'
126 verbose_name = 'User Permission'
128 return "%s -> %s" % ( str(self.usr_id), str(self.perm_id) )
131 class Card(models.Model):
132 usr_id = models.ForeignKey(User, db_column='usr')
133 barcode = models.CharField(blank=False, null=False, maxlength=200)
134 active = models.BooleanField()
139 verbose_name = 'Card'
145 class OrgAddress(models.Model):
146 valid = models.BooleanField()
147 org_unit_id = models.ForeignKey('OrgUnit', db_column='org_unit')
148 address_type = models.CharField(blank=False, maxlength=200, default='MAILING')
149 street1 = models.CharField(blank=False, maxlength=200)
150 street2 = models.CharField(maxlength=200)
151 city = models.CharField(blank=False, maxlength=200)
152 county = models.CharField(maxlength=200)
153 state = models.CharField(blank=False, maxlength=200)
154 country = models.CharField(blank=False, maxlength=200)
155 post_code = models.CharField(blank=False, maxlength=200)
157 search_fields = ['street1', 'city', 'post_code']
158 list_filter = ['org_unit_id']
159 list_display = ('street1', 'street2', 'city', 'county', 'state', 'post_code')
162 db_table = 'org_address'
163 verbose_name = 'Library Address'
165 return self.street1+' '+self.city+', '+self.state+' '+self.post_code
167 class OrgUnit(models.Model):
168 parent_ou_id = models.ForeignKey('self', null=True, related_name='children', db_column='parent_ou')
169 ou_type_id = models.ForeignKey(OrgUnitType, db_column='ou_type')
170 shortname = models.CharField(maxlength=200)
171 name = models.CharField(maxlength=200)
172 email = models.EmailField(null=True, blank=True)
173 phone = models.CharField(maxlength=200, null=True, blank=True)
174 opac_visible = models.BooleanField(blank=True)
175 ill_address_id = models.ForeignKey(OrgAddress,
176 db_column='ill_address', related_name='ill_addresses', null=True, blank=True)
177 holds_address_id = models.ForeignKey(OrgAddress,
178 db_column='holds_address', related_name='holds_addresses', null=True, blank=True)
179 mailing_address_id = models.ForeignKey(OrgAddress,
180 db_column='mailing_address', related_name='mailing_addresses', null=True, blank=True)
181 billing_address_id = models.ForeignKey(OrgAddress,
182 db_column='billing_address', related_name='billing_addresses', null=True, blank=True)
184 search_fields = ['name', 'shortname']
185 list_display = ('shortname', 'name')
187 db_table = 'org_unit'
188 ordering = ['shortname']
189 verbose_name = 'Library'
191 return self.shortname
194 class RuleCircDuration(models.Model):
195 name = models.CharField(maxlength=200)
196 extended = models.CharField(maxlength=200, help_text=INTERVAL_HELP_TEXT);
197 normal = models.CharField(maxlength=200, help_text=INTERVAL_HELP_TEXT);
198 shrt = models.CharField(maxlength=200, help_text=INTERVAL_HELP_TEXT);
199 max_renewals = models.IntegerField()
201 search_fields = ['name']
202 list_display = ('name','extended','normal','shrt','max_renewals')
204 db_table = 'rule_circ_duration'
206 verbose_name = 'Circ Duration Rule'
211 class RuleMaxFine(models.Model):
212 name = models.CharField(maxlength=200)
213 amount = models.FloatField(max_digits=6, decimal_places=2)
215 search_fields = ['name']
216 list_display = ('name','amount')
218 db_table = 'rule_max_fine'
220 verbose_name = 'Circ Max Fine Rule'
224 class RuleRecurringFine(models.Model):
225 name = models.CharField(maxlength=200)
226 high = models.FloatField(max_digits=6, decimal_places=2)
227 normal = models.FloatField(max_digits=6, decimal_places=2)
228 low = models.FloatField(max_digits=6, decimal_places=2)
230 search_fields = ['name']
231 list_display = ('name','high', 'normal', 'low')
233 db_table = 'rule_recuring_fine'
235 verbose_name = 'Circ Recurring Fine Rule'
239 class IdentificationType(models.Model):
240 name = models.CharField(maxlength=200)
242 search_fields = ['name']
244 db_table = 'identification_type'
246 verbose_name = 'Identification Type'
251 class RuleAgeHoldProtect(models.Model):
252 name = models.CharField(maxlength=200)
253 age = models.CharField(blank=True, maxlength=100, help_text=INTERVAL_HELP_TEXT)
254 prox = models.IntegerField()
256 search_fields = ['name']
258 db_table = 'rule_age_hold_protect'
260 verbose_name = 'Hold Age Protection Rule'
264 class MetabibField(models.Model):
265 field_class_choices = (
267 ('author', 'Author'),
268 ('subject', 'Subject'),
269 ('series', 'Series'),
270 ('keyword', 'Keyword'),
272 field_class = models.CharField(maxlength=200, choices=field_class_choices, null=False, blank=False)
273 name = models.CharField(maxlength=200, null=False, blank=False)
274 xpath = models.TextField(null=False, blank=False)
275 weight = models.IntegerField(null=False, blank=False)
276 format = models.CharField(maxlength=200, null=False, blank=False)
278 search_fields = ['name', 'format', 'field_class']
279 list_display = ('field_class', 'name', 'format')
281 db_table = 'metabib_field'
282 ordering = ['field_class', 'name']
283 verbose_name = 'Metabib Field'