[open-ils-commits] r774 - in servres/branches/eg-schema-experiment/conifer: . syrup (gfawcett)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Feb 8 21:21:17 EST 2010
Author: gfawcett
Date: 2010-02-08 21:21:16 -0500 (Mon, 08 Feb 2010)
New Revision: 774
Modified:
servres/branches/eg-schema-experiment/conifer/settings.py
servres/branches/eg-schema-experiment/conifer/syrup/admin.py
servres/branches/eg-schema-experiment/conifer/syrup/models.py
Log:
Create Syrup model tables in a 'reserves' schema, just because we can.
This is still the 'classic' Syrup database model; we haven't made any
changes here vis-a-vis Robin's model. I've simply used explicit
db_table naming and our custom backend to put the Syrup tables in a
'reserves' schema.
I've also moved the default Django tables (users, groups, etc.) into a
'django' schema. This leaves 'public' empty. Note that I didn't do
this by setting explicit db_table values for the Django tables, but
rather by putting 'django' at the head of the search_path in
settings.py.
Modified: servres/branches/eg-schema-experiment/conifer/settings.py
===================================================================
--- servres/branches/eg-schema-experiment/conifer/settings.py 2010-02-09 02:21:13 UTC (rev 773)
+++ servres/branches/eg-schema-experiment/conifer/settings.py 2010-02-09 02:21:16 UTC (rev 774)
@@ -17,7 +17,7 @@
MANAGERS = ADMINS
DATABASE_ENGINE = 'conifer.evergreen.backends.postgresql_with_schemas'
-DATABASE_PG_SCHEMAS = ['public','actor','asset','config','permission','reserves']
+DATABASE_PG_SCHEMAS = ['django','actor','asset','config','permission','reserves']
DATABASE_NAME = 'robin' # Or path to database file if using sqlite3.
DATABASE_USER = 'postgres' # Not used with sqlite3.
DATABASE_PASSWORD = 'XXX' # Not used with sqlite3.
Modified: servres/branches/eg-schema-experiment/conifer/syrup/admin.py
===================================================================
--- servres/branches/eg-schema-experiment/conifer/syrup/admin.py 2010-02-09 02:21:13 UTC (rev 773)
+++ servres/branches/eg-schema-experiment/conifer/syrup/admin.py 2010-02-09 02:21:16 UTC (rev 774)
@@ -5,7 +5,7 @@
import django.db.models
from conifer.syrup.models import *
-for m in [LibraryUnit, ServiceDesk, Member, Department, Course, Term, UserProfile, NewsItem,
+for m in [Member, Department, Course, Term, UserProfile, NewsItem,
Target, PhysicalObject]:
admin.site.register(m)
Modified: servres/branches/eg-schema-experiment/conifer/syrup/models.py
===================================================================
--- servres/branches/eg-schema-experiment/conifer/syrup/models.py 2010-02-09 02:21:13 UTC (rev 773)
+++ servres/branches/eg-schema-experiment/conifer/syrup/models.py 2010-02-09 02:21:16 UTC (rev 774)
@@ -12,7 +12,23 @@
import random
from django.utils import simplejson
from conifer.middleware import genshi_locals
+from django.conf import settings
+try:
+ import markdown
+ def do_markdown(txt):
+ return markdown.markdown(txt)
+except ImportError:
+ def do_markdown(txt):
+ return _('(Markdown not installed).')
+
+
+# SCHEMAS: True if our database is being stored in a
+# multi-schema Postgres database.
+
+SCHEMAS = (settings.DATABASE_ENGINE == 'conifer.evergreen.backends.postgresql_with_schemas')
+
+
def highlight(text, phrase,
highlighter='<strong class="highlight">\\1</strong>'):
''' This may be a lame way to do this, but will want to highlight matches somehow
@@ -64,6 +80,10 @@
class UserProfile(m.Model):
+
+ class Meta:
+ db_table = 'reserves.user_profile' if SCHEMAS else 'reserves_user_profile'
+
user = m.ForeignKey(User, unique=True)
home_phone = m.CharField(max_length=100, blank=True)
home_address = m.TextField(blank=True)
@@ -75,7 +95,7 @@
wants_email_notices = m.BooleanField(default=False)
last_email_notice = m.DateTimeField(default=datetime.now,
blank=True, null=True)
-
+
def __unicode__(self):
return 'UserProfile(%s)' % self.user
@@ -106,31 +126,15 @@
if user:
return user
-#----------------------------------------------------------------------
-# LIBRARIES, SERVICE DESKS
-class LibraryUnit(m.Model):
- name = m.CharField(max_length=100)
- nickname = m.CharField(max_length=15,blank=True,default='')
- url = m.URLField()
- contact_email = m.EmailField()
-
- def __unicode__(self):
- return self.name
-
-class ServiceDesk(m.Model):
- library = m.ForeignKey(LibraryUnit)
- abbreviation = m.CharField(max_length=8,db_index=True)
- name = m.CharField(max_length=100)
- active = m.BooleanField(default=True)
-
- def __unicode__(self):
- return self.name
-
#----------------------------------------------------------------------
# TERMS, COURSES, MEMBERSHIP
class Term(m.Model):
+
+ class Meta:
+ db_table = 'reserves.term' if SCHEMAS else 'reserves_term'
+
code = m.CharField(max_length=16, blank=True, null=True, unique=True)
name = m.CharField(max_length=255)
start = m.DateField('Start (Y-M-D)')
@@ -140,6 +144,10 @@
return self.code or self.name
class Department(m.Model):
+
+ class Meta:
+ db_table = 'reserves.department' if SCHEMAS else 'reserves_department'
+
abbreviation = m.CharField(max_length=8,db_index=True)
name = m.CharField(max_length=255)
active = m.BooleanField(default=True)
@@ -149,6 +157,10 @@
class Course(m.Model):
"""An offering of a course."""
+
+ class Meta:
+ db_table = 'reserves.course' if SCHEMAS else 'reserves_course'
+
# some courses may be ad-hoc and have no code.
code = m.CharField(max_length=64, blank=True, null=True)
department = m.ForeignKey(Department)
@@ -314,8 +326,10 @@
return course_sections.sections_tuple_delimiter.join(section).encode('base64').strip()
class Member(m.Model):
+
class Meta:
unique_together = (('course', 'user'))
+ db_table = 'reserves.member' if SCHEMAS else 'reserves_member'
course = m.ForeignKey(Course)
user = m.ForeignKey(User)
@@ -355,6 +369,9 @@
A reserve item, physical or electronic, as it appears in a given
course instance.
"""
+
+ class Meta:
+ db_table = 'reserves.item' if SCHEMAS else 'reserves_item'
# Structure
@@ -537,9 +554,13 @@
metadata_attribute_choices = metadata_attributes.items()
metadata_attribute_choices.sort(key=lambda (a,b): b)
+
class Metadata(m.Model):
"""Metadata for items."""
+ class Meta:
+ db_table = 'reserves.metadata' if SCHEMAS else 'reserves_metadata'
+
item = m.ForeignKey(Item)
#fixme, arbitrary sizes.
name = m.CharField('Attribute', max_length=128, choices=metadata_attribute_choices)
@@ -548,15 +569,11 @@
#------------------------------------------------------------
# News items
-try:
- import markdown
- def do_markdown(txt):
- return markdown.markdown(txt)
-except ImportError:
- def do_markdown(txt):
- return _('(Markdown not installed).')
+class NewsItem(m.Model):
-class NewsItem(m.Model):
+ class Meta:
+ db_table = 'reserves.news_item' if SCHEMAS else 'reserves_news_item'
+
subject = m.CharField(max_length=200)
body = m.TextField()
published = m.DateTimeField(default=datetime.now, blank=True, null=True)
@@ -581,6 +598,10 @@
# Z39.50 Support
class Target(m.Model):
+
+ class Meta:
+ db_table = 'reserves.target' if SCHEMAS else 'reserves_target'
+
name = m.CharField(max_length=100)
host = m.CharField(max_length=50)
db = m.CharField(max_length=50)
@@ -597,6 +618,9 @@
class CheckInOut(m.Model):
"""A log of checkout-to-patron and item-return events."""
+ class Meta:
+ db_table = 'reserves.check_inout' if SCHEMAS else 'reserves_check_inout'
+
is_checkout = m.BooleanField() # in or out?
is_successful = m.BooleanField() # did the transaction work?
staff = m.ForeignKey(User) # who processed the request?
@@ -610,6 +634,10 @@
class PhysicalObject(m.Model):
"""A record of a physical object entering and leaving the Reserves area."""
+
+ class Meta:
+ db_table = 'reserves.physical_object' if SCHEMAS else 'reserves_physical_object'
+
barcode = m.CharField(max_length=100) # item barcode
receiver = m.ForeignKey(User, related_name='receiver') # who received the item?
received = m.DateTimeField(auto_now_add=True)
More information about the open-ils-commits
mailing list