On Wednesday, February 7, 2018 at 2:08:23 PM UTC-8, Leonel Câmara wrote:
>
> Hummm you're right, can I see the code for default/sorted and the
> quartermaster table?
>
db.define_table('QuarterMaster',
Field('IssueYr', 'integer',
requires = [IS_NOT_EMPTY(), IS_INT_IN_RANGE(1965,2018,
"Not
a valid year of issue")],
widget = lambda f, v: SQLFORM.widgets.integer.widget(f,
v, _autofocus=True)),
Field('StateNm', 'string', default=None, represent=lambda
StateNm: StateNm or '', requires=IS_EMPTY_OR(IS_IN_SET(us_states))),
Field('Other', 'string', default=None, represent=lambda
Other: Other or '', requires=IS_EMPTY_OR(IS_IN_SET(us_other))),
Field('Mint', 'string', requires=IS_MATCH('^[dpx]*$',
error_message="not a valid mint string")),
Field('NumAdded', "integer", compute = lambda r: len(r[
"Mint"])),
Field('PostDate', "date", requires=IS_DATE(format='%Y-%m-%d'
, error_message='must be YYYY-MM-DD!')))
And then the ugly beast:
(most of the ugliness is in the way I present 1 field)
def sorted():
import re
from gluon.storage import Storage
from pydal.objects import Rows
dateshape = re.compile("\d{4}-\d{2}-\d{2}")
if request.vars.pdate:
if not dateshape.match(request.vars.pdate):
raise HTTP(501, "error in date argument; YYYY-MM-DD expected")
r = db(db.QuarterMaster.PostDate == request.vars.pdate)
else:
r = db(db.QuarterMaster.PostDate != None)
sum = db.QuarterMaster.NumAdded.sum()
streetval = r.select(sum).first()[sum]
rows=r.select(orderby=db.QuarterMaster.IssueYr|db.QuarterMaster.StateNm|
db.QuarterMaster.Other)
rowed = Rows(db);
rowed.records = []
print rows
prev = 0
skip = 0
for row in rows:
if len(rowed.records) == 0: #row == rows[0]:
prev = 0;
rowed.records.append(row)
elif rowed.records[-1].IssueYr == row.IssueYr and str(rowed.records
[-1].StateNm) == str(row.StateNm) and str(rowed.records[-1].Other) == str(
row.Other):
rowed.records[-1].NumAdded = rowed.records[-1].NumAdded + row.
NumAdded
rawmint = rowed.records[-1].Mint + row.Mint # + "-" + row.Mint
rowed.records[-1].Mint = rawmint.replace('x', '').replace('p',
'')
rowed.records[-1].Mint += rawmint.replace('x', '').replace('d',
'')
rowed.records[-1].Mint += rawmint.replace('d', '').replace('p',
'')
row.NumAdded = 0
row.Mint = ""
print "matched and munged" + str(rowed.records[-1].IssueYr) +
str(rowed.records[-1].Mint)
else:
prev = prev + 1
rowed.records.append(row)
print "done"
if (streetval):
return dict(rows = rowed, streetval = float(streetval)/4)
else:
return dict(rows = rowed, streetval = 0);
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.