]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/admin/ils_admin/setup/models.py
bug fix (global replace) and better function name for Mike's sanity :)
[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     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)
20
21
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()
29     class Admin:
30         list_display = ('name', 'description')
31         list_filter = ['parent_id']
32         search_fields = ['name', 'description']
33     class Meta:
34         db_table = 'grp_tree'
35         ordering = ['name']
36         verbose_name = 'User Group'
37     def __str__(self):
38         return self.name
39
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()
47     class Meta:
48         db_table = 'org_unit_type'
49         verbose_name = 'Library Type'
50     class Admin:
51         list_display = ('name', 'depth')
52         list_filter = ['parent_id']
53         ordering = ['depth']
54     def __str__(self):
55         return self.name
56
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)
61     class Admin:
62         list_display = ('org_unit_id', 'name', 'value')
63         search_fields = ['name', 'value']
64         list_filter = ['name', 'org_unit_id']
65     class Meta:
66         db_table = 'org_unit_setting'
67         ordering = ['org_unit_id', 'name']
68         verbose_name = 'Library Setting'
69     def __str__(self):
70         return "%s:%s=%s" % (self.org_unit_id.shortname, self.name, self.value)
71
72
73 class PermList(models.Model):
74     code = models.CharField(maxlength=100)
75     description = models.CharField(blank=True, maxlength=200)
76     class Admin:
77         list_display = ('code','description')
78         search_fields = ['code']
79     class Meta:
80         db_table = 'perm_list'
81         ordering = ['code']
82         verbose_name = 'Permission'
83     def __str__(self):
84         return self.code
85
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()
91     class Admin:
92         list_filter = ['grp_id']
93         list_display = ('perm_id', 'grp_id', 'depth_id')
94     class Meta:
95         db_table = 'grp_perm_map'
96         ordering = ['perm_id', 'grp_id']
97         verbose_name = 'Permission Setting'
98     def __str__(self):
99         return str(self.grp_id)+' -> '+str(self.perm_id)
100
101
102
103
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 :(
106
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)
111    def __str__(self):
112       return "%s (%s)" % ( str(self.card_id), str(self.usrname))
113    class Meta:
114       db_table = 'usr'
115       verbose_name = 'User'
116
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()
122    class Admin:
123       search_fields = ['usr_id', 'perm_id']  # we need text fields to search...
124    class Meta:
125       db_table = 'usr_perm_map'
126       verbose_name = 'User Permission'
127    def __str__(self):
128       return "%s -> %s" % ( str(self.usr_id), str(self.perm_id) )
129
130
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()
135    def __str__(self): 
136       return self.barcode
137    class Meta:
138       db_table = 'card'
139       verbose_name = 'Card'
140 """
141
142    
143
144
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)
156     class Admin:
157         search_fields = ['street1', 'city', 'post_code']   
158         list_filter = ['org_unit_id']
159         list_display = ('street1', 'street2', 'city', 'county', 'state', 'post_code')
160     class Meta:
161         ordering = ['city']
162         db_table = 'org_address'
163         verbose_name = 'Library Address'
164     def __str__(self):
165         return self.street1+' '+self.city+', '+self.state+' '+self.post_code
166
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)
183     class Admin:
184         search_fields = ['name', 'shortname']
185         list_display = ('shortname', 'name')
186     class Meta:
187         db_table = 'org_unit'
188         ordering = ['shortname']
189         verbose_name = 'Library'
190     def __str__(self):
191         return self.shortname
192
193
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()
200     class Admin:
201         search_fields = ['name']
202         list_display = ('name','extended','normal','shrt','max_renewals')
203     class Meta:
204         db_table = 'rule_circ_duration'
205         ordering = ['name']
206         verbose_name = 'Circ Duration Rule'
207     def __str__(self):
208         return self.name
209
210
211 class RuleMaxFine(models.Model):
212     name = models.CharField(maxlength=200)
213     amount = models.FloatField(max_digits=6, decimal_places=2)
214     class Admin:
215         search_fields = ['name']
216         list_display = ('name','amount')
217     class Meta:
218         db_table = 'rule_max_fine'
219         ordering = ['name']
220         verbose_name = 'Circ Max Fine Rule'
221     def __str__(self):
222         return self.name
223
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)
229     class Admin:
230         search_fields = ['name']
231         list_display = ('name','high', 'normal', 'low')
232     class Meta:
233         db_table = 'rule_recuring_fine'
234         ordering = ['name']
235         verbose_name = 'Circ Recurring Fine Rule'
236     def __str__(self):
237         return self.name
238
239 class IdentificationType(models.Model):
240     name = models.CharField(maxlength=200)
241     class Admin:
242         search_fields = ['name']
243     class Meta:
244         db_table = 'identification_type'
245         ordering = ['name']
246         verbose_name = 'Identification Type'
247     def __str__(self):
248         return self.name
249
250
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()
255     class Admin:
256         search_fields = ['name']
257     class Meta:
258         db_table = 'rule_age_hold_protect'
259         ordering = ['name']
260         verbose_name = 'Hold Age Protection Rule'
261     def __str__(self):
262         return self.name
263
264 class MetabibField(models.Model):
265     field_class_choices = (
266         ('title', 'Title'),
267         ('author', 'Author'),
268         ('subject', 'Subject'),
269         ('series', 'Series'),
270         ('keyword', 'Keyword'),
271     )
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)
277     class Admin:
278         search_fields = ['name', 'format', 'field_class']
279         list_display = ('field_class', 'name', 'format')
280     class Meta:
281         db_table = 'metabib_field'
282         ordering = ['field_class', 'name']
283         verbose_name = 'Metabib Field'
284     def __str__(self):
285         return self.name
286
287