I think the problem is in the app models, which I have attached below.

Apologies for the lengthy post.

Note the print statements at the end of db.py.  Those statements do
not
execute until I attempt to use the database administration link on the
admin/default/design page.  Is that normal?

## db.py, stripped of comments #####################################
# -*- coding: utf-8 -*-
db = DAL('postgres://<redacted>)
response.generic_patterns = ['*'] if request.is_local else []
from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db, hmac_key=Auth.get_or_create_key())
crud, service, plugins = Crud(db), Service(), PluginManager()

crud.settings.update_deletable = False

## This is in place of request_tenant
## It's how I used to handle tenants and I'm comfortable with it
## Old dog, new tricks :)
db.define_table('org',
                Field('name', length=64),
                Field('created_on', 'datetime', default=request.now),
                Field('created_by', 'integer'),
                Field('updated_on', 'datetime', default=request.now),
                Field('updated_by', 'integer'),
                Field('is_active', 'boolean', default=True),
                singular='Organization',
                plural='Organizations',
               )
db.org.is_active.readable  = db.org.is_active.writable = False
db.org.created_on.readable = db.org.created_on.writable = False
db.org.created_by.readable = db.org.created_by.writable = False
db.org.updated_on.readable = db.org.updated_on.writable = False
db.org.updated_by.readable = db.org.updated_by.writable = False

db.define_table(
      'auth_user',
      Field('first_name', length=128, default='', label='First name',
            required=True, comment=SPAN('Required',
_style='color:orange;')),
      Field('middle_name', length=128, default='', label='Middle
name'),
      Field('last_name', length=128, default='', label='Last name'),
      Field('generation', length=16, default='', label='Generation'),
      Field('address', length=128, default=''),
      Field('address_2', length=128, default=''),
      Field('city', length=32, default=''),
      Field('state', length=32, default=''),
      Field('zip', length=12, default=''),
      Field('email', length=128, default='', unique=True),
      Field('password', 'password', length=512,
         writable=False, readable=False, label='Password'),
      Field('registration_key', length=512,
         writable=False, readable=False, default=''),
      Field('reset_password_key', length=512,
         writable=False, readable=False, default=''),
      Field('registration_id', length=512,
         writable=False, readable=False, default=''),
      Field('land_line', length=32, default=''),
      Field('mobile', length=32, default=''),
      Field('fax', length=32, default=''),
      Field('created_on', 'datetime', default=request.now),
      Field('created_by', 'integer'),
      Field('updated_on', 'datetime', default=request.now),
      Field('updated_by', 'integer'),
      Field('is_active', 'boolean', default=True),
      Field('org_link', db.org, ),
      format='%(first_name)s %(middle_name)s %(last_name)s %
(generation)s'
      )
db.auth_user.first_name.requires = \
      IS_NOT_EMPTY(error_message='First name is required')
db.auth_user.last_name.requires = \
      IS_NOT_EMPTY(error_message='Last name is required')
db.auth_user.password.requires = [IS_STRONG(), CRYPT()]
db.auth_user.email.requires = [IS_EMPTY_OR(
      [IS_EMAIL(error_message=auth.messages.invalid_email),
      IS_NOT_IN_DB(db, 'auth_user.email')])]
db.auth_user.org_link.requires = IS_IN_DB(db, 'org.id',
                                             '%(name)s',
                                             zero= "Choose")
db.auth_user.is_active.readable  = db.auth_user.is_active.writable =
False
db.auth_user.created_on.readable = db.auth_user.created_on.writable =
False
db.auth_user.created_by.readable = db.auth_user.created_by.writable =
False
db.auth_user.updated_on.readable = db.auth_user.updated_on.writable =
False
db.auth_user.updated_by.readable = db.auth_user.updated_by.writable =
False
db.auth_user.org_link.readable   = db.auth_user.org_link.writable =
False

auth.define_tables()

if hasattr(session, 'auth') and hasattr(session.auth, 'user'):
    db.org.created_by.default = session.auth.user.id
else:
    db.org.created_by.default = 1

mail=auth.settings.mailer
mail.settings.server = 'logging' or 'smtp.gmail.com:587'
mail.settings.sender = '[email protected]'
mail.settings.login = 'username:password'

auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

print 'hello, world'
print BEAUTIFY(session)

################################################################################
# Application tables file name is e.py
#
##############################################################################
## The error shows up around line 116
## The following four lines are not normally commented out
##if hasattr(auth, 'user') and auth.user is not None:
##    org_link_default = auth.user.org_link
##else:
##    org_link_default = None

## This line is an attempted work-around.  It does not help
org_link_default = 1

signature = db.Table(
    db, 'signature',
    Field('org_link', db.org, default=org_link_default,
          requires = IS_IN_DB(db, db.org.id, '%(name)s'),
          readable = False,
          writable = False)
)


db.define_table('contractor',
                Field('name', length=128),
                Field('address', length=128),
                Field('address_2', length=128),
                Field('city', length=32),
                Field('state', length=32),
                Field('zip', length=16),
                Field('land_line', length=16),
                Field('mobile', length=16),
                Field('fax', length=16),
                Field('email', length=128),
                Field('service_area', length=256),
                Field('needs_workers_comp', 'boolean'),
                Field('has_workers_comp', 'boolean'),
                Field('workers_comp_expires', 'date'),
                Field('has_liability', 'boolean'),
                Field('liability_expires', 'date'),
                auth.signature,
                signature,
                format = '%(name)s'
               )

db.define_table('contractor_types',
                Field('contractor_type', length=128),
                signature,
                auth.signature,
                format = '%(contractor_type)s',
               )

db.define_table('contractor_contractor_type',
                Field('contractor_id', db.contractor),
                Field('contractor_types_id', db.contractor_types),
                signature,
                auth.signature,
               )
db.contractor_contractor_type.contractor_id.requires = IS_IN_DB(
    db, 'contractor.id',) #(name)s', zero='Choose a contractor.')
db.contractor_contractor_type.contractor_types_id.requires = IS_IN_DB(
    db, 'contractor_types.id') #, '%(contractor_type)s', zero='Choose
a type.')

db.define_table('contractor_contacts',
                Field('contractor_id', db.contractor),
                Field('user_id', db.auth_user)
               )
db.contractor_contacts.contractor_id.requires = IS_IN_DB(
    db, 'contractor.id', '%(name)s', zero = 'Choose a contractor')
db.contractor_contacts.user_id.requires = IS_IN_DB(
    db, 'auth_user.id', '%(first_name)s %(middle_name)s %(last_name)s %
(generation)s',
    zero = 'Choose')

db.define_table('property',
                Field('address', length=128),
                Field('address_2', length=128),
                Field('city', length=32),
                Field('state', length=32),
                Field('zip', length=16),
                signature,
                auth.signature,
                format= '%(address)s %(address_2)s',
                singular= 'Property',
                plural='Properties',
               )

db.define_table('lease',
                Field('property_id', db.property),
                Field('rent', 'decimal(9,2)'),
                Field('lease_end', 'date'),
                signature,
                auth.signature,
               )

db.define_table('user_types',
                Field('user_type', length=32, required=True,
notnull=True),
                signature,
                auth.signature,
               )

db.define_table('property_associates',
                Field('property_id', db.property),
                Field('associate_id', db.auth_user),
                Field('association_type', length=32),
                signature,
                auth.signature,
                format= '%(association_type)s',
               )

db.define_table('property_user',
                Field('property_id', db.property),
                Field('user_id', db.auth_user),
                Field('user_type', db.user_types),
                signature,
                auth.signature,
               )
## The following ref to session.auth.user.org_link causes an error
query = ((db.property.is_active==True) &
         (db.property.org_link==session.auth.user.org_link))
db.property_user.property_id.requires=IS_IN_DB(
    db(query), 'property.id', '%(address)s %address_2)s',
    zero = 'Choose a property')
query = ((db.auth_user.is_active==True) &
         (db.auth_user.org_link==session.auth.user.org_link))
db.property_user.user_id.requires=IS_IN_DB(
    db(query), 'auth_user.id',
    '%(first_name)s, %(middle_name)s, %(last_name)s, %(generation)s',
    zero = 'Choose a user')
query=(
    (db.user_types.is_active==True) &
    ((db.user_types.org_link==1) |
     (db.user_types.org_link==session.auth.user.org_link))
)
db.property_user.user_type.requires=IS_IN_DB(
    db(query), 'user_type.id', '%(user_type)s',
    zero = 'Select a type')

db.define_table('lease_user',
                Field('lease_id', db.lease),
                Field('user_id', db.auth_user),
                signature,
                auth.signature,
               )

db.define_table('user_roles',
                Field('user_role', length=32),
                Field('user_id', db.auth_user),
                signature,
                auth.signature,
               )
query = ((db.auth_user.is_active==True) &
         (db.auth_user.org_link==session.auth.user.org_link))
db.user_roles.user_id.requires = IS_IN_DB(
    db(query), 'auth_user.id',
    '%(first_name)s, %(middle_name)s, %(last_name)s, %(generation)s',
    zero = 'Choose a user')

db.define_table('landlord_types',
                Field('landlord_id', db.auth_user),
                Field('landlord_type', length=16)
               )
query = ((db.auth_user.is_active==True) &
         (db.auth_user.org_link==session.auth.user.org_link))
db.landlord_types.landlord_id.requires = IS_IN_DB(
    db(query),
    'auth_user.id', '%(first_name)s %(middle_name)s %(last_name)s %
(generation)s')

db.define_table('scheduling_method',
                Field('name', length=32),
                Field('comment', 'text',),
                signature,
                auth.signature,
                format = '%(name)s',
               )

db.define_table('standard_tasks',
                Field('name', length=64),
                Field('scheduling_method', length=32),
                signature,
                auth.signature,
               )

On Jan 27, 10:56 am, Massimo Di Pierro <[email protected]>
wrote:
> Can you login into the welcome app? How about admin? Is this problem
> specific of one app?
>
> On Jan 27, 6:00 am, Cliff <[email protected]> wrote:
>
>
>
>
>
>
>
> > Before the problem I was using port 8010.  The day the problem started
> > I used port 8000.  But I've changed ports before without problem.
>
> > There was also a kernel upgrade, but I can't imagine that would cause
> > this.
>
> > Version 1.99.4 from the start.  Checked permissions.  Cleared browser
> > cache, cookies and remembered passwords.
>
> > Changed session repository from file to db with
> > "session.connect(request, response, db)"
>
> > Problem still there this AM.  No session file when using a file
> > repository, no record in the db when using the db repository.
>
> > Any more ideas?
>
> > On Jan 26, 10:11 pm, Bruno Rocha <[email protected]> wrote:
>
> > > web2py version was updated?
>
> > > permission to /sessions have changed?
>
> > > try to clean your browser cache, cookies etc and test again
>
> > > On Thu, Jan 26, 2012 at 11:55 PM, Cliff <[email protected]> wrote:
> > > > My application was working yesterday.  I was able to log in and test.
>
> > > > Today, Web2py is not writing a session file.  Looking in the sessions
> > > > directory, I have a session file dated the 17th and one dated
> > > > yesterday.
>
> > > > No session file dated today, though I am able to log in to the app.
>
> > > > The app gives me a ticket when it tries to execute my models, because
> > > > I set certain field defaults based on session values.
>
> > > > Here is the traceback:
>
> > > > Traceback (most recent call last):
> > > >  File "/home/cjk/svpy/gluon/restricted.py", line 204, in restricted
> > > >    exec ccode in environment
> > > >  File "/home/cjk/svpy/applications/sv/models/e.py", line 147, in
> > > > <module>
> > > >    (db.property.org_link==session.auth.user.org_link))
> > > > AttributeError: 'NoneType' object has no attribute 'user'
>
> > > > Anybody got a clue what's going on?
>
> > > --
>
> > > Bruno Rocha
> > > [http://rochacbruno.com.br]

Reply via email to