This application has quite but of code; 5-10 python source files; and
an equal number of kid files.

Here's the controller.py as a start!  Do you want/need more??

=======================

import logging
import cherrypy
from datetime import datetime

import turbogears
from turbogears import (controllers, expose, validate, redirect,
                                                                                
        widgets, validators, error_handler)
from research import json
from string import digits
import os,sys

from model import *
from researchforms import *
from historyservice import *
from sendEmail import send_mime_msg
import export2csv as csv

# log = logging.getLogger("research.controllers")

DEBUG = True              # Print debug/trace statements (e.g.
functions/methods entered and their parameters,
                                                                                
#        db query strings, etc.)
VERBOSE = False        # Pring out MUCH more details (e.g. returned
results from db queries)

class Root(controllers.RootController):
        def __init__(self):
                super(controllers.RootController,self).__init__()
                self.sandboxID = None
                self.sandbox_data = None
                self.raw_version = ''

        @expose(template="research.templates.index")
        @error_handler(index)
        @validate(form=select_sandboxid_form)
        def index(self,*args,**kwargs):
                if VERBOSE:
                        print '\nStarting "Index"'
                        print '       args =',args,
                        print '       kwargs =', kwargs
                        print '\n'

                self.homedir = os.getcwd()
                if isinstance(self.sandbox_data, sandbox_data):
                        self.sandbox_data.closeDB()
                options = get_sandbox_options()
                if DEBUG: print 'Sandbox options values =', options
                return
dict(form=select_sandboxid_form,values=dict(sandboxID=options) ,
                                                        
action='/sandbox/metadata')

        @expose(template="research.templates.enter_sandbox_data")
        def enter_sandbox_data(self, *args, **kwargs):
                if VERBOSE:
                        print '\nStarting "enter_sandbox_data...'
                        print '       args =',args
                        print '       kwargs =', kwargs
                        print '\n'
                sd=sandboxes.get(self.sandboxID)
                return dict(form=enter_sandbox_data_form, values=sd, action='/
set_sandbox_data',
                                                        title='Enter Sandbox 
Data', id=self.sandboxID)

        @expose()
        def set_sandbox_data(self,**kwargs):
                if VERBOSE:
                        print '\nStarting "set_sandbox_data...'
                        print '       kwargs =', kwargs
                        print '\n'
                self.md.update_metadata(**kwargs)
                raise redirect('/sandbox')

        @expose(template="research.templates.sandbox")
        def sandbox(self, *args, **kwargs):
                if VERBOSE:
                        print '\n ==> Entering the sandbox method..'
                        try: print "     +++ received args:",args
                        except NameError: pass
                        try: print "     +++ kwargs:", kwargs
                        except (NameError, KeyError): pass
                        print '\n'

                if args and args[0] == "metadata":
                        try:
                                if kwargs['sandboxID'] == None:
                                        turbogears.flash("You did not select a 
sandbox!")
                                        raise redirect("/index")
                        except KeyError:
                                turbogears.flash("You did not select a 
sandbox!")
                                raise redirect("/index")
                        self.sandboxID = kwargs['sandboxID']
                        self.sandbox_data = sandbox_data(self.sandboxID)
                        self.md=get_sandbox_metadata(self.sandboxID)
                        sh_desc = self.md.short_description.lower()
                        if (sh_desc.find('unused') > -1):
                                self.md.short_description=""
                                self.md.full_description=""
                                self.md.researcher_name=''
                                self.md.researcher_email=''
                                raise redirect("/enter_sandbox_data")

                        raise redirect("/sandbox")

                #elif args and args[0]=='load_history':
                        #print "\n==> Received request to load history"
                        #for key in kwargs:
                                #print '\t %s = %s' % (key, kwargs[key])
                        #print '\n'

                return dict(metadata=self.md)

        @expose(template="research.templates.select_scores")
        def select_raw_scores(self,*args,**kwargs):
                if DEBUG:
                        print '\nStarting "select_raw_scores"'
                        print '       args =',args,
                        print '       kwargs =', kwargs
                        print '\n'
                if kwargs=={}:
                        clients_list = get_raw_clients()
                        return dict(title="RawScores", 
form1=select_rawscoreclients_form,
                                                                
action1='/select_raw_scores',
options1=dict(rawScoreClients=clients_list),
        
size1=dict(rawScoreClients=min(len(clients_list),RAW_CLIENTS_FIELD_SIZE)),
                                                                
form2='',form3='')
                if kwargs['field'] == "clients":
                        self.new_raw_clients = kwargs['rawScoreClients']
                        if type(self.new_raw_clients) is not ListType:
                                self.new_raw_clients = [self.new_raw_clients]
                        if DEBUG: print '\n The list of RawScore clients = %s' %
self.new_raw_clients
                        participant_list =
get_raw_participants(clients=self.new_raw_clients)
                        return dict(title="RawScores", 
form1=select_rawscoreclients_form,
                                                        action1='',
options1=dict(rawScoreClients=self.new_raw_clients),
        
size1=dict(rawScoreClients=min(len(self.new_raw_clients),RAW_CLIENTS_FIELD_SIZE)),
                                                        
form2=select_rawscoreparticipants_form, action2='/
select_raw_scores',
                                                        
options2=dict(rawScoreParticipants=participant_list),
        
size2=dict(rawScoreParticipants=min(len(participant_list),RAW_PARTICIPANTS_FIELD_SIZE)),
                                                        form3='')
                elif kwargs['field'] == "participants":
                        self.new_raw_participants = 
kwargs['rawScoreParticipants']
                        if type(self.new_raw_participants) is not ListType:
                                self.new_raw_participants = 
[self.new_raw_participants]
                        if DEBUG: print 'The list of RawScore participants = %s 
\nfor
clients %s'  % (self.new_raw_participants,self.new_raw_clients)
                        version_list =  
get_raw_versions(clients=self.new_raw_clients,
participants=self.new_raw_participants)
                        if DEBUG: print '\twith the available versions %s' % 
version_list
                        #
                        # if there are NOT multiple versions for this 
client/participant
pair, we MAY be done querying the user:
                        #
                        if len(version_list) == 1 :
                                #
                                # if this is NOT the 1st time we've loaded 
rawScores AND  the
version for the requested
                                # client/participant does NOT match; Notify the 
user.
                                #
                                if DEBUG: print '\ntesting received version 
list <%s> with
previous <%s>' % (version_list, self.md.rawscores_type)
                                if (self.md.rawscores_type.strip() != '' and 
version_list.strip() !
= self.md.rawscores_type.strip()):
                                        if DEBUG: print 'Attempting to mix 
versions:  requested version =
%s; existing  vers = %s' % (version_list, self.md.rawscores_type)
                                        turbogears.flash("You cannot mix 
rawScore types in this
sandbox!!!!")
                                        raise redirect('/sandbox')
                                else:
                                        self.raw_version = version_list
                        else:
                                #
                                # the selected client/participants have 
multiple versions.
                                # If this first time we're loading RawScores, 
query user for
preferenct
                                #
                                if self.md.rawscores_type == '':
                                        return dict(title="RawScores",
form1=select_rawscoreclients_form,
                                                                        
action1='',
options1=dict(rawScoreClients=self.new_raw_clients),
        
size1=dict(rawScoreClients=min(len(self.new_raw_clients),RAW_CLIENTS_FIELD_SIZE)),
                                                                        
form2=select_rawscoreparticipants_form, action2='/
select_raw_scores',
        
options2=dict(rawScoreParticipants=self.new_raw_participants),
        
size2=dict(rawScoreParticipants=min(len(self.new_raw_participants),RAW_PARTICIPANTS_FIELD_SIZE)),
                                                                        
form3=select_rawscoreversion_form, action3='/
select_raw_scores',
                                                                        
options3=dict(rawScoreVersions=version_list))
                                else:
                                        try:
                                                if 
(version_list.index(self.md.rawscores_type) >= 0):
                                                        self.raw_version = 
self.md.rawscores_type
                                        except ValueError:
                                                if DEBUG: print 'Cannot mix 
versions:  requested version = %s;
existing  vers = %s' % (version_list, self.md.rawscores_type)
                                                turbogears.flash("The selected 
selected RawScores do match
already loaded scores!!!!")
                                                raise redirect('/sandbox')

                elif kwargs['field'] == 'versions':
                        self.raw_version = kwargs['rawScoreVersion']

                raise redirect('/get_history_data/' + kwargs['hst_src'])

        @expose(template="research.templates.select_scores")
        def select_dimension_scores(self,*args,**kwargs):
                if DEBUG:
                        print '\nStarting "select_dimension_scores"'
                        print '       args =',args,
                        print '       kwargs =', kwargs
                        print '\n'
                if kwargs=={}:
                        clients_list = get_dim_clients()
                        return
dict(title="DimensionScores",form1=select_dimensionscoreclients_form,
action1='/select_dimension_scores',
                                                                
options1=dict(dimScoreClients=get_dim_clients),
        
size1=dict(dimScoreClients=min(len(clients_list),DIM_CLIENTS_FIELD_SIZE)),
                                                                form2='', 
form3='')

                if kwargs['field'] == 'clients':
                        self.new_dim_clients = kwargs['dimScoreClients']
                        if type(self.new_dim_clients) is not ListType:
                                self.new_dim_clients = [self.new_dim_clients]
                        if DEBUG: print "\n The list of new clients = %s" %
self.new_dim_clients
                        participant_list =
get_dim_participants(clients=self.new_dim_clients)
                        if DEBUG: print "   The list of new clients now = %s" %
self.new_dim_clients
                        return
dict(title="DimensionScores",form1=select_dimensionscoreclients_form,
action1='/select_dimension_scores',
                                                                
options1=dict(dimScoreClients=self.new_dim_clients),
        
size1=dict(dimScoreClients=min(len(self.new_dim_clients),DIM_CLIENTS_FIELD_SIZE)),
                                                                
form2=select_dimensionscoreparticipants_form, action2='/
select_dimension_scores',
                                                                
options2=dict(dimScoreParticipants=participant_list),
        
size2=dict(dimScoreParticipants=min(len(participant_list),DIM_PARTICIPANTS_FIELD_SIZE)),
                                                                form3 = '')
                elif kwargs['field'] == 'participants':
                                self.new_dim_participants = 
kwargs['dimScoreParticipants']
                                if type(self.new_dim_participants) == 
StringType:
                                        self.new_dim_participants = 
[self.new_dim_participants]
                                raise redirect 
('/get_history_data/'+kwargs['hst_src'])

        @expose(template="research.templates.select_scores")
        def select_fitness_scores(self,*args,**kwargs):
                return dict(form1=select_fitnessscoreclients_form, action1='/
get_history_data',
                                                        form2='', form3='',
                                                        title="FitnessScores")

        @expose()
        def get_history_data(self,*args,**kwargs):
                if DEBUG:
                        print '\nStarting "get_history_data"'
                        print '       args =',args,
                        print '       kwargs =', kwargs
                        print '\n'
                data_src = args[0]
                if VERBOSE: print "Fetching %s data from History Service" % 
data_src
                if data_src == "DimensionScores":
                        hst_docs = hstsvc.get_ScoresHistory(hst_src=data_src,
                                                                                
Clients = self.new_dim_clients,
                                                                                
Participants = self.new_dim_participants)
                elif data_src == "RawScores":
                        hst_docs = hstsvc.get_ScoresHistory(hst_src=data_src,
                                                                                
Clients=self.new_raw_clients,
                                                                                
Participants=self.new_raw_participants,
                                                                                
Version=self.raw_version)
                elif data_src == "FitnessScores":
                        hst_docs = hstsvc.get_ScoresHistory(hst_src=data_src,
                                                                                
Clients=self.new_fit_clients,
                                                                                
Pas=self.new_fit_pas,
                                                                                
Participants=self.new_fit_participants)
                #
                # If we got a list back, it is the XML docs retrieved
                #
                if isinstance(hst_docs,list):
                        if VERBOSE: print 'Received %d XML documents' % 
len(hst_docs)
                        for d in hst_docs:
                                status = self.sandbox_data.putDocument(d)
                                if (status.find('<Error') >= 0):
                                        print "***Could Not save the document 
-- Error msg = %s" % status

                else:
                        if VERBOSE: print '***No data returned -- 
status:',hst_docs

                raise redirect('/sandbox')

        @expose()
        def default(self, *args, **kwargs):
                return 'The "%s" page is not ready.' % args[0]

        @expose()
        def reinit_sandbox(self, *args, **kwargs):
                if DEBUG:
                        print '\nEntering "reinit_sandbox...'
                        print '       args =', args, '       kwargs =', kwargs
                        print '\n'

                data_set = args[0]
                if (data_set == 'all'):
                        self.sandbox_data.reset()
                        self.md.reset('all')
                        raise redirect('/index')
                elif ((data_set == 'rawscores') or (data_set == 
'dimensionscores')
or (data_set == 'fitnessscores')):
                        self.sandbox_data.erase_container(data_set)
                        self.md.reset(data_set)
                else:
                        print '*** Unrecognized data_set received by 
sandbox_reinit: "%s"'
% data_set

                raise redirect('/sandbox')

        @expose()
        def csv_export(self):
                """
                Export contents of dbxml sandbox to csv -- one file for each
                xml document found.  Results will be mailed to the user
                """
                csv_dir = os.path.join(os.getcwd(), 'tmp')
                if not os.path.isdir(csv_dir): os.mkdir(csv_dir)

                rawscores = self.sandbox_data.getRawScores()
                if type(rawscores) is list:
                        raw_csv = csv.csvRawScores()
                        csvfile_name = os.path.join(csv_dir,'raw_scores.csv')
                        for xml in rawscores:
                                raw_csv.extractData(xml)
                        raw_csv.write(csvfile_name)
                else:
                        if (rawscores == 0):
                                print 'No rawScores loaded'
                        else:
                                print 'Error getting RawScores'

                dimscores = self.sandbox_data.getDimensionScores()
                if type(dimscores) is list:
                        dim_csv = csv.csvDimensionScores()
                        csvfile_name = 
os.path.join(csv_dir,'dimension_scores.csv')
                        for xml in dimscores:
                                dim_csv.extractData(xml)
                        dim_csv.write(csvfile_name)
                else:
                        if (dimscores == 0):
                                print 'No DimensionScores loaded'
                        else:
                                print 'Error getting DimensionScores'

                fitscores = self.sandbox_data.getFitnessScores()
                if type(fitscores) is list:
                        fit_csv = csv.csvFitnessScores()
                        csvfile_name = 
os.path.join(csv_dir,'fitness_scores.csv')
                        for xml in fitscores:
                                fit_csv.extractData(xml)
                        fit_csv.write(csvfile_name)
                else:
                        if (fitscores == 0):
                                print 'No FitnessScores loaded'
                        else:
                                print 'Error getting FitnessScores'

                recpt_list = [self.md.researcher_email]
                attachments = csv_dir + os.sep + '*.csv'
                send_mime_msg(toaddrlist= recpt_list,
                                                                        
fromaddr='[EMAIL PROTECTED]',
                                                                        
attachmentpatty=attachments)
                raise redirect('/sandbox')

On May 24, 4:18 pm, "Alaa Salman" <[EMAIL PROTECTED]> wrote:
> There seems to be something wrong in your code.
> Please paste the code so that we can take a look.
>
> Regards,
> Alaa Salman
>
> On 5/25/07, Denny <[EMAIL PROTECTED]> wrote:
>
>
>
> > I suddenly got the below traceback when I attempted to browse to my
> > application's main page.
>
> > I'm sure I've done something wrong, but I can't find ANY references to
> > my code in this traceback!!  Can someone give me a clue???
>
> > When I run  start-application.py that seems to go OK,  this traceback
> > happens when I browse tohttp://localhost:8080
>
> > thanks,
> >   Denny
>
> > ============================
>
> > 2007-05-24 15:43:20,664 cherrypy.msg INFO HTTP: Serving HTTP on
> >http://localhost:8080/
> > 2007-05-24 15:43:41,504 cherrypy.msg INFO HTTP: Page handler: <bound
> > method Root.index of <research.controllers.Root object at 0x418a6bcc>>
> > Traceback (most recent call last):
> >   File "/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/
> > cherrypy/_cphttptools.py", line 105, in _run
> >     self.main()
> >   File "/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/
> > cherrypy/_cphttptools.py", line 254, in main
> >     body = page_handler(*virtual_path, **self.params)
> >   File "<string>", line 3, in index
> >   File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/
> > turbogears/controllers.py", line 334, in expose
> >     output = database.run_with_transaction(
> >   File "<string>", line 5, in run_with_transaction
> >   File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/
> > turbogears/database.py", line 302, in so_rwt
> >     retval = func(*args, **kw)
> >   File "<string>", line 5, in _expose
> >   File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/
> > turbogears/controllers.py", line 351, in <lambda>
> >     mapping, fragment, args, kw)))
> >   File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/
> > turbogears/controllers.py", line 378, in _execute_func
> >     output = errorhandling.try_call(func, *args, **kw)
> >   File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/
> > turbogears/errorhandling.py", line 73, in try_call
> >     return func(self, *args, **kw)
> >   File "<string>", line 3, in index
> >   File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/
> > turbogears/controllers.py", line 173, in validate
> >     return errorhandling.run_with_errors(errors, func, *args, **kw)
> >   File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/
> > turbogears/errorhandling.py", line 108, in run_with_errors
> >     return dispatch_error(self, func, errors, None, *args, **kw)
> >   File "<string>", line 5, in dispatch_error
> >   File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/
> > turbogears/errorhandling.py", line 63, in adaptor
> >     args, kw, 1)
> >   File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/
> > turbogears/util.py", line 215, in inject_args
> >     args, kw = inject_arg(func, argname, argval, args, kw, start)
> >   File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/
> > turbogears/util.py", line 201, in inject_arg
> >     argnames, defaults = getargspec(func)[::3]
> >   File "/usr/lib/python2.4/inspect.py", line 670, in getargspec
> >     raise TypeError('arg is not a Python function')
> > TypeError: arg is not a Python function
> > Request Headers:
> >   Content-Length:
> >   ACCEPT-CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> >   USER-AGENT: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.11)
> > Gecko/20070327 Ubuntu/dapper-security Firefox/1.5.0.11
> >   CONNECTION: keep-alive
> >   HOST: localhost:8080
> >   ACCEPT: text/xml,application/xml,application/xhtml+xml,text/
> > html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> >   Remote-Addr: 127.0.0.1
> >   ACCEPT-LANGUAGE: en-us,en;q=0.5
> >   Content-Type:
> >   Remote-Host: 127.0.0.1
> >   ACCEPT-ENCODING: gzip,deflate
> >   KEEP-ALIVE: 300
> > 127.0.0.1 - - "GET / HTTP/1.1" 500 3262 "" "Mozilla/5.0 (X11; U; Linux
> > i686; en-US; rv:1.8.0.11) Gecko/20070327 Ubuntu/dapper-security
> > Firefox/1.5.0.11"


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to