Hi,  I'm new to working with Turbogears2 and I have a problem
accessing values from a dict in a template.

This code gets executed in the root controller to query the DB and
pass a couple of dictionaries back, exposed to a particular template.

The query / returned data that is causing the problem comes from this
table definition in the model;

class corporations(DeclarativeBase):
    __tablename__ = 'corporations'

    #{ Columns
    id = Column(Integer, primary_key=True)
    corporationID = Column(Unicode(255), nullable=False)
    corporationName = Column(Unicode(255), nullable=False)
    ticker = Column(Unicode(255), nullable=False)
    ceoID = Column(Unicode(255), nullable=False)
    ceoName = Column(Unicode(255), nullable=False)
    stationID = Column(Unicode(255), nullable=False)
    stationName = Column(Unicode(255), nullable=False)
    description = Column(Unicode(255), nullable=True)
    url = Column(Unicode(255), nullable=True)
    allianceID = Column(Unicode(255), nullable=True)
    allianceName = Column(Unicode(255), nullable=True)
    taxRate = Column(Unicode(255), nullable=False)
    memberCount = Column(Unicode(255), nullable=False)
    shares = Column(Unicode(255), nullable=False)
    #}

    def __init__
(self,description,url,allianceID,corporationID,corporationName,ticker,ceoID,ceoName,stationID,stationName,taxRate,memberCount,shares):
        self.corporationID=corporationID
        self.corporationName=corporationName
        self.ticker=ticker
        self.ceoID=ceoID
        self.ceoName=ceoName
        self.stationID=stationID
        self.stationName=stationName
        self.description=description
        self.url=url
        self.allianceID=allianceID
        self.taxRate=taxRate
        self.memberCount=memberCount
        self.shares=shares

This table is queried in the controller with the following code;

    @expose('browseeve.templates.ShowAllianceList')
    def ShowAllianceList(self):
        alinfo=DBSession.query(alliances)
        XCinfo={};
        for al in alinfo:
            XC=DBSession.query(corporations).filter_by
(corporationID=al.executorCorpID)
            XCinfo[al.allianceID]=XC
        """Display alliance table."""
        return dict(alinfo=alinfo, XCinfo=XCinfo)

The alinfo dict is accessible in the following template no problem,
but I have problems with XCinfo;

(Excerpt HTML from template)

                <tr py:for="al in alinfo">
                        <td>
                                <a 
href="/ShowAlliance?allianceID=${al.allianceID}">${al.name}</a>
                        </td>
                        <td>
                                ${al.shortName}
                        </td>
                        <td>
                                ${al.allianceID}
                        </td>
                        <td >
                                ${XCinfo[al.allianceID]}
                        </td>
                        <td>
                                ${al.memberCount}
                        </td>
                        <td>
                                ${al.startDate}
                        </td>
                </tr>


In its current form, that template extract builds output lines similar
to;

GoonSwarm        OHGOD           824518128
<browseeve.model.corporations.corporations object at 0x06109150>
5251     1149295800


This to me means that ${XCinfo[al.allianceID]} is evaluating to a
browseeve.model.corporations.corporations object. This object should
have a  corporationName field, but when replacing

${XCinfo[al.allianceID]}

with

${XCinfo[al.allianceID].corporationName}

I get the error that;

ndefinedError: <sqlalchemy.orm.query.Query object at 0x06BA10D0> has
no member named "corporationName"

.. I am confused as to why the object type being refrenced now becomes
a sqlalchemy Query object, where before it was being reported as a
browseeve.model.corporations.corporations object.


Can anyone explain to me what going on?

Thankyou,

AlienBaby.

--~--~---------~--~----~------------~-------~--~----~
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