>
> If the virtual field is defined in the project bizobj, it is
> straightforward to calculate the sum of the child values for a given
> project. Paul has done much more work on this, so I'm hoping he can give you
> a better example than I could come up with.
>
>
>
> -- Ed Leafe
>
> Ed, if you noticed my response to Kirby here is my db table/filed
structure:
Customer Table: fields are: ID and Name
Project Table: fields are: ID and Name
Task Table: fields are ID and Name
Records Table: fields are: ID, customerID, projectID, taskID, start time,
and end time. I created the duration field as a virtual filed in the records
table by subtracting start time from end time.
Here is my Records bizobj: (sorry for the length of this message)
<code>
# -*- coding: utf-8 -*-
import datetime
import time
from Base import Base
class Records(Base):
def initProperties(self):
self.super()
self.Caption = "Records"
self.DataSource = "records"
self.KeyField = "id"
# Setting the DataStructure explicitly here is optional, but
recommended as
# it will keep Dabo from interpreting field types from the backend
every
# time. It lets you specify what types you expect which fields to
be. Also,
# this information is used in self.setSQL() to add the fields to the
query.
# (field_alias, field_type, pk, table_name, field_name, field_scale)
self.DataStructure = (
("id", "I", True, "records", "id"),
("fromTime", "C", False, "records", "fromTime"),
("toTime", "C", False, "records", "toTime"),
("customerID", "I", False, "records", "customerID"),
("custName", "C", False, "customers", "name"),
("projectID", "I", False, "records", "projectID"),
("projName", "C", False, "projects", "name"),
("taskID", "I", False, "records", "taskID"),
("tasName", "C", False, "tasks", "name"),
("rate", "C", False, "tasks", "rate"),
("icalEventID", "C", False, "records", "icalEventID"),
("comments", "C", False, "records", "comments"),
("GoogleEditURL", "C", False, "records", "GoogleEditURL"),
("OutlookEntryID", "C", False, "records", "OutlookEntryID"),
)
# Use the DefaultValues dict to specify default field values for new
# records. By default DefaultValues is the empty dict, meaning that
# no default values will be filled in.
#self.DefaultValues['<field_name>'] = <value_or_function_object>
# Default encoding is set to utf8, but if your backend db encodes in
# something else, you need to set that encoding here (or in each
# bizobj individually. A very common encoding for the Americas and
# Western Europe is "latin-1", so if you are getting errors but are
# unsure what encoding to pick, try uncommenting the following line:
#self.Encoding = "latin-1"
def afterInit(self):
self.super()
def setBaseSQL(self):
# Set up the base SQL (the fields clause, the from clause, etc.) The
# UI refresh() will probably modify the where clause and maybe the
# limit clause, depending on what the runtime user chooses in the
# select page.
self.addFrom("records")
self.setLimitClause("500")
self.addFieldsFromDataStructure()
self.addJoin("customers", "records.customerID = customers.id")
self.addJoin("projects", "records.projectID = projects.id")
self.addJoin("tasks", "records.taskID = tasks.id")
self.VirtualFields = {"duration": self.getDuration, "dayDuration":
self.getDurationDay,
"weekDuration": self.getDurationWeek,
"yearDuration": self.getDurationYear}
#"projDuration": self.getDurationProject
def getDuration(self):
timeFrom = self.Record.fromTime
timeTo = self.Record.toTime
fromTimeTuple = datetime.datetime.strptime(timeFrom, '%Y-%m-%d
%H:%M:%S')
toTimeTuple = datetime.datetime.strptime(timeTo, '%Y-%m-%d
%H:%M:%S')
fromSeconds = time.mktime(fromTimeTuple.timetuple())
toSeconds = time.mktime(toTimeTuple.timetuple())
duration = toSeconds - fromSeconds
return int(duration)
def getDurationDay(self):
dayFrom = self.Record.fromTime
dayfromTimeTuple = datetime.datetime.strptime(dayFrom, '%Y-%m-%d
%H:%M:%S')
return dayfromTimeTuple.strftime('%j')
def getDurationWeek(self):
weekFrom = self.Record.fromTime
weekfromTimeTuple = datetime.datetime.strptime(weekFrom, '%Y-%m-%d
%H:%M:%S')
return weekfromTimeTuple.strftime('%W')
def getDurationYear(self):
yearFrom = self.Record.fromTime
yearfromTimeTuple = datetime.datetime.strptime(yearFrom, '%Y-%m-%d
%H:%M:%S')
return yearfromTimeTuple.strftime('%Y')
# def getDurationProjectSubtotal(self):
# ds = self.getDataSet()
# projDurationSubtotal = ds.execute("select sum(duration) as dursum
from dataset")
# return projDurationSubtotal[0]["dursum"]
# def getDurationProject(self):
# projDuration = sum([projectID.getDurationProjectSubtotal() for
projectID in self.DataStructure])
</code>
As you can see by th commented out sections, I am having a hell of a time
figuring out a projectDuration method as a virtual field in my records
bizobj.
I've tried varying combination which has produced varying errors from max
out recursion errors to no callable object errors.
Carey
--- StripMime Report -- processed MIME parts ---
multipart/alternative
text/plain (text body -- kept)
text/html
---
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message:
http://leafe.com/archives/byMID/[email protected]