Alright, I have a few questions. Being that I am still new at web
programming, I am a bit confused doing things the TG way. Take for example
the following code ( please forgive the ugliness ).

I am a bit list how I would do this correctly using kid and the correct MVC
approach. I appreciate any help.


<snip>
    def getEvent(self):
        sql = """SELECT event_day FROM event_data
                          WHERE event_month=%s""" % (self.month)
        self.conn.execute(sql)

        return self.conn.fetchall()

# The getEvent() returns an SQL query that returns all day field data ( day
objects attributes in ORM parlance ) within the matching month
# Below I have built a global list object of all the days in that given
month.

    self.hotDays = []

    def getHotDays(self):
        results = self.getEvent()
        rows = []
        for row in results:
            rows.append(row)
            for days in row:
                self.hotDays.append(days)
        return self.hotDays

# Now the TG way to do this is much easier, which I am doing like so... here
I am going to build a month calendar and use kid for the view, the hotday
list is what is in question

    @expose(template="tgcal.templates.events")
    def calendar(self, year='2006', month='1', day=None):
        import calendar
        calendar.setfirstweekday(calendar.SUNDAY)
        monthcal = calendar.monthcalendar(int(year), int(month))
        daysevents = model.Event.selectBy(year=year,month=month,day=day)
        event_fields = [('Title', 'title'), \
                        ('Text','text'), \
                        ('Time','time')]
        hotday=[]
        result = model.Event.selectBy(year=year, month=month)
        for row in result:
            hotday.append(row.day)

        return dict(hotday=hotday, year=year, month=month, day=day,
monthcal=monthcal, events=daysevents, \
                         events_widget=widgets.DataGrid
(fields=event_fields))

# above everything is fine, the hotday list is returned in the dict with the
rest of the data. I'll post my events.kid template at the end


# In python if I wanted to count each day that has an event in a particular
month (compare the day to hotdays), I would do it like so ( I know there are
probably better ways to do this, but I am focused on learning how to
accomplish this in TG first. )



    def isHot(self, day):
        if day in self.hotDays:
            events = self.hotDays.count(day)
            if events == 1:
                return str(events) + ' Event'
            else:
                return str(events) + ' Events'
        else:
            return 'No Events Today'
</snip>



---------------------------------
 my kid template
---------------------------------
 so far it just print's out a calendar and the events

<snip>

        <tr py:for="days in monthcal">
            <td py:for="day in days">


                <span py:if="day==0" py:strip=''><br/></span>
                  <span py:if="day!=0" py:strip=''>
                   <a class='showday'
href='/calendar/${year}/${month}/${day}'>${day}</a><br/>
                   <a class='event'
href='/post/${year}/${month}/${day}'>[add]</a></span>



            </td>
        </tr>

</snip>



I hope this makes sense here, to further explain a bit, I in each calendar
box for each day I want to display

-the day number : complete
-add link to a form to add events for the day, month, year: comlete
# here is where I need help
-if there are events on this day and how many: not complate


As you all can tell I am a bit lost. So thanks for your patience.


-- 
-mike


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