[web2py] Re: a couple of related questions

2011-10-21 Thread niknok
Anyone?

On Oct 21, 10:40 am, niknok nikolai...@gmail.com wrote:
 I have a person table[1] with a parent field with a clickable
 representation view of the record. If I put this on a grid and click on
 the link, I get a not authorized error message. I thought I need to
 pass the signature so I can make it viewable. (This works fine if
 parameter user_signature=False)

 Also, I have defined a default representation for the person table but
 in my validation statement, note that I had to specify the same format
 again. I'm wondering if there's a way to tell the validator to use the
 default representation of the person (which I thought was web2py's
 default behavior.)

 In my grid, I specified a new button [2] in the links parameter, how do
 I specificy an icon for this button? For example I want to use what's
 already in base.css (book, heart, cross etc.)

 /r
 Nik

 [1]
 db.define_table('person'
                 ,Field('birth_date', 'date', requires=IS_DATE())
                 ,Field('last_name', notnull=True)
                 ,Field('given_name', notnull=True)
                 ,Field('parent', 'list:reference person'
                                 ,requires=IS_EMPTY_OR(IS_IN_DB(db, 'person.id'
                                               ,'%(last_name)s,
 %(given_name)s [%(birth_date)s]'
                                               ,multiple=True
                                               ,zero=T('pick one')))
                                 ,represent =  lambda value, row: [A(' ▸'+
 db.person[v].given_name , _href = URL('index/view/person', args=[v]))
 for v in value])
                 ,auth.signature
                 ,format='%(last_name)s, %(given_name)s [%(birth_date)s]'
                 )

 [2]
  form=SQLFORM.grid( db.person
                       ,fields=[db.person.id, db.person.last_name,
 db.person.given_name
                                     ,db.person.middle_name,
 db.person.gender, db.person.birth_date, db.person.parent]
                       ,showbuttontext=False
                       ,sorter_icons=('[▴]','[▾]')
                       ,onvalidation=person_processing
                       ,links = [lambda row: A('X',
 _href=URL(args=[view, db.person, row.id] ))]
                       )

[web2py] a couple of related questions

2011-10-20 Thread niknok
I have a person table[1] with a parent field with a clickable
representation view of the record. If I put this on a grid and click on
the link, I get a not authorized error message. I thought I need to
pass the signature so I can make it viewable. (This works fine if
parameter user_signature=False)

Also, I have defined a default representation for the person table but
in my validation statement, note that I had to specify the same format
again. I'm wondering if there's a way to tell the validator to use the
default representation of the person (which I thought was web2py's
default behavior.)

In my grid, I specified a new button [2] in the links parameter, how do
I specificy an icon for this button? For example I want to use what's
already in base.css (book, heart, cross etc.)

/r
Nik

[1]
db.define_table('person'
,Field('birth_date', 'date', requires=IS_DATE())
,Field('last_name', notnull=True)
,Field('given_name', notnull=True)
,Field('parent', 'list:reference person'
,requires=IS_EMPTY_OR(IS_IN_DB(db, 'person.id'
  ,'%(last_name)s,
%(given_name)s [%(birth_date)s]'
  ,multiple=True
  ,zero=T('pick one')))
,represent =  lambda value, row: [A(' ▸'+
db.person[v].given_name , _href = URL('index/view/person', args=[v]))
for v in value])
,auth.signature
,format='%(last_name)s, %(given_name)s [%(birth_date)s]'
)


[2]
 form=SQLFORM.grid( db.person
  ,fields=[db.person.id, db.person.last_name,
db.person.given_name
,db.person.middle_name,
db.person.gender, db.person.birth_date, db.person.parent]
  ,showbuttontext=False
  ,sorter_icons=('[▴]','[▾]')
  ,onvalidation=person_processing
  ,links = [lambda row: A('X',
_href=URL(args=[view, db.person, row.id] ))]
  )



[web2py] looking for suggestions - large number of selections

2011-10-09 Thread niknok
I anticipate a huge number of entries in a person table and expect users
find it difficult to do two things: 

  * selecting or viewing multiple entries 
  * adding a new entry on the fly


The initial person table design used a traditional mother/father set-up
but same-sex parent concept made this obsolete.

db.define_table('person'
,Field('name')
,Field('birth_date')
,Field('parent', 'list:reference person'))

I'm looking for a convenient way to add a person's parent where they can
select the person's parents (if they're already in the list) or add one
if they're not.

The way multiple.widgets is rendered now, the parents are not easily
seen unless the user scrolls through the list.


[web2py] question about preferred represenation and filtering

2011-10-06 Thread niknok
I have a self-referencing table [1] with a defined format for
representing a record in this fashion: Lastname, Firstname
[-mm-dd]. In the father field, I expect it to display the drop-down
list of persons as defined in format, but it doesn't unless I define it
explicitly (like in the  mother field).  

Second, I tried dbset filter for the selection list of the  father and
mother  fields but I still get the whole table instead. 

I'm trying this out on v1.99.2. What am I doing wrong here?

TIA


[1]
db.define_table('person'
,Field('birth_date', 'date', requires=IS_DATE())
,Field('last_name', notnull=True)
,Field('given_name', notnull=True)
,Field('middle_name', label=Mother's maiden name)
,Field('gender', 'integer', requires=IS_IN_SET(settings.gender, 
zero='pick one'))
,Field('father', 'reference person'
   ,requires=IS_EMPTY_OR(IS_IN_DB(db('person.gender'==1), 
'person.id'
  ,zero=T('pick one'
,Field('mother', 'reference person'
   ,requires=IS_EMPTY_OR(IS_IN_DB(db('person.gender'==2), 
'person.id'
  ,'%(last_name)s, %(given_name)s 
[%(birth_date)s]'
,zero=T('pick one'
,auth.signature
,format='%(last_name)s, %(given_name)s [%(birth_date)s]'
)







[web2py] date picker on v1.99

2011-10-06 Thread niknok

The new date picker looks very good. Is there a way to input dates by
typing it directly (similar to default behaviour in older versions), in
addition to selecting dates thru the calendar interface?

/r
Nik 

P.S.
Though I couldn't type in a date, I could paste one.  (which is a
behavior I don't expect from users)


[web2py] error: lambda() takes exactly 1 argument (2 given)

2011-10-06 Thread niknok

When I try 

form=SQLFORM.grid(db.person) 


with a defined represent parameter, I get the following error: 

lambda() takes exactly 1 argument (2 given)



The person table is defined as: 

db.define_table('person'
,Field('birth_date', 'date', requires=IS_DATE())
,Field('last_name', notnull=True)
,Field('given_name', notnull=True)
,Field('middle_name', label=Mother's maiden name)
,Field('gender', 'integer', requires=IS_IN_SET(settings.gender, 
zero='pick one')
,represent=lambda id: settings.gender[id][1][:1])
,Field('father', 'reference person'
   ,requires=IS_EMPTY_OR(IS_IN_DB(db('person.gender'==1), 
'person.id'
  ,zero=T('pick one'
,Field('mother', 'reference person'
   ,requires=IS_EMPTY_OR(IS_IN_DB(db('person.gender'==2), 
'person.id'
  ,'%(last_name)s, %(given_name)s 
[%(birth_date)s]'
  ,zero=T('pick one'
,auth.signature
,format='%(last_name)s, %(given_name)s [%(birth_date)s]'
)






[web2py] Re: what about web2py 2.0?

2011-09-20 Thread niknok
Web2Py 2.0 must be *fully* documented in online book.

On Sep 20, 4:26 pm, Mengu whalb...@gmail.com wrote:
 anything special coming up?

 will it broke backward compatibility? nobody needs backward
 compatibility in a major version.

 are there any plans for a clean up?


[web2py] Re: billing app

2011-09-12 Thread niknok
Thanks for sharing Kenneth. This looks good. Are you going to open
source it?

Would like to learn from the code, especially the invoicing part.

On Sep 12, 6:03 pm, Kenneth Lundström kenneth.t.lundst...@gmail.com
wrote:
 Now you can have a look at it athttp://web2py.nudata.fi/em

 Login with kenneth and kenneth

 This is an application for a very small firm, three part-time
 IT-supporters.

 FRONTPAGE:
 summary of all kind of data.
          a) how many unpaid receipts
          b) how much money every person has earned
          c) ticket situation
          d) log work done

 RECEIPT:
 this is the place where we declare what we have bought, either by credit
 card or on bill. If a bill then you put due-date and things like that
 too and out accountant receives an mail about it. Here you upload an PDF
 or JPG of the receipt too. Every receipt has to be broken down to which
 customer should be billed for it.

 BILLS:
 here you create bills that should be sent to customer. A bill is created
 from items from Receipts, Reported work. If you have customer that buys
 something from you and you bill every year you can create Periodical bills.

 CUSTOMERS:
 customerdatabase

 PRODUCTS:
 product database

 TICKETS:
 a very simple ticketing system, work in progress. If you visit
 web2py.nudata.fi/em/ticket without being logged in you ll get a create
 ticket page ment for customers.
 The idea is that when a ticket is ready the work used to solve the
 problem will be billed directly. But I m working on that part.

 All comments are welcomed.

 Kenneth







  That would be awesome! Looking forward to it.

  On Sep 8, 3:05 pm, Kenneth Lundstr mkenneth.t.lundst...@gmail.com
  wrote:
  Hello Nikolai,

  I have created a simple billing application that contains customers,
  products, hour tracker (simple) and receipt handling.

  If interested I could during the weekend put up a english version of it
  (Well swedish too it thats better) so you can check it out.

  Kenneth

  is there any billing component among the web2py appliances that can be
  used as a base or a billing appliance?
  Just wondering if there's any such code out there before starting from
  scratch.
  Thanks.


[web2py] Re: preparing for 1.99.1

2011-09-12 Thread niknok
Yes. Eventually. :)

On Sep 13, 1:30 pm, Gour-Gadadhara Dasa g...@atmarama.net wrote:
 On Mon, 12 Sep 2011 20:21:39 -0700 (PDT)
 Massimo Di Pierro

 massimo.dipie...@gmail.com wrote:
  There is huge list of new features already in trunk that will be
  included in 1.99.1

 [...]

  I am forgetting something important? Am I forgetting to acknowledge
  your contribution?

 What about the docs/book?

 Will everything from the list become documented and the book updated
 accordingly?

 Sincerely,
 Gour

 --
 “In the material world, conceptions of good and bad are
 all mental speculations…” (Sri Caitanya Mahaprabhu)

 http://atmarama.net| Hlapicina (Croatia) | GPG: 52B5C810

  signature.asc
  1KViewDownload


[web2py] Re: has anyone done web2py + google maps?

2011-09-10 Thread niknok
Thank you all for the responses and links. They are very good models
to learn from.

Has anyone done something similar to crimereports.com or haybol.ph?

On Sep 11, 7:09 am, Christopher Steel chris.st...@gmail.com wrote:
 You might want to check out Public Radio Roadtrip an application done (in
 progress?) by John Tynan. It was still slightly rough around the edges the
 last time I tried it out but was looking really interesting and was
 exploring some really interesting ideas.

 *Public Radio Roadtrip*

 GAE test site

 http://publicradioroadtrip.appspot.com/publicradioroadtrip

 Get the Code here

 http://code.google.com/p/publicradioroadtrip/

 John's Blog

 http://p2pu.org/en/johntynan/

 John also did an application for public radio funding campaigns...


[web2py] Re: Off topic: New Google Groups Look

2011-09-09 Thread niknok
Looks like a major UI revamp is rolling out across big G's landscape.

Too bad for people like me stuck with poor bandwidth, we'll make do with the 
old interface for now.


[web2py] has anyone done web2py + google maps?

2011-09-09 Thread niknok
Any links to try out?

[web2py] Re: billing app

2011-09-08 Thread niknok
That would be awesome! Looking forward to it.

On Sep 8, 3:05 pm, Kenneth Lundström kenneth.t.lundst...@gmail.com
wrote:
 Hello Nikolai,

 I have created a simple billing application that contains customers,
 products, hour tracker (simple) and receipt handling.

 If interested I could during the weekend put up a english version of it
 (Well swedish too it thats better) so you can check it out.

 Kenneth







  is there any billing component among the web2py appliances that can be
  used as a base or a billing appliance?

  Just wondering if there's any such code out there before starting from
  scratch.

  Thanks.


[web2py] billing app

2011-09-07 Thread niknok
is there any billing component among the web2py appliances that can be
used as a base or a billing appliance?

Just wondering if there's any such code out there before starting from
scratch.

Thanks.


[web2py] web2py trunk [a bit OT]

2011-08-19 Thread niknok
using the web2py repository, is this how you get trunk:

hg clone https://code.google.com/p/web2py/

What are the commands to update the local copy to the latest trunk or
the latest stable?

Thanks.


[web2py] Re: web2py trunk [a bit OT]

2011-08-19 Thread niknok
so, if I only do 'hg pull' i get trunk? and if I do 'hg update' I get
stable?

Is that what you mean?

On Aug 19, 7:20 pm, David Marko dma...@tiscali.cz wrote:
 'hg pull' and then 'hg update'


[web2py] Re: web2py trunk [a bit OT]

2011-08-19 Thread niknok
so, if I only do 'hg pull' i get trunk? and if I do 'hg update' I get
stable?

Is that what you mean?

On Aug 19, 7:20 pm, David Marko dma...@tiscali.cz wrote:
 'hg pull' and then 'hg update'


[web2py] Re: web2py trunk [a bit OT]

2011-08-19 Thread niknok
PS
The reason I'm asking this is so that I could try out the trunk
features without having to download the zipped files.

So I'm trying to find out how to
a.) get trunk version installed in a different directory using
mercurial
b.) get stable version installed in another directory using mercurial

Thanks

On Aug 19, 7:18 pm, niknok nikolai...@gmail.com wrote:
 using the web2py repository, is this how you get trunk:

 hg clonehttps://code.google.com/p/web2py/

 What are the commands to update the local copy to the latest trunk or
 the latest stable?

 Thanks.


[web2py] Re: web2py trunk [a bit OT]

2011-08-19 Thread niknok
so, is there a tag for stable or trunk

On Aug 20, 8:51 am, pbreit pbreitenb...@gmail.com wrote:
 When you hg pull you grab all of the changes since you last did an hg
 pull but your working directory remains unchanged. It is not until you do
 an hg update that your working directory will reflect a new changeset (or
 version, if you will). If you do hg update without specifying a tag or
 changeset, your working directory will reflect the most current version of
 the project that you have downloaded. But you can hg update
 [tag/chageset_id] to set your working directory to a specific changeset.

 Does that make sense?


[web2py] field labels in crud search

2011-08-11 Thread niknok
I noticed while using crud search results that web2py doesn't use labels
defined in tables as headers.  Of course, headers can be defined in crud
but wouldn't it be better if by default it uses the labels already
defined with the table instead of field names?


[web2py] PowerGrid and reference fields

2011-08-11 Thread niknok
When I list a table with a reference field, it shows up as an index key.
I was expecting  it to show up as usual, with the default record
representation of the referenced table. 

It does show up correctly inside a modal window, after hitting an action
button (i.e. Details), though.

I tried setting a .representation for the said field, but that didn't
seem to change anything.

Also, I wish Bruno would consider adding an option for
plugin_PowerGrid.CallBack to return only readable fields.

/r
Nik





[web2py] Re: crud.search query

2011-08-10 Thread niknok
I finally found out that equals don't work but using contain does.
It's counter-intuitive but at least there's a workaround.

On Jul 1, 7:24 pm, niknok nikolai...@gmail.com wrote:
 I have field gender that is defined like so:

         Field('gender','reference aux_gender',notnull=True,widget=radio_h)

 The aux_gender table data were inserted from:

         db.aux_gender.insert(code='F',concept='Female')
         db.aux_gender.insert(code='M',concept='Male')

 I have a view that uses crud.search but couldn't search for records on
 gender field. Tried using record id (since they're saved as integers in
 database) but it doesn't produce any search results. Also tried M, and
 F to no avail.

 What am I doing wrong here?

 /r
 Nik

  w2p gender bender.png
 134KViewDownload

  w2p gender bender results.png
 59KViewDownload


[web2py] Re: The web2py grid/crud plugin you've always dreamed about!

2011-07-28 Thread niknok
I observed a curious behavior when scrolling inside a modal window:
when you reach the top (or bottom) of the modal, your main window also
scrolls up(or down) as well.

Very nice. Kudos to Bruno!

+1 for plans to make this part of web2py/contrib

On Jul 26, 6:15 am, Bruno Rocha rochacbr...@gmail.com wrote:
 BTW:
 You can remove or comment these two lines:

 from gluon.custom_import import track_changes

 track_changes()

 This is usefull only on my development environment.

 PowerGrid works only in web2py 1.97+, because it uses 'current' to
 deal with session, request, response and T

 I made some improvements, hope to release new beta version soon.

 Thanks.

 2011/7/25 Kenneth Lundström kenneth.t.lundst...@gmail.com









   Sorry, I found the error already. A stupid error.

  Our production server was laging behind on updates, was using 1.95.1, but
  not anymore. And now Powergrid is working.

  Kenneth

   I published my first new version of our intranet on our production server
  and now I´m getting:

  Traceback (most recent call last):
    File /data/domains/web2py/gluon/restricted.py, line 181, in restricted
      exec ccode in environment
    File 
  /data/domains/web2py/applications/economy/models/plugin_PowerGrid.py 
  https://economy.nudata.fi/admin/edit/economy/models/plugin_PowerGrid.py, 
  line 40, in module
      from gluon.custom_import import track_changes
  ImportError: cannot import name track_changes

  I copied everything from dev server to production server. On dev it was
  working. Any ideas?

   I think you can use headers=[['f_name',str(T('Name'))]

  This works. Thanks.

   The highlight can be easuly implemented with JavaScript and CSS.

  The idea was that the trigger was the data, if e.g. a rows' sum is 0 it
  would be highlighted.

  Kenneth

 --

 --
 Bruno Rocha
 [ About me:http://zerp.ly/rochacbruno]
 [ Aprenda a programar:http://CursoDePython.com.br]
 [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
 [ Consultoria em desenvolvimento web:http://www.blouweb.com]


[web2py] Re: record representation using a non-id column?

2011-07-20 Thread niknok
Thanks Johann!

On Jul 20, 8:11 pm, Johann Spies johann.sp...@gmail.com wrote:
 On 20 July 2011 14:09, Johann Spies johann.sp...@gmail.com wrote:



  I use this:

  db.define_table('akb_doccenter_location',

                  Field('location'))

 Apologies, I did not complete the message before sending: the model includes
 a Field(uuid),  obviously.

 Regards
 Johann

 --
  May grace and peace be yours in abundance through the full knowledge of God
 and of Jesus our Lord!  His divine power has given us everything we need for
 life and godliness through the full knowledge of the one who called us by
 his own glory and excellence.
                                                     2 Pet. 1:2b,3a


[web2py] Re: request - mmodal examples

2011-07-19 Thread niknok
bump.

No takers? :s

On Jul 16, 8:23 am, niknok nikolai...@gmail.com wrote:
 I just discovered this modal plugin: web2py.com/plugins/default/
 mmodal

 Sorry for being a little slow, but would someone please post an
 example of how I can use crud inside modals?


[web2py] Re: Using T with IS_IN_DB

2011-07-17 Thread niknok
how about:

db.t_status.f_name.represent=lambda f_name: T(f_name)

On Jul 15, 9:27 pm, Kenneth Lundström kenneth.t.lundst...@gmail.com
wrote:
 I have a requires with IS_IN_DB like this:
 IS_IN_DB(db(db.t_status.id  0), 't_status.id', '%(f_status)s / %(f_name)s')

 I d like to translate the f_name with T(). Is it possible?

 Kenneth


[web2py] request - mmodal examples

2011-07-15 Thread niknok
I just discovered this modal plugin: web2py.com/plugins/default/
mmodal

Sorry for being a little slow, but would someone please post an
example of how I can use crud inside modals?


[web2py] Re: compute fields on update

2011-07-14 Thread niknok
You're checking it from the shell. Do a db.commit() before checking
for total_price.

On Jul 15, 3:37 am, guruyaya guruy...@gmail.com wrote:
 This is run on a web2py shell:

  db.define_table('item',

 ...         Field('unit_price','double'),
 ...         Field('quantity','integer'),
 ...         Field('total_price',
 ...             compute=lambda r: r['unit_price']*r['quantity']))
 .
 .
 .

  r = db.item.insert(unit_price=1.99, quantity=5)
  r.total_price
 '9.95'
  db(db.item.id == 1).select()[0]

 Row {'total_price': '9.95', 'update_record': function lambda at
 0x17f10c8, 'unit_price': 1.99, 'id': 1, 'delete_record': function
 lambda at 0x17f1230, 'quantity': 5}

 Till now, all is good.

  db(db.item.id == 1).update(unit_price = 3)
 1
  db(db.item.id == 1).select()[0].total_price
 '9.95'
  db(db.item.id == 1).select()[0].unit_price

 3.0

 The web2py book said that
  When a new record is modified, including both insertions and
 *updates*, if a value for the field is not provided, web2py tries to
 compute from the other field values using the compute function 

 How come? shouldn't the compute field be recalculated?

 Now


[web2py] Re: auth_user.id == kenneth

2011-07-14 Thread niknok
request.args always contain strings. str(request.args(0)) is
extraneous

There's a logic hole here: What if my username is 1 but my record's
id is 22. This code will return the record db.auth_user[1] when it's
supposed to return db.auth_user[22]

Anyway, ou get invalid literal for int() with base 10 error because
auth_user.id expects integers and you're sending it a string,
kenneth. Quick fix:
user = db(db.auth_user.id == request.args[0] if
request.args[0].isdigit() else 0).select()

That fixes the syntax error but not the logic error I pointed out
earlier.



On Jul 15, 5:06 am, Kenneth Lundström kenneth.t.lundst...@gmail.com
wrote:
 Hello,

 why can�t I do this:
 user = db(db.auth_user.id == 'kenneth').select()

 I know that this should result in len(user) = 0 but I�m sending
 sometimes a text and sometimes a number and I�m trying to do this:
          user = db(db.auth_user.id == str(request.args[0])).select()
          if len(user):
              user_id = user[0].id
          else:
              user = db(db.auth_user.username == request.args[0]).select()
              if len(user):
                  user_id = user[0].id
              else:
                  user_id = 0

     Error ticket for kenneths

       Ticket ID

 85.76.66.169.2011-07-15.00-45-45.b6793e0f-2144-4a02-802f-d7b8a45ec8a5

       Version

 web2py^(TM)     Version 1.97.1 (2011-06-26 19:25:44)
 Python  Python 2.6.5: /usr/bin/python

       Traceback

 1.
 2.
 3.
 4.
 5.
 6.
 7.
 8.
 9.
 10.
 11.
 12.
 13.
 14.
 15.
 16.
 17.
 18.
 19.
 20.
 21.
 22.
 23.
 24.

 Traceback(most recent call last):
    File/data/domains/web2py/gluon/restricted.py,line192,inrestricted
      execccodeinenvironment
    File/data/domains/web2py/applications/kenneths/controllers/ticket.py  
 https://web2py.nudata.fi/admin/default/edit/kenneths/controllers/tick...,line43,inmodule
    File/data/domains/web2py/gluon/globals.py,line137,inlambda
      self._caller=lambdaf:f()
    File/data/domains/web2py/applications/kenneths/controllers/ticket.py  
 https://web2py.nudata.fi/admin/default/edit/kenneths/controllers/tick...,line9,innew_ticket
      user=db(db.auth_user.id=='kenneth').select()
    File/data/domains/web2py/gluon/dal.py,line5394,inselect
      return self.db._adapter.select(self.query,fields,attributes)
    File/data/domains/web2py/gluon/dal.py,line1168,inselect
      sql=self._select(query,fields,attributes)
    File/data/domains/web2py/gluon/dal.py,line1078,in_select
      sql_w=' WHERE '+self.expand(query)
    File/data/domains/web2py/gluon/dal.py,line937,inexpand
      returnexpression.op(expression.first,expression.second)
    File/data/domains/web2py/gluon/dal.py,line886,inEQ
      return'(%s = %s)'% (self.expand(first),self.expand(second,first.type))
    File/data/domains/web2py/gluon/dal.py,line943,inexpand
      return self.represent(expression,field_type)
    File/data/domains/web2py/gluon/dal.py,line1280,inrepresent
      returnstr(int(obj))
 ValueError:invalid literalforint()with base10:'kenneth'

       Error snapshot

 |type 'exceptions.ValueError'(invalid literal for int() with base 10:
 'kenneth')|


[web2py] Re: auth_user.id == kenneth

2011-07-14 Thread niknok
In that case, this should work as well:

query = db.auth_user.id == request.args[0]).select() if
request.args[0].isdigit() else db.auth_user.username ==
request.args[0]
user_id = db(query).select()[0].id or 0




On Jul 15, 6:54 am, Kenneth Lundström kenneth.t.lundst...@gmail.com
wrote:
 Thanks,

 logic error noted, in this case it woun t be a problem. Can t think of a
 fix without changing the idea behind this.

 I find it interesting that some fields expect a specific type. Is ID the
 only one?

 user = db(db.auth_user.id == request.args[0] if
 request.args[0].isdigit() else 0).select()

 This didn t work, it throws an error saying no table selected.
 But instead I did it like this:
          if request.args[0].isdigit():
              user = db(db.auth_user.id == str(request.args[0])).select()
              if len(user):
                  user_id = user[0].id
              else:
                  user_id = 0
          else:
              user = db(db.auth_user.username == request.args[0]).select()
              if len(user):
                  user_id = user[0].id
              else:
                  user_id = 0

 Kenneth







  request.args always contain strings. str(request.args(0)) is
  extraneous

  There's a logic hole here: What if my username is 1 but my record's
  id is 22. This code will return the record db.auth_user[1] when it's
  supposed to return db.auth_user[22]

  Anyway, ou get invalid literal for int() with base 10 error because
  auth_user.id expects integers and you're sending it a string,
  kenneth. Quick fix:
  user = db(db.auth_user.id == request.args[0] if
  request.args[0].isdigit() else 0).select()

  That fixes the syntax error but not the logic error I pointed out
  earlier.

  On Jul 15, 5:06 am, Kenneth Lundstr mkenneth.t.lundst...@gmail.com
  wrote:
  Hello,

  why can t I do this:
  user = db(db.auth_user.id == 'kenneth').select()

  I know that this should result in len(user) = 0 but I m sending
  sometimes a text and sometimes a number and I m trying to do this:
            user = db(db.auth_user.id == str(request.args[0])).select()
            if len(user):
                user_id = user[0].id
            else:
                user = db(db.auth_user.username == request.args[0]).select()
                if len(user):
                    user_id = user[0].id
                else:
                    user_id = 0

       Error ticket for kenneths

         Ticket ID

  85.76.66.169.2011-07-15.00-45-45.b6793e0f-2144-4a02-802f-d7b8a45ec8a5

         Version

  web2py^(TM)     Version 1.97.1 (2011-06-26 19:25:44)
  Python  Python 2.6.5: /usr/bin/python

         Traceback

  1.
  2.
  3.
  4.
  5.
  6.
  7.
  8.
  9.
  10.
  11.
  12.
  13.
  14.
  15.
  16.
  17.
  18.
  19.
  20.
  21.
  22.
  23.
  24.

  Traceback(most recent call last):
      File/data/domains/web2py/gluon/restricted.py,line192,inrestricted
        execccodeinenvironment
      
  File/data/domains/web2py/applications/kenneths/controllers/ticket.pyhttps://web2py.nudata.fi/admin/default/edit/kenneths/controllers/tick...,line43,inmodule
      File/data/domains/web2py/gluon/globals.py,line137,inlambda
        self._caller=lambdaf:f()
      
  File/data/domains/web2py/applications/kenneths/controllers/ticket.pyhttps://web2py.nudata.fi/admin/default/edit/kenneths/controllers/tick...,line9,innew_ticket
        user=db(db.auth_user.id=='kenneth').select()
      File/data/domains/web2py/gluon/dal.py,line5394,inselect
        return self.db._adapter.select(self.query,fields,attributes)
      File/data/domains/web2py/gluon/dal.py,line1168,inselect
        sql=self._select(query,fields,attributes)
      File/data/domains/web2py/gluon/dal.py,line1078,in_select
        sql_w=' WHERE '+self.expand(query)
      File/data/domains/web2py/gluon/dal.py,line937,inexpand
        returnexpression.op(expression.first,expression.second)
      File/data/domains/web2py/gluon/dal.py,line886,inEQ
        return'(%s = %s)'% 
  (self.expand(first),self.expand(second,first.type))
      File/data/domains/web2py/gluon/dal.py,line943,inexpand
        return self.represent(expression,field_type)
      File/data/domains/web2py/gluon/dal.py,line1280,inrepresent
        returnstr(int(obj))
  ValueError:invalid literalforint()with base10:'kenneth'

         Error snapshot

  |type 'exceptions.ValueError'(invalid literal for int() with base 10:
  'kenneth')|


[web2py] Re: auth_user.id == kenneth

2011-07-14 Thread niknok
As far as I know only with ID, which is always auto-magically created
for you.

On Jul 15, 6:54 am, Kenneth Lundström kenneth.t.lundst...@gmail.com
wrote:
 Thanks,

 logic error noted, in this case it woun t be a problem. Can t think of a
 fix without changing the idea behind this.

 I find it interesting that some fields expect a specific type. Is ID the
 only one?

 user = db(db.auth_user.id == request.args[0] if
 request.args[0].isdigit() else 0).select()

 This didn t work, it throws an error saying no table selected.
 But instead I did it like this:
          if request.args[0].isdigit():
              user = db(db.auth_user.id == str(request.args[0])).select()
              if len(user):
                  user_id = user[0].id
              else:
                  user_id = 0
          else:
              user = db(db.auth_user.username == request.args[0]).select()
              if len(user):
                  user_id = user[0].id
              else:
                  user_id = 0

 Kenneth







  request.args always contain strings. str(request.args(0)) is
  extraneous

  There's a logic hole here: What if my username is 1 but my record's
  id is 22. This code will return the record db.auth_user[1] when it's
  supposed to return db.auth_user[22]

  Anyway, ou get invalid literal for int() with base 10 error because
  auth_user.id expects integers and you're sending it a string,
  kenneth. Quick fix:
  user = db(db.auth_user.id == request.args[0] if
  request.args[0].isdigit() else 0).select()

  That fixes the syntax error but not the logic error I pointed out
  earlier.

  On Jul 15, 5:06 am, Kenneth Lundstr mkenneth.t.lundst...@gmail.com
  wrote:
  Hello,

  why can t I do this:
  user = db(db.auth_user.id == 'kenneth').select()

  I know that this should result in len(user) = 0 but I m sending
  sometimes a text and sometimes a number and I m trying to do this:
            user = db(db.auth_user.id == str(request.args[0])).select()
            if len(user):
                user_id = user[0].id
            else:
                user = db(db.auth_user.username == request.args[0]).select()
                if len(user):
                    user_id = user[0].id
                else:
                    user_id = 0

       Error ticket for kenneths

         Ticket ID

  85.76.66.169.2011-07-15.00-45-45.b6793e0f-2144-4a02-802f-d7b8a45ec8a5

         Version

  web2py^(TM)     Version 1.97.1 (2011-06-26 19:25:44)
  Python  Python 2.6.5: /usr/bin/python

         Traceback

  1.
  2.
  3.
  4.
  5.
  6.
  7.
  8.
  9.
  10.
  11.
  12.
  13.
  14.
  15.
  16.
  17.
  18.
  19.
  20.
  21.
  22.
  23.
  24.

  Traceback(most recent call last):
      File/data/domains/web2py/gluon/restricted.py,line192,inrestricted
        execccodeinenvironment
      
  File/data/domains/web2py/applications/kenneths/controllers/ticket.pyhttps://web2py.nudata.fi/admin/default/edit/kenneths/controllers/tick...,line43,inmodule
      File/data/domains/web2py/gluon/globals.py,line137,inlambda
        self._caller=lambdaf:f()
      
  File/data/domains/web2py/applications/kenneths/controllers/ticket.pyhttps://web2py.nudata.fi/admin/default/edit/kenneths/controllers/tick...,line9,innew_ticket
        user=db(db.auth_user.id=='kenneth').select()
      File/data/domains/web2py/gluon/dal.py,line5394,inselect
        return self.db._adapter.select(self.query,fields,attributes)
      File/data/domains/web2py/gluon/dal.py,line1168,inselect
        sql=self._select(query,fields,attributes)
      File/data/domains/web2py/gluon/dal.py,line1078,in_select
        sql_w=' WHERE '+self.expand(query)
      File/data/domains/web2py/gluon/dal.py,line937,inexpand
        returnexpression.op(expression.first,expression.second)
      File/data/domains/web2py/gluon/dal.py,line886,inEQ
        return'(%s = %s)'% 
  (self.expand(first),self.expand(second,first.type))
      File/data/domains/web2py/gluon/dal.py,line943,inexpand
        return self.represent(expression,field_type)
      File/data/domains/web2py/gluon/dal.py,line1280,inrepresent
        returnstr(int(obj))
  ValueError:invalid literalforint()with base10:'kenneth'

         Error snapshot

  |type 'exceptions.ValueError'(invalid literal for int() with base 10:
  'kenneth')|


[web2py] Re: compute fields on update

2011-07-14 Thread niknok
I just tested this on v1.97.1 , and confirm that from the shell the
record doesn't appear to be updated even after a db.commit(). However,
using appadmin to check the database, the records were actually are
updated.

But if do it like this:
for i in db(db.item.id0).select(): i.quantity, i.unit_price,
i.total_price

instead of like:
items =db(db.item.id0).select()
for i in items: i.quantity, i.unit_price, i.total_price

You will see the record values are immediately updated.

So, I think this is a bug unless I'm very much mistaken.



On Jul 15, 12:17 pm, guruyaya guruy...@gmail.com wrote:
  db.commit()
  db(db.item.id == 1).select()[0].total_price
 '9.95'
  db(db.item.id == 1).select()[0]

 Row {'total_price': '9.95', 'update_record': function lambda at
 0x17f1758, 'unit_price': 3.0, 'id': 1, 'delete_record': function
 lambda at 0x17f17d0, 'quantity': 5}

 On Jul 15, 12:54 am, niknok nikolai...@gmail.com wrote:







  You're checking it from the shell. Do a db.commit() before checking
  for total_price.

  On Jul 15, 3:37 am, guruyaya guruy...@gmail.com wrote:

   This is run on a web2py shell:

db.define_table('item',

   ...         Field('unit_price','double'),
   ...         Field('quantity','integer'),
   ...         Field('total_price',
   ...             compute=lambda r: r['unit_price']*r['quantity']))
   .
   .
   .

r = db.item.insert(unit_price=1.99, quantity=5)
r.total_price
   '9.95'
db(db.item.id == 1).select()[0]

   Row {'total_price': '9.95', 'update_record': function lambda at
   0x17f10c8, 'unit_price': 1.99, 'id': 1, 'delete_record': function
   lambda at 0x17f1230, 'quantity': 5}

   Till now, all is good.

db(db.item.id == 1).update(unit_price = 3)
   1
db(db.item.id == 1).select()[0].total_price
   '9.95'
db(db.item.id == 1).select()[0].unit_price

   3.0

   The web2py book said that
When a new record is modified, including both insertions and
   *updates*, if a value for the field is not provided, web2py tries to
   compute from the other field values using the compute function 

   How come? shouldn't the compute field be recalculated?

   Now


[web2py] [closed] Re: one form for multiple tables - updating record

2011-07-13 Thread niknok
Thanks Anthony.

I checked that out but prefer Jay Kelnar take here:
http://groups.google.com/group/web2py/msg/bc03cef19067fa83

In short, SQLFORM.factory has no record argument. You must retrieve
the previous record and store it in form.vars.

Jay shared me his code and I modified it here: http://pastie.org/2210228

hth


[web2py] Re: Many modal windows on one page

2011-07-12 Thread niknok
Bruno, would you be so kind and post a slice or short example on the
use of easyframework+w2p?

On Jul 13, 7:58 am, Bruno Rocha rochacbr...@gmail.com wrote:
 I am usinghttp://easyframework.com/demo_popup.phpwithout problems.

 2011/7/12 Kenneth Lundström kenneth.t.lundst...@gmail.com









  Is this impossible? Should I instead try something with a form in a DIV. I
  got some hints from Branko but could just not get it working. Javascript
  sounded a nice way but even their I only got close, not perfect.

  Kenneth

   Hello everybody,

  I惴 trying to create a page with a list of items. On every row a item is
  shown and every row has an Edit button. Instead of going to a new page to
  edit the record I惴 trying to use modal window via AJAX to edit the record.

  Mmodal plugin gets me quite close to a solution, but the problem is that
  mmodal is great for one link on the page. I惴 going to need many links to 
  the
  same form but different attributes. With mmodal I have to create a new
  different form for every row.

  So far I have edited the example for mmdaol to look like this:
  {{a=PluginMModal(title=T('Edit record'),content=form_edit,**
  close='close',width=40,height=**82)}}
  {{=a}}
  {{=a.link(T('Edit record'))}}

  So instead of a text in content I惴 sending a form that is created in the
  controller.

  Ideal would be that in the a.link I could define what record I悲 like to
  edit.

  Any ideas how to achieve this?

  Kenneth

 --

 --
 Bruno Rocha
 [ About me:http://zerp.ly/rochacbruno]
 [ Aprenda a programar:http://CursoDePython.com.br]
 [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
 [ Consultoria em desenvolvimento web:http://www.blouweb.com]


[web2py] fields and field_labels argument in crud.seach

2011-07-11 Thread niknok
This example from the epydoc doesn't work: 

form, results = crud.search(db.test,
   queries = ['equals', 'not equal', 'contains'],
   query_labels={'equals':'Equals',
 'not equal':'Not equal'},
   fields = [db.test.id, db.test.children],
   field_labels = {'id':'ID','children':'Children'},
   zero='Please choose',
   query = (db.test.id  0)(db.test.id != 3) )



However, it will work if I change the fields argument to: 

fields = ['id', 'children']


In the book though the latter convention is but I often refer to epydoc
when I'm offline. 



I also couldn't get the field_labels to show up with crud.search as
above. 








[web2py] one form for multiple tables - updating record

2011-07-11 Thread niknok
I've read the section about one form for multiple tables  and
following the example created my function that updates four tables: 

def register():
form=SQLFORM.factory(db.person, db.affiliation, db.address, db.card)
if form.accepts(request.vars):
id = db.person.insert(**db.person._filter_fields(form.vars))
form.vars.person=id
id = db.affiliation.insert(**db.affiliation._filter_fields(form.vars))
id = db.address.insert(**db.address._filter_fields(form.vars))
id = db.card.insert(**db.card._filter_fields(form.vars))
return dict(form=form)


That works fine. Now, following the book convention, I tried to display
the same record set but it produces an error:


def display():
record = db.person(request.args(0)) 
form=SQLFORM.factory(db.person, db.affiliation, db.address, db.card, record)

if form.accepts(request.vars, session):
record.update_record(**dict(form.vars))

return dict(form=form)



Traceback (most recent call last):
  File /home/rwn/Projects/web2py/gluon/restricted.py, line 192, in restricted
exec ccode in environment
  File 
/home/rwn/Projects/web2py/applications/g_bender/controllers/default.py, line 
132, in module
  File /home/rwn/Projects/web2py/gluon/globals.py, line 137, in lambda
self._caller = lambda f: f()
  File 
/home/rwn/Projects/web2py/applications/g_bender/controllers/default.py, line 
66, in update
form=SQLFORM.factory(db.person, db.affiliation, db.address, db.card, 
record=record)
  File /home/rwn/Projects/web2py/gluon/sqlhtml.py, line 1226, in factory
return SQLFORM(DAL(None).define_table(table_name, *fields), **attributes)
  File /home/rwn/Projects/web2py/gluon/sqlhtml.py, line 772, in __init__
default = record[fieldname]
  File /home/rwn/Projects/web2py/gluon/dal.py, line 3701, in __getitem__
return dict.__getitem__(self, key)
KeyError: 'organization'


I think the error is because  I'm only passing a record from db.person. 

So how do I actually retrieve the same record set I entered using the
technique presented in one form for multiple tables? I couldn't find a
relevant example to follow in the book.

Thanks.






[web2py] Re: one form for multiple tables - updating record

2011-07-11 Thread niknok
Thanks for looking Kenneth.

Should it be a record id?  From the book (and epydocs):
record = db.person(request.args(0))
form = SQLFORM(db.person, record)

where record is a Row object and it works correctly. I tried your
suggestion to pass an id but got a KeyError:'name' error.

Sorry for being a bit thick here, but correct me if I'm wrong, but the
one form for multiple tables section in the book uses
SQLFORM.factory which, I now realize, doesn't accept a record
argument. Or does it?


On Jul 11, 9:06 pm, Kenneth Lundström kenneth.t.lundst...@gmail.com
wrote:
 def display():
       record = db.person(request.args(0))
       form=SQLFORM.factory(db.person, db.affiliation, db.address,
 db.card, record)
       if form.accepts(request.vars, session):
           record.update_record(**dict(form.vars))
           return dict(form=form)

 The problem is that your are giving SQLFORM a row object as you should
 give it an ID.
 record = db.person(request.args(0)) creates a row object so instead o:
       form=SQLFORM.factory(db.person, db.affiliation, db.address,
 db.card, record)
 try:
       form=SQLFORM.factory(db.person, db.affiliation, db.address,
 db.card, record[0].id)

 or maybe even add an small check that request.args is correct:
       record = db.person(request.args(0))
       if len(record):
           form=SQLFORM.factory(db.person, db.affiliation, db.address,
 db.card, record)
       else:
           response.flash=(T('No record with that ID found'))

 Kenneth









  Traceback (most recent call last):
     File /home/rwn/Projects/web2py/gluon/restricted.py, line192, in 
  restricted
       exec ccode in environment
     File/home/  
  http://127.0.0.1:8000/admin/default/edit/g_bender/controllers/default.pyrwn/Projects/web2py/applications/g_bender/controllers/default.py
    
  http://127.0.0.1:8000/admin/default/edit/g_bender/controllers/default.py, 
  line132, inmodule
     File /home/rwn/Projects/web2py/gluon/globals.py, line137, inlambda
       self._caller = lambda f: f()
     File/home/  
  http://127.0.0.1:8000/admin/default/edit/g_bender/controllers/default.pyrwn/Projects/web2py/applications/g_bender/controllers/default.py
    
  http://127.0.0.1:8000/admin/default/edit/g_bender/controllers/default.py, 
  line66, in update
       form=SQLFORM.factory(db.person, db.affiliation, db.address, db.card, 
  record=record)
     File /home/rwn/Projects/web2py/gluon/sqlhtml.py, line1226, in factory
       return SQLFORM(DAL(None).define_table(table_name, *fields), 
  **attributes)
     File /home/rwn/Projects/web2py/gluon/sqlhtml.py, line772, in __init__
       default = record[fieldname]
     File /home/rwn/Projects/web2py/gluon/dal.py, line3701, in __getitem__
       return dict.__getitem__(self, key)
  KeyError: 'organization'

  I think the error is because  I'm only passing a record from db.person.

  So how do I actually retrieve the same record set I entered using the
  technique presented in one form for multiple tables? I couldn't find
  a relevant example to follow in the book.

  Thanks.


[web2py] record representation using a non-id column?

2011-07-09 Thread niknok
I have another unique column in my table that I would like to use as
index for record representation.  How do I tell web2py to use another
index?

Ttrying to use like:
db.mytable.thisfield.represent = lambda id:
db.other(myidx).thatfield


[web2py] Re: PowerFormWizard 0.1.4 - Bug Fixes and auto_validation (+ a new plugin for grids)

2011-07-09 Thread niknok
Any suggestion how to make this work with multiple tables (ie. one-to-
many relationships)?

For example, auth_user and is linked to other tables which I would
like to view in other tabs?


On Jul 7, 5:27 pm, Bruno Rocha rochacbr...@gmail.com wrote:
 UPDATE:

 auto_validate renamed to .validate()

 Now we have another method that allows this:

 return dict(form=PowerFormWizard(db.table).process(messages=['Sucess!','Fail
 try again']))

 which creates and auto validate the form returning the form itsef.

 Other thing I guess no one tought about is the use for single step forms:

 http://labs.blouweb.com/powerformwizard/default/singlestep

 You can use the plugin for one step (normal) forms, use the client side
 validation and layout!

 More comming...









 On Tue, Jul 5, 2011 at 6:53 AM, Bruno Rocha rochacbr...@gmail.com wrote:
  HI,

  I just finished the refactoring for PFWizard plugin, major bug fixes
  (thanks everyone testing and reporting)

  *# NOTES*
  - It works only wih web2py 1.97+
  - It works only for SQLFORM based forms, you have to pass a db.table
  - It does not works for Crud() , does not allows editing or delete yet (can
  you contribute?)
  - It receives any arg that SQLFORM receives

  *# FIXES*
  - Fixed Issue #2 - Now it works with tables which has '_' or '__' in
  fieldnames.
  - Fixed Issue #1 - Now it works with Python  2.6 - removed enumerate()
  - Ommit fields - Fixed issue, now you cam ommit fields with no break in
  validation (client and server side)
  - Code cleanup, PEP8 checkups # But I really does not matter about it :P

  *# FEATURES*
  - Added form.auto_validation method
  Now you don t need to always write if form.accepts()elif
  form.errors.
  Just use in this way:

   form = PowerFormWizard(db, steps)
  form.auto_validate()
  return dict(form=form)

  or
  # define flash message
  form.auto_validate(messages=['Yeah it works', 'Ops, error'])

  or

  #execute a function after validation
  def myfunction(success, x,y,z):
       #first argument receives True or False
  

  form.auto_validate(flash=my_function, args=[x, y, z])

  DEMO  DOWNLOAD :http://labs.blouweb.com/powerformwizard
  REPO:https://bitbucket.org/rochacbruno/powerformwizard

  *# Whats next?*
  working on a new plugin for the 'Power' family, it is a JSON based
  tableless grid (which is much more than a grid)
  hope to release with examples, by the end of the week, preview -
 http://labs.blouweb.com/PowerGrid

  Need help, contribution, test..

  []'s
  --
  Bruno Rocha
  [ About me:http://zerp.ly/rochacbruno]

 --

 --
 Bruno Rocha
 [ About me:http://zerp.ly/rochacbruno]
 [ Aprenda a programar:http://CursoDePython.com.br]
 [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
 [ Consultoria em desenvolvimento web:http://www.blouweb.com]


[web2py] headers argument behavior in v1.97.1

2011-07-07 Thread niknok
While using crud, I sometimes define headers for *some* fields listed in
the fields argument. This works until I upgraded to 1.97.1 and now I get
an error if I do not define the headers for *all* fields listed in the
fields argument.

For example, the following code no longer works

rows=crud.select(db.address
,query=((db.address.owner_is==address_owner)

(db.address.owner_is_person==address_owner_is_person))
,fields=['address.id'
,'address.line_1'
,'address.is_type'
,'address.country']
,headers={'address.id':'#'
,'address.line_1':'Street address'
,'address.country':'Country'})


until I add a header for address.is_type, too. 

Is this a bug or a new feature?


[web2py] Re: headers argument behavior in v1.97.1

2011-07-07 Thread niknok
Thanks for looking.

Code runs without errors in v1.96.1 but throws an error on 1.97.1.
Here's the traceback:

Traceback (most recent call last):
  File /home/rwn/Projects/web2py/gluon/restricted.py, line 192, in
restricted
exec ccode in environment
  File /home/rwn/Projects/web2py/applications/bbc/controllers/
donor.py, line 418, in module
  File /home/rwn/Projects/web2py/gluon/globals.py, line 137, in
lambda
self._caller = lambda f: f()
  File /home/rwn/Projects/web2py/gluon/tools.py, line 2415, in f
return action(*a, **b)
  File /home/rwn/Projects/web2py/applications/bbc/controllers/
donor.py, line 62, in address
,'address.country':'Country'})
  File /home/rwn/Projects/web2py/gluon/tools.py, line 3225, in
select
return SQLTABLE(rows,headers=headers,**attr)
  File /home/rwn/Projects/web2py/gluon/sqlhtml.py, line 1453, in
__init__
if isinstance(headers[colname],dict):
KeyError: 'address.line_3'

In prior versions, web2py will not complain about missing label and
just use the field name (or label in table definition) instead. I
suppose this new behavior is the right way of doing it and I should
just adjust the code accordingly, but IMO the old behavior handles the
issue more elegantly.


On Jul 7, 3:11 pm, Bruno Rocha rochacbr...@gmail.com wrote:
 Can you share some example app or model + controller code t reproduce the
 bug.

 Do you have a Traceback ticket error? what message, what file/line?

 The erro occurs when running the mentioned controller, or qhen doing some
 other action on this?

 Need more onfo to help tracking this issue.

 []'s









 On Thu, Jul 7, 2011 at 2:50 AM, niknok nikolai...@gmail.com wrote:
  **
  While using crud, I sometimes define headers for *some* fields listed in
  the fields argument. This works until I upgraded to 1.97.1 and now I get an
  error if I do not define the headers for *all* fields listed in the fields
  argument.

  For example, the following code no longer works

  rows=crud.select(db.address
                      ,query=((db.address.owner_is==address_owner)
                              
  (db.address.owner_is_person==address_owner_is_person))
                      ,fields=['address.id'
                                  ,'address.line_1'
                                  ,'address.is_type'
                                  ,'address.country']
                      ,headers={'address.id':'#'
                                  ,'address.line_1':'Street address'
                                  ,'address.country':'Country'})

  until I add a header for address.is_type, too.

  Is this a bug or a new feature?

 --

 --
 Bruno Rocha
 [ About me:http://zerp.ly/rochacbruno]
 [ Aprenda a programar:http://CursoDePython.com.br]
 [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
 [ Consultoria em desenvolvimento web:http://www.blouweb.com]


[web2py] Re: headers argument behavior in v1.97.1

2011-07-07 Thread niknok
Nope, I'm not using trunk.

And yes, now I know that I have do define *all* the headers while in
the old versions, that isn't a requirement. I guess it's part of being
explicit..

On Jul 7, 6:36 pm, Martín Mulone mulone.mar...@gmail.com wrote:
 Did you use trunk version?, I submitted recently some changes there.-

 2011/7/7 Bruno Rocha rochacbr...@gmail.com









  Can you share some example app or model + controller code t reproduce the
  bug.

  Do you have a Traceback ticket error? what message, what file/line?

  The erro occurs when running the mentioned controller, or qhen doing some
  other action on this?

  Need more onfo to help tracking this issue.

  []'s

  On Thu, Jul 7, 2011 at 2:50 AM, niknok nikolai...@gmail.com wrote:

  **
  While using crud, I sometimes define headers for *some* fields listed in
  the fields argument. This works until I upgraded to 1.97.1 and now I get an
  error if I do not define the headers for *all* fields listed in the fields
  argument.

  For example, the following code no longer works

  rows=crud.select(db.address
                      ,query=((db.address.owner_is==address_owner)
                              
  (db.address.owner_is_person==address_owner_is_person))
                      ,fields=['address.id'
                                  ,'address.line_1'
                                  ,'address.is_type'
                                  ,'address.country']
                      ,headers={'address.id':'#'
                                  ,'address.line_1':'Street address'
                                  ,'address.country':'Country'})

  until I add a header for address.is_type, too.

  Is this a bug or a new feature?

  --

  --
  Bruno Rocha
  [ About me:http://zerp.ly/rochacbruno]
  [ Aprenda a programar:http://CursoDePython.com.br]
  [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
  [ Consultoria em desenvolvimento web:http://www.blouweb.com]

 --
  http://martin.tecnodoc.com.ar


[web2py] Re: crud.search query

2011-07-03 Thread niknok
Bump. Anyone?


On Jul 1, 7:24 pm, niknok nikolai...@gmail.com wrote:
 I have field gender that is defined like so:

         Field('gender','reference aux_gender',notnull=True,widget=radio_h)

 The aux_gender table data were inserted from:

         db.aux_gender.insert(code='F',concept='Female')
         db.aux_gender.insert(code='M',concept='Male')

 I have a view that uses crud.search but couldn't search for records on
 gender field. Tried using record id (since they're saved as integers in
 database) but it doesn't produce any search results. Also tried M, and
 F to no avail.

 What am I doing wrong here?

 /r
 Nik

  w2p gender bender.png
 134KViewDownload

  w2p gender bender results.png
 59KViewDownload


[web2py] Re: new plugin - web2py Form Wizard - PowerFormWizard

2011-06-30 Thread niknok
In the validation example,  I entered a single character in the Bio
and was allowed to proceed to the next field despite the
db.person.bio.requires = IS_LENGTH(minsize=5, maxsize=200). You  made
a note about Client side validation is not supposed to validate
everything!, is this included in that exception?

A few suggestions:
* How about using description or details instead of the legend
keyword at it seems to be more appropriate for said function.

• As default behavior, instead of the default X errorImage beside
the step title, how about using an exclamation point icon to indicate
that this step needs attention and then in the specific field with an
error use the X icon instead.


The other day you answered my query re modal windows with a reference
to easyframework.com + web2py.

I pray that you have plans of adding that feature to your
PowerFormWizard Plugin (or perhaps turning this into a PowerForms
plugin to truly enable feature-full forms in Web2py?

Cheers and many thanks for your many contributions to the web2py
community.


/r
Nik


On Jun 29, 10:33 pm, Bruno Rocha rochacbr...@gmail.com wrote:
 Hi,

 I just created a new plugin for stepped form wizards.

 I made it last night, so it is not tested very well, I would like your help
 to test it.

 web2py PowerFormWizard Plugin - based on Jquery Stepy

 - Steps
 - Customizable titles
 - Server side validation
 - Client side validation (with jquery validate)
 - Custom css
 - JS Callbaks
 - Error images

 Take a look:http://labs.blouweb.com/powerformwizard

 This plugin is the second plugin of blouweb PowerPlugins, I am now starting
 the third one which I hope to have the first version soon.

 http://labs.blouweb.com

 Suggestions, testers, issues, contributions etc on 
 bitbucket:https://bitbucket.org/rochacbruno/powerformwizard

 Hope it helps someone!

 Thanks.

 --
 Bruno Rocha
 [ About me:http://zerp.ly/rochacbruno]
 [ Aprenda Python:http://CursoDePython.com.br]
 [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
 [ Consultoria em desenvolvimento web:http://www.blouweb.com]


[web2py] Re: new plugin - web2py Form Wizard - PowerFormWizard

2011-06-30 Thread niknok
Clarification regarding the bio field with requires. It does let me
proceed to the next step, but will not be allowed to submit the data
after validation unless i meet the requires statement.

A bit confusing since some fields will allow me to move to next step.

One more thing, is there going to be an equivalent for
SQLFORM.factory?



On Jun 30, 2:41 pm, niknok nikolai...@gmail.com wrote:
 In the validation example,  I entered a single character in the Bio
 and was allowed to proceed to the next field despite the
 db.person.bio.requires = IS_LENGTH(minsize=5, maxsize=200). You  made
 a note about Client side validation is not supposed to validate
 everything!, is this included in that exception?

 A few suggestions:
 * How about using description or details instead of the legend
 keyword at it seems to be more appropriate for said function.

 • As default behavior, instead of the default X errorImage beside
 the step title, how about using an exclamation point icon to indicate
 that this step needs attention and then in the specific field with an
 error use the X icon instead.

 The other day you answered my query re modal windows with a reference
 to easyframework.com + web2py.

 I pray that you have plans of adding that feature to your
 PowerFormWizard Plugin (or perhaps turning this into a PowerForms
 plugin to truly enable feature-full forms in Web2py?

 Cheers and many thanks for your many contributions to the web2py
 community.

 /r
 Nik

 On Jun 29, 10:33 pm, Bruno Rocha rochacbr...@gmail.com wrote:







  Hi,

  I just created a new plugin for stepped form wizards.

  I made it last night, so it is not tested very well, I would like your help
  to test it.

  web2py PowerFormWizard Plugin - based on Jquery Stepy

  - Steps
  - Customizable titles
  - Server side validation
  - Client side validation (with jquery validate)
  - Custom css
  - JS Callbaks
  - Error images

  Take a look:http://labs.blouweb.com/powerformwizard

  This plugin is the second plugin of blouweb PowerPlugins, I am now starting
  the third one which I hope to have the first version soon.

 http://labs.blouweb.com

  Suggestions, testers, issues, contributions etc on 
  bitbucket:https://bitbucket.org/rochacbruno/powerformwizard

  Hope it helps someone!

  Thanks.

  --
  Bruno Rocha
  [ About me:http://zerp.ly/rochacbruno]
  [ Aprenda Python:http://CursoDePython.com.br]
  [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
  [ Consultoria em desenvolvimento web:http://www.blouweb.com]


[web2py] Re: pop-up pages interface

2011-06-29 Thread niknok
This is interesting. Could you tell me how to use this in Web2py?

On Jun 29, 4:10 pm, Bruno Rocha rochacbr...@gmail.com wrote:
 if want an easy way...

 http://easyframework.com/+ web2py

 --
 Bruno Rocha
 [ About me:http://zerp.ly/rochacbruno]







 On Tue, Jun 28, 2011 at 5:32 AM, niknok nikolai...@gmail.com wrote:
  **
  Hello all.

  How can I create a web2py interface similar to that of the Chromium Browser
  when you need to change the browser settings?  I particularly like those
  screens where a page pops out and you can add/edit the details of a
  particular item you're interested in (i.e. the Autofill settings, etc.) Or
  when new pages appear in front of (dimmed) previous pages to show the
  hierarchy or menu level you're in.

  Thanks.

  /r
  Nik


[web2py] Re: new plugin - web2py Form Wizard - PowerFormWizard

2011-06-29 Thread niknok
+1

Another golden egg from the proverbial goose ... or gander, in this
case. :P

Thank you Bruno

On Jun 29, 10:33 pm, Bruno Rocha rochacbr...@gmail.com wrote:
 Hi,

 I just created a new plugin for stepped form wizards.

 I made it last night, so it is not tested very well, I would like your help
 to test it.

 web2py PowerFormWizard Plugin - based on Jquery Stepy

 - Steps
 - Customizable titles
 - Server side validation
 - Client side validation (with jquery validate)
 - Custom css
 - JS Callbaks
 - Error images

 Take a look:http://labs.blouweb.com/powerformwizard

 This plugin is the second plugin of blouweb PowerPlugins, I am now starting
 the third one which I hope to have the first version soon.

 http://labs.blouweb.com

 Suggestions, testers, issues, contributions etc on 
 bitbucket:https://bitbucket.org/rochacbruno/powerformwizard

 Hope it helps someone!

 Thanks.

 --
 Bruno Rocha
 [ About me:http://zerp.ly/rochacbruno]
 [ Aprenda Python:http://CursoDePython.com.br]
 [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
 [ Consultoria em desenvolvimento web:http://www.blouweb.com]


[web2py] Re: relational database example app

2011-06-19 Thread niknok
Google Translate thinks it's Swahili...

On Jun 19, 1:40 pm, Vineet vineet.deod...@gmail.com wrote:
 What is this tongue? (wewe andeya kuja nikufundishe web2py na ubebe
 nyama :D)

 It is my sincere thought that web2py group is for sharing the
 knowledge within the community.
 Kindly write something which others can understand.
 For any personal matter, one can use emails.

 On Jun 18, 11:26 am, kesh johnmah...@gmail.com wrote:







  wewe andeya kuja nikufundishe web2py na ubebe nyama :D

  On May 24, 11:46 pm, Markandeya mrc55...@gmail.com wrote:

   Ok i found some appliances on the Appliances web page and that is very
   helpful. Which ones are considered good coding standards/practices to
   follow?? Which would you advise to get started with??
   Any recommendations or suggestions would be appreciated. Thanks again,
   Markandeya


[web2py] Re: Social network plug-in

2011-06-19 Thread niknok
Can someone post this somewhere where resume download is supported? I
got a crappy connection right now...

On Jun 12, 12:09 am, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 Here is the source of the facebook clone

  web2py.app.friends.w2p
 1002KViewDownload


[web2py] Re: web2py book changelog?

2011-06-16 Thread niknok
Yes. Same reason I asked.

Thanks.

On Jun 14, 6:10 am, Sebastian E. Ovide sebastian.ov...@gmail.com
wrote:
 web2py is adding so many functionalities that it is difficult to understand
 what the book is documenting.

 It would be great to have a changelog... or at least a web2py version that
 the book is referring to

 On Sat, Jun 11, 2011 at 2:19 AM, niknok nikolai...@gmail.com wrote:

  Is there like a change log for the web2py book where I can view what's been
  added or modified recently?

  /r

 --
 Sebastian E. Ovide


[web2py] web2py book changelog?

2011-06-10 Thread niknok

Is there like a change log for the web2py book where I can view what's
been added or modified recently?

/r


[web2py] Re: recommendations for production system?

2011-05-18 Thread niknok
It's nice to see feedback from real users of these hosts. Could you
please add how much traffic you got with those plans you have?

On May 18, 6:54 am, Carlos carlosgali...@gmail.com wrote:
 Hi all,

 In order to prepare my web2py production system, I would really welcome all
 your advice.

 I will get one node from vps.net:

    http://vps.net/product/cloud-servers
    dedicated cpu = 0.6 GHz
    dedicated ram = 376 MB
    disk space = 10 GB
    network transfer = 250 GB

 I am planning to install the following software:

    os = ubuntu 10.04 (lucid) x64 basic installation
    web = apache2
    db = postgresql
    sh =http://web2py.googlecode.com/hg/scripts/setup-web2py-ubuntu.sh

 Is the above the recommended configuration (based on my one node capacity @
 vps.net)?.

 I've read that nginx web server is really good, should I reconsider this?,
 instead or in addition to apache?.

 Would you recommend a different configuration if I eventually add more
 nodes/capacity?.

 Any other software?, e.g. web server control panels?.

    - isp manager
    - webmin
    - virtualmin
    - landscape

 Thanks in advance for all your recommendations.

 p.s. my experience has been mostly with Windows.

    Carlos


[web2py] Re: using CRYPT in SQLFORM.factory doesn't work?

2011-05-12 Thread niknok
Nice catch Anthony! Thanks a bunch.

That's the second time I got bitten by a misplaced comma in an
SQLFORM ...

On May 12, 12:23 pm, Anthony abasta...@gmail.com wrote:
 I think you've got a simple typo in you code -- in SQLFORM.factory, you have
 a ')' at the end of the Field line, so your 'requires' ends up being a
 SQLFORM.factory argument instead of a Field argument. It should be:

     form=SQLFORM.factory(
         Field('card_number','string',comment='with dashes',
               requires=CRYPT(auth.settings.hmac_key)))
 When I try the above, CRYPT works fine for me.

 Anthony







 On Wednesday, May 11, 2011 11:02:17 PM UTC-4, niknok wrote:
  here's the code I used.
 http://pastie.org/1891534

  what's weird is that I know that CRYPT works in my other apps, it's
  just in this particular controller that it isn't working right.

  And in my case, my logical test is == and not !=. My problem is
  the unecrypted
   variable...


[web2py] Re: using CRYPT in SQLFORM.factory doesn't work?

2011-05-12 Thread niknok
Ok, here's a quote for you:
“Confusion is the welcome mat at the door of creativity.”

;)

On May 13, 2:26 am, pbreit pbreitenb...@gmail.com wrote:
 I suppose it's personal preference but the comma placement at the beginning
 of the line is really confusing.


[web2py] Re: update is not saved in the database??

2011-05-11 Thread niknok

I can't, there's no record instance... So it's .update for me.

On May 11, 12:53 am, Thadeus Burgess thade...@thadeusb.com wrote:
 Use ``update_record`` instead of ``update``.

 the ``update`` function comes from the dict parent class, and does not issue
 SQL.

 ``update_record`` is a web2py thing that will take any changes made to the
 record instance (by use of assignment or update function) and issue the
 appropriate SQL

 --
 Thadeus







 On Mon, May 9, 2011 at 9:37 PM, niknok nikolai...@gmail.com wrote:
  Yes, guys thanks. I realized that that was the culprit this morning.
  Hard to decode with beer fogging your thoughts... :P

  Reverted to the original and all is working again. I forgot I was
  testing that line from a code in the book.

  On May 9, 11:01 pm, Anthony abasta...@gmail.com wrote:
   On Monday, May 9, 2011 10:45:36 AM UTC-4, niknok wrote:

I have these lines that is supposed to update a record but it doesn't:

    db.card.validated.writable=True
    db.card.modified_by.writable=True

  db.card(db.card.alnum==c_hash).update(validated=True,modified_by=auth.user.
  id)

Is there anything I missed? I tried to include a manual db.commit(),
  but
that didn't work either.

   You can use the db.card(db.card.alnum==c_hash) notation to fetch a row
   (though I think you have to include the record ID as the first argument),
   but I'm not sure you can use it to update a record. For that, you may
  have
   to use the usual query notation: db(db.card.alum==c_hash).update(...).
  You
   might also be able to use your original notation along with
  update_record,
   but I don't see any reason to prefer that over the usual method.

   Anthony


[web2py] Re: using CRYPT in SQLFORM.factory doesn't work?

2011-05-11 Thread niknok
here's the code I used.
http://pastie.org/1891534

what's weird is that I know that CRYPT works in my other apps, it's
just in this particular controller that it isn't working right.

And in my case, my logical test is == and not !=. My problem is
the unecrypted
 variable...


On May 10, 10:54 pm, Anthony abasta...@gmail.com wrote:
 On Tuesday, May 10, 2011 2:10:07 AM UTC-4, niknok wrote:

  Anthony, sorry for the typo. I meant calling onvalidation=, and not
  onaccept

  That is the behavior I'm expecting, since I've seen that work like so
  before. Here's a stripped-down version of the function:

  def cnv():
      c_hash=request.args(0)
      form=SQLFORM.factory(
          Field('card_number','string'
                  ,label='Card number',comment='with dashes')
                  ,requires=CRYPT(auth.settings.hmac_key))
      if form.accepts(request.vars,session):
          #import ipdb;ipdb.set_trace()
          #if c_hash!= form.vars.card_number:     #-- does not work

 What do you mean the above does not work? Are you expecting
 form.vars.card_number to equal c_hash (if so, shouldn't '!=' be '==')? Where
 does c_hash come from (i.e., how does it get in request.args)?

          if CRYPT(auth.settings.hmac_key)(form.vars.card_number)
  [0]==c_hash:

 What is the purpose of the above line? form.vars.card_number should already
 be hashed (form.accepts should result in it being hashed), so this line
 appears to be double hashing the card number, which I assume wouldn't match
 c_hash (assuming c_hash is supposed to be the hashed card number).

 Anthony


[web2py] Re: drop down box content depends of another drop box

2011-05-10 Thread niknok
search cascading select or cascading dropdowns

On May 10, 1:24 pm, pepe_eloy pepe.e...@gmail.com wrote:
 Hello!

 How can I fill a drop box widget with content depends of another drop
 box? I'll explain better: I have 3 tables:

 db.define_table('categoria',
                 SQLField('nombre', notnull=True),
                 format='%(nombre)s')

 db.define_table('subcategoria',
                 SQLField('categoria',db.categoria, label=Categoría),
                 SQLField('nombre'),
                 format='%(nombre)s')

 db.define_table('empresa',
                 SQLField('categoria',db.categoria, label=Categoría),
                 SQLField('subcategoria', db.subcategoria,
 label=Subcategoría),
                 SQLField('nombre'),
                 SQLField('contenido','text'),
                 format='%(nombre)s')

 db.categoria.nombre.requires=[IS_NOT_EMPTY(), IS_NOT_IN_DB(db,
 db.categoria.nombre)]
 db.subcategoria.nombre.requires=[IS_NOT_EMPTY(), IS_NOT_IN_DB(db,
 db.subcategoria.nombre)]
 db.empresa.nombre.requires=[IS_NOT_EMPTY(), IS_NOT_IN_DB(db,
 db.empresa.nombre)]

 One categoria may have many subcategorias, and I'd like the contents
 of subcategorias change depending of the content of categoria,
 Somebody has any suggestion to do this?

 Thanks in advanced


[web2py] Re: using CRYPT in SQLFORM.factory doesn't work?

2011-05-10 Thread niknok
Anthony, sorry for the typo. I meant calling onvalidation=, and not
onaccept

That is the behavior I'm expecting, since I've seen that work like so
before. Here's a stripped-down version of the function:

def cnv():
c_hash=request.args(0)
form=SQLFORM.factory(
Field('card_number','string'
,label='Card number',comment='with dashes')
,requires=CRYPT(auth.settings.hmac_key))
if form.accepts(request.vars,session):
#import ipdb;ipdb.set_trace()
#if c_hash!= form.vars.card_number: #-- does not work
if CRYPT(auth.settings.hmac_key)(form.vars.card_number)
[0]==c_hash:
db.card.validated.writable=
db.card.modified_by.writable=True
db(db.card.alnum==c_hash).update(validated=True)
response.flash='Card number validated.'
else:
form.errors.card_number='Card number is not valid!'
return dict(form=form)

On May 10, 12:11 pm, Anthony abasta...@gmail.com wrote:
 On Monday, May 9, 2011 10:59:46 PM UTC-4, pbreit wrote:

  Do filters work with SQLFORM.factory? I'm not sure CRYPT returns an
  encrypted string so much as it causes the string to be encrypted when
  SQLFORM puts it in the DB. I could be wrong.

 When I create a SQLFORM.factory with a requires=CRYPT and call form.accepts,
 I get back a hash of the input, even without any db IO.

 Anthony


[web2py] using CRYPT in SQLFORM.factory doesn't work?

2011-05-09 Thread niknok
I tried:

form=SQLFORM.factory(
Field('card_number','string'
,label='Enter a card number to verify'
,requires=CRYPT(auth.settings.hmac_key))

But instead I found form.vars.card_number unencrypted.  This is on w2p
v1.94.5.

/r
Nik


[web2py] update is not saved in the database??

2011-05-09 Thread niknok
I have these lines that is supposed to update a record but it doesn't:

db.card.validated.writable=True
db.card.modified_by.writable=True

db.card(db.card.alnum==c_hash).update(validated=True,modified_by=auth.user.id)


Is there anything I missed? I tried to include a manual db.commit(), but
that didn't work either.


[web2py] Re: represented fields and jqgrid

2011-05-09 Thread niknok
pbreit, config is a Storage() object and member_status a Dictionary,
and the python get() function.

Ross, you're right. That's how I'm using it.  I went back to re-check
my definition file and everything appears to be in order. Note that
it's only in jqgrid that it's not showing up, it works correctly with
appadmin

In the model:
settings.member_status={
0:'Pending'
,2:'Blocked'
,4:'Verified'
}

...
Field('member_status','integer',default=0)
...
db.auth_user.member_status\
.requires=IS_IN_SET(settings.member_status,zero=None,sort=False)

If I don't define the representation, it doesn't use the hard coded
dictionary options. After I define the representation, it still
doesn't show up in jQuery.

I'm using version 1.94.6. What version are you using?

On May 6, 11:14 pm, Ross Peoples ross.peop...@gmail.com wrote:
 I had similar issues with computed fields. I don't know if this helps or
 not, but it looks like you are using member_status as a selection of hard
 coded options. This is what I do:

 db.member_statuses = {
   1: 'Active',
   2: 'Inactive',}

 db.define_table('auth_user_extended',
   Field('auth_user', db.auth_user),
   Field('member_status', 'int', requires=IS_IN_SET(db.member_statuses),
 default=1),
   ...
 )

 Then when the field is represented, it should use the values from dictionary
 ('Active' or 'Inactive') automatically without having to set represent. I
 hope this helps, as it's worked for me pretty well so far.


[web2py] Re: using CRYPT in SQLFORM.factory doesn't work?

2011-05-09 Thread niknok
I was trying to process it inside onvalidation= ...

On May 9, 10:53 pm, Anthony abasta...@gmail.com wrote:
 On Monday, May 9, 2011 10:37:02 AM UTC-4, niknok wrote:

  I tried:

      form=SQLFORM.factory(
          Field('card_number','string'
                  ,label='Enter a card number to verify'
                  ,requires=CRYPT(auth.settings.hmac_key))

  But instead I found form.vars.card_number unencrypted.  This is on w2p
  v1.94.5.

 Was it unencrypted before or after calling form.accepts? The validators
 aren't applied until you call form.accepts.


[web2py] Re: update is not saved in the database??

2011-05-09 Thread niknok
Yes, guys thanks. I realized that that was the culprit this morning.
Hard to decode with beer fogging your thoughts... :P

Reverted to the original and all is working again. I forgot I was
testing that line from a code in the book.

On May 9, 11:01 pm, Anthony abasta...@gmail.com wrote:
 On Monday, May 9, 2011 10:45:36 AM UTC-4, niknok wrote:

  I have these lines that is supposed to update a record but it doesn't:

      db.card.validated.writable=True
      db.card.modified_by.writable=True
      
  db.card(db.card.alnum==c_hash).update(validated=True,modified_by=auth.user. 
  id)

  Is there anything I missed? I tried to include a manual db.commit(), but
  that didn't work either.

 You can use the db.card(db.card.alnum==c_hash) notation to fetch a row
 (though I think you have to include the record ID as the first argument),
 but I'm not sure you can use it to update a record. For that, you may have
 to use the usual query notation: db(db.card.alum==c_hash).update(...). You
 might also be able to use your original notation along with update_record,
 but I don't see any reason to prefer that over the usual method.

 Anthony


[web2py] Re: requires questions

2011-05-08 Thread niknok
Thanks for the suggestion. I tried it but I was unable to make use of
it. Your suggestion did force me to rethink the design so I discarded
the full IS_MATCH  string(can't even remember why I went for that),
and simply kept the expression string itself (i.e. '^\\d{3}-\\d{4}-\
\d{4}-\\d{1}?$')

And now it works and looks much cleaner without eval() ...

requires=[IS_MATCH(str(db.agency[int(request.vars.issuer or
1)].regex)),CRYPT(auth.settings.hmac_key),IS_NOT_IN_DB(db,'card.id_number')]

Thanks

On May 7, 12:04 am, pbreit pbreitenb...@gmail.com wrote:
 Maybe the IS_EXPR() validator?

 IS_EXPR
 IS_EXPR

 Its first argument is a string containing a logical expression in terms of a
 variable value. It validates a field value if the expression evaluates to
 True. For example:

 1.
 2.

 requires = IS_EXPR 
 http://web2py.com/book/default/docstring/IS_EXPR('int(value)%3==0',
                    error_message=T 
 http://web2py.com/book/default/docstring/T('not divisible by 3'))


[web2py] Re: skinning a cat ...

2011-05-08 Thread niknok
@Niphlod
Yes, that would be interesting.

On May 7, 4:09 am, Niphlod niph...@gmail.com wrote:
 go for raw sql if you need to, but be aware that that article was
 written in 2007, testing only MS SQL Server behaviour  we are in
 2011, MS SQL Server 2008 is on the run (and that article could be
 referring only to the 2000 or 2005 version)...

 Hopefully MS ingeneers have found (or will find) how to optimize
 different queries that lead to the same dataset in the exact same
 amount of time.

 I don't have the time to test right now, but at work I have to deal
 with MS SQL every day...if you want I can do some tests. right now
 I wonder also if it will be faster (I'm thinking exclusively to MS
 SQL) to do the same query again but using a different approach: left
 outer join and checking NULLs.

 Web2py implements a way to filter the data as you want (and give you a
 chance to use whatever raw query you want to)... it's database's
 engineers work to deal with this kind of optimization (or it's on you
 to use raw SQL, or to pick another database at all :-P)

 On 6 Mag, 18:12, pbreit pbreitenb...@gmail.com wrote:







  I didn't see EXISTS in 
  dal.py:http://code.google.com/p/web2py/source/browse/gluon/dal.py

  That seems like it might be a tricky optimization to program but perhaps
  it's possible.

  You could also use raw sql:http://web2py.com/book/default/chapter/06#Raw-SQL


[web2py] custom attributes

2011-05-08 Thread niknok
Massimo (or anyone who'd like to pitch in)

You made this suggestion when I asked a question about a help system. 


Field('name',...) 
db.table.name.help = 'custom attribute' 


Could you please elaborate on this, and perhaps add a use case or
example?

Also, I was reading the code of register_other() of conf2py, and I found
these 2 lines that I don't quite understand:

db.auth_user.registered_by.default=auth.user.id
record=db.auth_user(request.args(0) or 0,registered_by=auth.user.id)

Why isregistered_by=auth.user.id supplied when it's already preceded
by a line that tells the database that it should use auth.user.id as the
default value. And I don't recall reading this convention of assigning
values to a record being retrieved.

/
Nik


[web2py] Re: CRUD.search sorting order

2011-05-06 Thread niknok
Thanks for the response Villas.

Do note that my use of
   fields=['id','last_name','first_name', ...
is based on examples in the book . I tried your suggestions, sadly,
I'm getting a KeyError error message. W2P complaining about the
db.auth_user table names... Have you tried this out yourself and is
it working in your system?

As for orderby, the use of built-in python functions (i.e.
orderby=db.auth_user.last_name.lower() ...) are documented in the
book.

So I suppose the issue is something else?

/r

On May 4, 11:45 pm, villas villa...@gmail.com wrote:
 I should have also said that I think the fields should be fields and
 not strings:
 i.e.
 fields = [db.auth_user.id, db.auth_user.last_name, ]

 On May 4, 2:47 pm, niknok nikolai...@gmail.com wrote:







  I'm using v1.94.6 and retrieving ordered search results from crud.search
  always produces a list sorted by id

  Tried various combinations:

      orderby=db.auth_user.last_name
      orderby=db.auth_user.birth_date
      orderby=db.auth_user.last_name.lower()|db.auth_user.first_name.lower()

  Attached is a screenshot with orderby set to last entry above.

  The code I use is:

  form,rows = crud.search(db.auth_user
      ,query=(db.auth_user.account_type==0)(db.auth_user.id!=auth.user.id)
      ,fields=['id','last_name','first_name','middle_name','birth_date']
      ,orderby=db.auth_user.last_name.lower()|db.auth_user.first_name.lower()
      ,queries=['equals','contains','starts with','ends with','greater 
  than','less than'])

  Did I miss anything or doing something wrong here?

  /r
  Nik

   crud.search-sorting.png
  103KViewDownload


[web2py] skinning a cat ...

2011-05-06 Thread niknok
this SQL statement :

SELECT agency.card_type FROM agency 
WHERE agency.id NOT IN (select issuer from card where person=1)

is equivalent in DAL:


registered_cards=db(db.card.person==1)(db.card.issuer==db.agency.id)._select(db.card.issuer)
unregistered_cards=db((db.agency.is_active==True)  
(~db.agency.id.belongs(registered_cards)))


The following SQL statement is functionally the same as above:

SELECT a.card_type FROM agency AS a
WHERE NOT EXISTS (SELECT issuer FROM card as c WHERE c.issuer=a.id AND 
c.person=1)

But according to this page, EXISTS operator (also UNION ALL, LEFT JOIN)
is more efficient and several factors faster than NOT IN:
http://weblogs.sqlteam.com/peterl/archive/2007/09/20/Finding-records-in-one-table-not-present-in-another-table.aspx

I'm curious if there is an EXISTS operator equivalent in DAL?

/r 
Nik


[web2py] requires questions

2011-05-06 Thread niknok
I'm doing a requires statement so the id number matches a prescribed
format, encrypt it, and then store it in the database (if it isn't a
duplicate number) 


db.card.id_number.requires=[eval(db.agency[int(request.vars.id_number)].regex),CRYPT(),IS_NOT_IN_DB(db,'card.id_number')


Do you use eval() and strings for validation? I've tested eval() in a
Shell for validation like: 

eval(db.agency[id].regex)('')

where regex column is something like: IS_MATCH('^\\d{3}-\\d{4}-\\d{4}-\
\d{1}?$') or Null, and it works! The idea, is that every record in the
administrative table comes with the regex needed to validate the id
number.

But when I try it in a requires statement, it complains that
request.vars.id_number is not valid, but I couldn't place an expression
inside eval(). I already have a CRUD form that uses a validation routine
called by onaccept, but I'm wondering if I could replace it instead with
just a requires statement. 

I use it like this in my custom validation:

if (db.agency[int(form.vars.issuer)].regex and\
eval(db.agency[int(form.vars.issuer)].regex)(form.vars.id_number)[1]!= 
None):
form.errors.id_number='Enter id number exactly as shown in your card.'

Looking forward to hear your suggestions. TIA.

/r
Nik 


[web2py] Re: represented fields and jqgrid

2011-05-06 Thread niknok
bump...

Anyone?

On May 5, 8:27 am, niknok nikolai...@gmail.com wrote:
 I .represent a field as follows:

         db.auth_user.gender.represent=lambda i: db.aux_gender[i].concept[:1] 
 if i0 else '?'
         db.auth_user.member_status.represent=lambda i: 
 config.member_status.get(i)[:1] or '?'

 The first one works, and displays data in jqgrid as expected:'M','F'
 or'?'. The second only shows a blank cell in jqgrid.

 I tried a DAL select query and crud.search and the data is represented
 correctly.


[web2py] represented fields and jqgrid

2011-05-05 Thread niknok
I .represent a field as follows:

db.auth_user.gender.represent=lambda i: db.aux_gender[i].concept[:1] if 
i0 else '?'
db.auth_user.member_status.represent=lambda i: 
config.member_status.get(i)[:1] or '?'


The first one works, and displays data in jqgrid as expected:'M','F'
or'?'. The second only shows a blank cell in jqgrid.

I tried a DAL select query and crud.search and the data is represented
correctly.


[web2py] getting characters before encryption

2011-05-05 Thread niknok
I have SSNs in a table as text strings. I'm planning to use CRYPT() on
the web2py app fields that will store these SSNs.

define_table('identity_card'
,Field('person', 'reference auth_user')
,Field('id_type', 'reference valid_id')
,Field('id_number','string',requires=CRYPT()
,Field('id_prefix',compute=lambda r: r['id_number'][:4])
)



The 'id_prefix' field is for human users facilitating person
verification, without having to ask for the full id number. As it is,
the id_prefix will take the first 4 chars of the hashed id number, and
not the original string. Right now I use a custom form that takes in the
id_number, without encryption, take the id_prefix, then encrypt the
id_number and finally do a manual insert into the database.

Is there a way to get the prefix characters before encryption without a
custom form?




[web2py] Re: jquery for triggering change in dropdown list values

2011-05-03 Thread niknok
Right now, I just generate a list from the database and feed it into a
IS_IN_SET validator. It worked out faster than slice 85.

On May 2, 11:38 pm, Anthony abasta...@gmail.com wrote:
 On Sunday, May 1, 2011 11:56:55 PM UTC-4, niknok wrote:

  Thanks Anthony.

  I've actually tried that, but it was a tad too slow for me. :(

 Bummer. If you figure out an alternative, let us know.


[web2py] Re: button action

2011-05-03 Thread niknok
The old function I used passed values using args. Now I'm using
session variables instead, so I need a way to move forward and
backward between records.

I need the button to decrement the session variable, then redirect to
the page.

On May 2, 9:36 pm, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 http://mywiki.wooledge.org/XyProblem

 what do you want to do exactly?

 On May 1, 8:04 pm, niknok nikolai...@gmail.com wrote:







  I have this button that redirects to a URL:

  form[0][-1][1].append(INPUT(_type='button',_value=T('Previous')
                              ,_onclick='document.location=%s' 
  %URL(question)))

  what do I add to _onclick to do the following:
  1) session.current_item -=1
  2) redirect(URL('question'))

  /r
  Nik


[web2py] Re: button action

2011-05-03 Thread niknok
+1 for the link :P

On May 2, 9:36 pm, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 http://mywiki.wooledge.org/XyProblem

 what do you want to do exactly?

 On May 1, 8:04 pm, niknok nikolai...@gmail.com wrote:







  I have this button that redirects to a URL:

  form[0][-1][1].append(INPUT(_type='button',_value=T('Previous')
                              ,_onclick='document.location=%s' 
  %URL(question)))

  what do I add to _onclick to do the following:
  1) session.current_item -=1
  2) redirect(URL('question'))

  /r
  Nik


[web2py] displaying user's local time

2011-05-03 Thread niknok
How do I display the user's local time in a form?


[web2py] expression question

2011-05-01 Thread niknok
I'm wondering why this doesn't work:

delta=datetime.timedelta(seconds=15*60)
db(request.now(db.qa.time_start+delta)).count()

TypeError: can't compare datetime.datetime to Expression


while this one does:

delta=datetime.timedelta(seconds=15*60)
db(db.qa.time_start(request.now-delta)).count()


Struggled with that line all afternoon, and out of frustration decided
to transpose the values, and suddenly it worked.

/r
Nik


[web2py] joins in crud select

2011-05-01 Thread niknok
Can I do joins in CRUD?

I'm getting a 404 Not Found error with this: 


rows=crud.select(db((db.qa.candidate==user_id)(db.quiz.id==db.qa.quiz)))


But the following works alright: 

rows=db((db.qa.candidate==user_id)(db.qa.quiz==db.quiz.id)).select()



/r
Nik 


[web2py] button action

2011-05-01 Thread niknok
I have this button that redirects to a URL:

form[0][-1][1].append(INPUT(_type='button',_value=T('Previous')
,_onclick='document.location=%s' 
%URL(question)))

what do I add to _onclick to do the following:
1) session.current_item -=1
2) redirect(URL('question'))

/r
Nik


[web2py] Re: jquery for triggering change in dropdown list values

2011-05-01 Thread niknok
Thanks Anthony.

I've actually tried that, but it was a tad too slow for me. :(

On May 1, 12:32 pm, Anthony abasta...@gmail.com wrote:
 This may help:http://www.web2pyslices.com/main/slices/take_slice/85







 On Saturday, April 30, 2011 10:53:16 PM UTC-4, niknok wrote:
  I am clueless about jQuery, but I'm wondering if there's any script I can
  use to trigger a change the values in one dropdown list after selecting a
  value from another dropdown list in a CRUD form?

  Right now, I used a jquery script I picked up in the list that initiates a
  submit action. The consequence of that, however, is that it submits the
  whole form while there are other fields yet to be filled up.

  Thanks.

  /r Nik


[web2py] Re: readable/writable settings of auth.signature

2011-04-30 Thread niknok
Yes, it did work. Sorry for that post.

My error was that I should have set both to False but I was only
setting .readable=False, but not doing the same to .writable.

Thanks!

/r
Nik





On Apr 29, 9:45 pm, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 It should work. Can you post your model so I can try it?

 On Apr 29, 2:09 am, niknok nikolai...@gmail.com wrote:







  I'm trying to set it like this: db.mytable.is_active.readable=False
  but it doesn't appear to be working as they still show up in the CRUD
  forms I make.

  Is there a way to individually set the readable, writable settings for
  each field that auth.signature creates?


[web2py] IS_IN_DB label from two tables

2011-04-30 Thread niknok
The following validator doesn't work: 

IS_IN_DB(db(db.g_province.id==db.g_municipality.province)\
,db.g_municipality.psgc_m\
,label='%(g_municipality.name)s (%(g_province.name)s)')


I am trying to generate a select option that shows a label consisting of
the g_province.name and g_municipality.name fields. How do I do that?

Thanks.
/r
Nik 


[web2py] Re: selecting a value in dropdownlist reference to another value in dropdownlist

2011-04-30 Thread niknok
How can I add something like this in a CRUD form?

On Apr 26, 1:26 am, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 I would do something like this:

 db.define_table('nominee',Field('name'),Field('region_id',db.Regions))

 def get_nominees():
     region_id = request.vars.region_id
     return TAG[''](*[OPTION(r.name,_value=r.id) for r in
 db(db.nominee.region_id=region_id).select()])

 def get_form():
     script=
     jQuery(function(){jQuery('input[name=region_id]').keyup(function()
 {
        var region_id = jQuery('input[name=region_id]').val();
        jQuery.post('{{=URL('get_nominees')}}', { region_id:
 region_id }, function(data, textStatus, jqXHR){
           Query('select[name=nominee]').html(data);
        });});});
     
     form =
 FORM(INPUT(_name='region_id'),SELECT(_name='nominee'),INPUT(_type='submit') 
 ,script)

 On Apr 25, 11:45 am, Mohamed Sami melsa...@gmail.com wrote:







  Hi All,

  I'm making a website for elections,
  so i have table for Governorates definition, then region definition
  related to Governorate

  also i created a table for nominees which is related to each region
  and each region can have more than one nominee.

  also i have a table for voters who is living in a chosen region, and
  he should choose a nominee which is related only to these region.

  my table like:

  db.define_table('Voters', Field('name', label = 'Full Name'),
     Field('national_id', label ='National ID', unique= True, length
  =14),
     Field('email', label ='Email Address'),
     Field('region_id', db.Regions,label ='Region'),
     Field('Nominee_id', db.Nominees, label ='Nominee Name'))

  i want to create a form for adding new voter and in this form he can
  choose his nominee based on his living region. so i want the form to
  automatically show the governorates list, the regions list based on
  selected governorate, then show the nominees list based on selected
  region.

  is there any solution for this.

  thank you


[web2py] multi-select dropdown behavior with plugin_wiki installed

2011-04-30 Thread niknok
When plugin_wiki is installed, the multi-select dropdown uses a
different dropdown widget. 

Although it indicates how many items are selected, is there a way to
make it show at least one of the items checked by default? I also miss
the ability to type a letter and get to those items beggining with that
letter.

Is there a way to restore the original dropdown widget even if
plugin_wiki is installed?

Thanks.

/r 
Nik 


[web2py] redirect to series of pages/functions after registration

2011-04-30 Thread niknok
After registration, user is automatically logged in (when verification
is set to False). How do I direct a newly registered user to a series of
pages?

I have a number of pages, I would like a user to go through. I tried: 

auth.settings.register_next =[URL(c='default',f='profile'), 
URL(c='default',f='address',args=(0,user_id,1,1))]


But, it only works for a single page.  I thought of adding the redirect
at the end of each function, but those functions are later accessed
without the need for redirection.

Any suggestions on how to go about this?

On a related note, is it possible for one function to call another
function without re-directing and then return to the calling function. I
tried it like:

def new_user():
do_this()
do_that()
and_this_too()
return dict()


Thanks.

/r
Nik






[web2py] jquery for triggering change in dropdown list values

2011-04-30 Thread niknok
I am clueless about jQuery, but I'm wondering if there's any script I
can use to trigger a change the values in one dropdown list after
selecting a value from another dropdown list in a CRUD form?

Right now, I used a jquery script I picked up in the list that initiates
a submit action. The consequence of that, however, is that it submits
the whole form while there are other fields yet to be filled up.

Thanks.

/r Nik 


[web2py] table cleanup

2011-04-30 Thread niknok
Where should I run a function whose task is to maintain the status of a
table record?

For example, I have a survey table with the column status. A record's
status is open when a user answers it, and it is set to completed
when a user finishes answering it. But, if in case the user doesn't
finish answering it the status remains open, and I want to set to
something like expired if it isn't completed after a period of time.

Thanks,

/r 
Nik 


[web2py] Re: debugging help. type 'exceptions.KeyError' when trying to edit a record.

2011-04-29 Thread niknok
Argh! It was a logic error. I was accessing a different database.
Thanks anyway.

On Apr 29, 11:43 am, niknok nikolai...@gmail.com wrote:
 The following model and controller works fine when adding records, but
 generates an error type 'exceptions.KeyError'('issuer') when I try
 to edit a record. Unfortunately for me, I couldn't understand what
 that error actually means, or what I missed doing.

 Could someone give me a nudge forward? Thanks.

 /r
 Nik

 code is here:http://pastie.org/1845934


[web2py] readable/writable settings of auth.signature

2011-04-29 Thread niknok
I'm trying to set it like this: db.mytable.is_active.readable=False
but it doesn't appear to be working as they still show up in the CRUD
forms I make.

Is there a way to individually set the readable, writable settings for
each field that auth.signature creates?


[web2py] debugging help. type 'exceptions.KeyError' when trying to edit a record.

2011-04-28 Thread niknok
The following model and controller works fine when adding records, but
generates an error type 'exceptions.KeyError'('issuer') when I try
to edit a record. Unfortunately for me, I couldn't understand what
that error actually means, or what I missed doing.

Could someone give me a nudge forward? Thanks.

/r
Nik

code is here: http://pastie.org/1845934


[web2py] using another unique column in IS_IN_DB

2011-04-24 Thread niknok
I have the following: 
db.profile.citizenship.requires=IS_IN_DB(gdb,'country.iso2',
'%(name)s',multiple=True,zero=None)

It works fine until I try accessing the record from appadmin (I can view
the table, it fails when I view a specific record), which dumps me this:

Traceback (most recent call last):

  File /home/erwin/Projects/web2py/gluon/restricted.py, line 188, in 
restricted
exec ccode in environment
  File /home/nrg/Projects/web2py/applications/bbc/controllers/appadmin.py, 
line 412, in module
  File /home/nrg/Projects/web2py/gluon/globals.py, line 124, in lambda
self._caller = lambda f: f()
  File /home/nrg/Projects/web2py/applications/bbc/controllers/appadmin.py, 
line 275, in update
f='download', args=request.args[:1]))
  File /home/nrg/Projects/web2py/gluon/sqlhtml.py, line 815, in __init__
inp = self.widgets.multiple.widget(field, default)
  File /home/nrg/Projects/web2py/gluon/sqlhtml.py, line 272, in widget
return OptionsWidget.widget(field, value, **attributes)
  File /home/nrg/Projects/web2py/gluon/sqlhtml.py, line 206, in widget
options = requires[0].options()
  File /home/nrg/Projects/web2py/gluon/validators.py, line 430, in options
self.build_set()
  File /home/nrg/Projects/web2py/gluon/validators.py, line 413, in build_set
fields = [self.dbset.db[self.ktable][k] for k in self.fields]
  File /home/nrg/Projects/web2py/gluon/dal.py, line 3898, in __getitem__
return dict.__getitem__(self, str(key))
KeyError: 'country'


[web2py] bpython shell

2011-04-24 Thread niknok
My 0.01 dollar opinion.

Two weeks after trying it out, I've had it. It's actually nice except
for the crashes - which I get lots of. So, I lose the code I'm trying
out. Its auto-completion doesn't even help redeem it. I'm back to the
robust iPython shell, now with ipdb installed, it gives iPython the
auto-completion I'm after in bpython.

If only it could be more forgiving for newbies like me, and crashed
much, much less ...

/r
Nik 


[web2py] Re: IS_IN_DB validator

2011-04-24 Thread niknok
Found the answer: orderby is supported.

IS_IN_DB(dbset, field, orderby='mytable.myfield', ...)

On Apr 24, 8:31 am, niknok nikolai...@gmail.com wrote:
 Thanks. But I guess I did not explain myself properly.

 I would like the list to display the titles, but sorted by say the ID
 field, or another field.

 Right now, I do it like label='%(id)s%(title)s', but I'd like to
 display it without the ID. I hope this makes sense.

 On Apr 23, 10:30 pm, DenesL denes1...@yahoo.ca wrote:







  Yes, use the label parameter e.g.

  IS_IN_DB(dbset, field, label='%(title)s', ...)

  On Apr 23, 8:59 am, niknok nikolai...@gmail.com wrote:

   Is there a way to sort the list generated by IS_IN_DB by another field
   other than the one formatted for display?

   Thanks.

   /r
   Nik


[web2py] Re: using another unique column in IS_IN_DB

2011-04-24 Thread niknok
Thanks Villas. I missed that, and it defaulted to 'string'.

How do I use 'list:reference table' with another database? I tried:
'list:reference gdb.country' but that doesn't work.

On Apr 25, 7:09 am, villas villa...@gmail.com wrote:
 country.iso2 is a  'list:reference' field,  right?

 On Apr 24, 5:40 am, niknok nikolai...@gmail.com wrote:







  I have the following:
      db.profile.citizenship.requires=IS_IN_DB(gdb,'country.iso2',
  '%(name)s',multiple=True,zero=None)

  It works fine until I try accessing the record from appadmin (I can view
  the table, it fails when I view a specific record), which dumps me this:

  Traceback (most recent call last):

    File /home/erwin/Projects/web2py/gluon/restricted.py, line 188, in 
  restricted
      exec ccode in environment
    File 
  /home/nrg/Projects/web2py/applications/bbc/controllers/appadmin.py, line 
  412, in module
    File /home/nrg/Projects/web2py/gluon/globals.py, line 124, in lambda
      self._caller = lambda f: f()
    File 
  /home/nrg/Projects/web2py/applications/bbc/controllers/appadmin.py, line 
  275, in update
      f='download', args=request.args[:1]))
    File /home/nrg/Projects/web2py/gluon/sqlhtml.py, line 815, in __init__
      inp = self.widgets.multiple.widget(field, default)
    File /home/nrg/Projects/web2py/gluon/sqlhtml.py, line 272, in widget
      return OptionsWidget.widget(field, value, **attributes)
    File /home/nrg/Projects/web2py/gluon/sqlhtml.py, line 206, in widget
      options = requires[0].options()
    File /home/nrg/Projects/web2py/gluon/validators.py, line 430, in options
      self.build_set()
    File /home/nrg/Projects/web2py/gluon/validators.py, line 413, in 
  build_set
      fields = [self.dbset.db[self.ktable][k] for k in self.fields]
    File /home/nrg/Projects/web2py/gluon/dal.py, line 3898, in __getitem__
      return dict.__getitem__(self, str(key))
  KeyError: 'country'


[web2py] requires statement validation string coming from a field

2011-04-23 Thread niknok
I have a field regex which contains requires segements like IS_MATCH('^
\d{3}-\d{4}-\d{4}-\d{1}?$') in an administrative table

I store them as as Storage types and then retrieve and apply it to a
Form like this:
Field('f4', requires=IS_EMPTY_OR(settings.regex[4]))

In a model file, it's defined as:
settings=Storage()
settings.regex={
0:IS_MATCH('^\d{3}-\d{4}-\d{4}-\d{1}?$'),
1:IS_MATCH('^\d{4}-\d{3}-\d{3}-\d{1}?$'),
}
That worked fine. Now, however, I couldn't use the values I retrieve
from a record field because they are strings. I hope to use it like this
...
record=db.id_card_number(person==1,card==2)
form=SQLFORM.factory(Field('f4','string'))
form.f4.requires=record.regex
...


/r,
Nik


[web2py] IS_IN_DB validator

2011-04-23 Thread niknok
Is there a way to sort the list generated by IS_IN_DB by another field
other than the one formatted for display?

Thanks.

/r
Nik 


[web2py] IS_IN_DB validator

2011-04-23 Thread niknok
Is there a way to sort the list generated by IS_IN_DB by another field
other than the one formatted for display?

Thanks.

/r
Nik 


[web2py] Re: IS_IN_DB validator

2011-04-23 Thread niknok
Thanks. But I guess I did not explain myself properly.

I would like the list to display the titles, but sorted by say the ID
field, or another field.

Right now, I do it like label='%(id)s%(title)s', but I'd like to
display it without the ID. I hope this makes sense.

On Apr 23, 10:30 pm, DenesL denes1...@yahoo.ca wrote:
 Yes, use the label parameter e.g.

 IS_IN_DB(dbset, field, label='%(title)s', ...)

 On Apr 23, 8:59 am, niknok nikolai...@gmail.com wrote:







  Is there a way to sort the list generated by IS_IN_DB by another field
  other than the one formatted for display?

  Thanks.

  /r
  Nik


[web2py] Re: requires statement validation string coming from a field

2011-04-23 Thread niknok
**bump**

Anyone?

On Apr 23, 3:17 pm, niknok nikolai...@gmail.com wrote:
 I have a field regex which contains requires segements like IS_MATCH('^
 \d{3}-\d{4}-\d{4}-\d{1}?$') in an administrative table

 I store them as as Storage types and then retrieve and apply it to a
 Form like this:
     Field('f4', requires=IS_EMPTY_OR(settings.regex[4]))

 In a model file, it's defined as:
     settings=Storage()
     settings.regex={
         0:IS_MATCH('^\d{3}-\d{4}-\d{4}-\d{1}?$'),
         1:IS_MATCH('^\d{4}-\d{3}-\d{3}-\d{1}?$'),
         }
 That worked fine. Now, however, I couldn't use the values I retrieve
 from a record field because they are strings. I hope to use it like this
     ...
     record=db.id_card_number(person==1,card==2)
     form=SQLFORM.factory(Field('f4','string'))
     form.f4.requires=record.regex
     ...

 /r,
 Nik


[web2py] IS_IN_DB using a dal.Set

2011-04-21 Thread niknok
I have a set

mp_list=gdb(gdb.municipality.province==gdb.province.id)


which I'm trying to use it in a select field but causes an error:

Field('municipality',requires=IS_IN_DB(mp_list,'municipality.psgc_m',
'%(municipality.name)s 
(%(province.name)s)'))


I'm trying to get it to show in the dropdown like this: municipal_name
(province_name). How do I format the field names from a set?

I tried and can generate a query of the rows I'd like to have : 

mp_list=gdb(gdb.municipality.province==gdb.province.id)\
.select(gdb.municipality.psgc_m,gdb.municipality.name,\
gdb.province.name,orderby=gdb.municipality.name)
for x in mp_list: print x['municipality']['name']+' ('+x['province']['name']+')'




  1   2   >