[web2py] Re: web2py recipe book

2012-03-12 Thread cyber
**
* I'm 100% for this opinion!!!   *
* Thanks Massimo for his excellent work! *
**

On 13 мар, 02:55, Bruno Rocha  wrote:
> On Mon, Mar 12, 2012 at 12:10 PM, Bruce Wade  wrote:
> > The other book would be version 4 of the official manual. Bought it
> > because I didn't think it would be free online until much later.
>
> The official manual online version is available in HTML for free since the
> version 1.0, the PDF and PaperBack is released under a fee. That is the way
> it works since the beginning, you only have to pay for a book if you are
> not satisfied with HTML version, and if you want to have it on mobile
> reader or in physical paper.
>
> Another reason to buy is that it is a way to thank Massimo for the free and
> excellent work he does developing, answering questions and documenting
> web2py since the beginning and also help him to buy some pots of caffeine,
> so he can be always awake answering our questions and fixing bugs :)
>
> If you see some PDF or digital version for free, so it is piracy, and there
> is nothing we can do to stop this, even this new cookbook may become
> available on download sites for free.
>
> In my point of view, buying books on amazon, packt or another bookstore is
> also good for web2py advertisement, publishers will ask us all to write
> more books and web2py will be more visible!
>
> If I have enjoyed an open source software and also if I get some money
> working with an open source software. I always consider giving donations,
> paying for beers and coffees and buying some related stuff.
>
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]


[web2py] Re: * PYTILS *

2012-02-25 Thread cyber
PROBLEM SOLVED!

Thank you all for your fast response!

I have made a new *.py file in the model with that content:

# -*- coding: utf-8 -*-
from __future__ import division

ZERO = "ноль"

L_1_HE = HE = [ZERO, "один", "два", "три", "четыре", "пять", "шесть",
"семь", "восемь", "девять", "десять",
"одинадцать", "двенадцать", "тринадцать", "четырнадцать",
"пятнадцать",
"шестнадцать", "семнадцать", "восемнадцать", "девятнадцать"]

L_1_SHE = SHE = [ZERO, "одна", "две"] + L_1_HE[3:]

L_10 = [ZERO, "десять", "двадцать", "тридцать", "сорок", "пятьдесят",
"шестьдесят", "семьдесят", "восемьдесят", "девяносто"]

L_100 = [ZERO, "сто", "двести", "триста", "четыреста", "пятьсот",
"шестьсот", "семьсот", "восемьсот", "девятьсот"]

N_ROUBLE = "рубл"
N_COP = "копе"
RUR = (N_ROUBLE, N_COP)

N_DOLLAR = "доллар"
N_CENT = "цент"
USD = (N_DOLLAR, N_CENT)

GENDER = {
N_ROUBLE: HE,
N_COP: SHE,
N_DOLLAR: HE,
N_CENT: HE,
}

N_1000 = "тысяч"
N_MILLION = "миллион"
N_BILLION = "миллиард"

ENDINGS = {
N_ROUBLE: ["ей", "ь", "я", "я", "я"] + 30 * ["ей"],
N_COP:["ек", "йка", "йки", "йки", "йки"] + 30 * ["ек"],
N_DOLLAR:["ов", "", "а", "а", "а"] + 30 * ["ов"],
N_CENT:["ов", "", "а", "а", "а"] + 30 * ["ов"],
N_1000:["", "а", "и", "и", "и"] + 30 * [""],
N_MILLION:["ов", "", "а", "а", "а"] + 30 * ["ов"],
N_BILLION:["ов", "", "а", "а", "а"] + 30 * ["ов"],
}

def write_1_to_999(n, gender_digits=HE):
assert n<=999

if n==0:
return ZERO

n_100 = n // 100
n_10 = n % 100 // 10
n_1 = n % 10

res = []
res.append(L_100[n_100])

if n_10 == 1:
res.append(gender_digits[10*n_10 + n_1])
else:
res.append(L_10[n_10])
res.append(gender_digits[n_1])
return " ".join([s for s in res if s != ZERO])

def ending_index(n):
n_2 = n % 100
return n_2 if n_2 < 20 else n_2 % 10

def form_group_name(group, n):
return group + ENDINGS[group][ending_index(n)]

def form_group(group, n, gender_digits=HE):
return ("%s %s" % (write_1_to_999(n, gender_digits),
form_group_name(group, n))) if n else ZERO

def write_number(n, gender_digits=HE):
assert type(n) in (int, long)
if n==0:
    return ZERO

n_3 = n % 10**3
n_6 = n % 10**6 // 10**3
n_9 = n % 10**9 // 10**6
n_12 = n % 10**12 // 10**9
res = []

res.append(form_group(N_BILLION, n_12))
res.append(form_group(N_MILLION, n_9))
res.append(form_group(N_1000, n_6, SHE))
res.append(write_1_to_999(n_3, gender_digits))
return ", ".join([s for s in res if s != ZERO])

def write_price(n_rub, n_cop=0, currency=RUR):
rub_id, cop_id = currency
n = int(n_rub)
res = []
res.append("%s %s" % (write_number(n, GENDER[rub_id]),
form_group_name(rub_id, n)))
res.append(form_group(cop_id, n_cop, GENDER[cop_id]))
return ", ".join([s for s in res if s != ZERO])

And then I use the main function write_price() in my view like this:
{{=write_price(cur_invoice.invoice_sum, int(drob))}}
It works perfectly!


On 25 фев, 18:56, Anthony  wrote:
> On Saturday, February 25, 2012 3:28:39 AM UTC-5, cyber wrote:
>
> > ... but if I use web2py in MS Windows from the box?
> > I have no ideas of how to use additional modules to be able to import
> > required pieces of code from them.
>
> Are you using the web2py Windows binary, or are your running from web2py
> source using your own installation of Python? I recommend the latter. In
> that case, you can install Python setuptools
> (http://pypi.python.org/pypi/setuptools#windows) and use easy_install to
> install the Pytils egg. Alternatively, it might work if you simply copy the
> "pytils" folder from Pytils into your web2py site-packages folder (or even
> your application's "modules" folder).
>
> Anthony

[web2py] Re: * PYTILS *

2012-02-25 Thread cyber
... but if I use web2py in MS Windows from the box?
I have no ideas of how to use additional modules to be able to import
required pieces of code from them.


On 25 фев, 02:05, howesc  wrote:
> no experience with this package, but if you are on a traditional server
> just install the package and import it.  if you are on GAE or want to
> "sandbox" things, install the module to web2py/site-packages and then
> import it.
>
>
>
>
>
>
>
> On Friday, February 24, 2012 11:43:12 AM UTC-8, cyber wrote:
>
> > Hi, guys!
>
> > I just need a tools for processing string in russian for in-words
> > representation of numerals.
> > It seems that PYTILS (http://pypi.python.org/pypi/pytils/0.2.3or
> >https://github.com/j2a/pytils) is more convinient module.
> > So, is there a way to include PYTILS in my web2py project?
>
> > Perhaps someone has already have a similar experience?!?


[web2py] * PYTILS *

2012-02-24 Thread cyber
Hi, guys!

I just need a tools for processing string in russian for in-words
representation of numerals.
It seems that PYTILS (http://pypi.python.org/pypi/pytils/0.2.3 or
https://github.com/j2a/pytils) is more convinient module.
So, is there a way to include PYTILS in my web2py project?

Perhaps someone has already have a similar experience?!?


[web2py] Re: * DATE FIELDS REPRESENT *

2012-02-14 Thread cyber
Thanks! It's just my stupid mistake.

But my date fields have not changed. Even if I replace old settings
into ru-ru.py:
  '%Y-%m-%d': '%d.%m.%Y'
  '%Y-%m-%d %H:%M:%S': '%d.%m.%Y %H:%M:%S'



On 15 фев, 10:49, Bruce Wade  wrote:
> T.forse('ru-ru')
>
> to
>
>  T.force('ru-ru')
>
> you spelt force wrong like the error says, T doesn't have a forse attribute
>
>
>
>
>
>
>
>
>
> On Tue, Feb 14, 2012 at 10:37 PM, cyber  wrote:
> > I tried to use this elegant method but now I have this error message:
> >   "AttributeError: 'translator' object has no attribute 'forse'"
>
> > In the very top of my db.py I wrote:
> >   T.forse('ru-ru')
> > And into my languages/ru-ru.py I wrote:
> >   '%Y-%m-%d': '%d.%m.%Y'
> >   '%Y-%m-%d %H:%M:%S': '%d.%m.%Y %H:%M:%S'
>
> > What I did wrong?
>
> > On 14 фев, 17:30, Adi  wrote:
> > > you can enforce the date format through the language...
>
> > > this is how I use it, and I think there is a thread where Massimo
> > explained
> > > it before
>
> > > in my db.py:
>
> > > T.force('en-aa')
>
> > > in en-aa.py:
>
> > > %Y-%m-%d translate to %b %d, %Y
>
> > > and all dates became a new format, display and input fields as well...
>
> --
> --
> Regards,
> Bruce 
> Wadehttp://ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.fitnessfriendsfinder.com


[web2py] Re: * DATE FIELDS REPRESENT *

2012-02-14 Thread cyber
It's my fault :(
{{=db.contracts.date_start.represent(row.date_start)}} returns me all
values in a correct form in conformity with table field
representation: db.contracts.date_start.represent = lambda
v:v.strftime('%d.%m.%Y').

Thanks for your help Ross and Anthony!

Could you please give me a piece of advice which option is preferable
to use:
{{=db.contracts.date_start.represent(row.date_start)}}
{{=row.date_start.strftime("%d.%m.%Y")}} ???

And how to deal with input fields in my forms?


On 14 фев, 17:41, Anthony  wrote:
> On Tuesday, February 14, 2012 8:18:46 AM UTC-5, cyber wrote:
>
> > No way! It doesn't work.
>
> That should work. What happens when you try it?


[web2py] Re: * DATE FIELDS REPRESENT *

2012-02-14 Thread cyber
I tried to use this elegant method but now I have this error message:
   "AttributeError: 'translator' object has no attribute 'forse'"

In the very top of my db.py I wrote:
   T.forse('ru-ru')
And into my languages/ru-ru.py I wrote:
   '%Y-%m-%d': '%d.%m.%Y'
   '%Y-%m-%d %H:%M:%S': '%d.%m.%Y %H:%M:%S'

What I did wrong?



On 14 фев, 17:30, Adi  wrote:
> you can enforce the date format through the language...
>
> this is how I use it, and I think there is a thread where Massimo explained
> it before
>
> in my db.py:
>
> T.force('en-aa')
>
> in en-aa.py:
>
> %Y-%m-%d translate to %b %d, %Y
>
> and all dates became a new format, display and input fields as well...


[web2py] Re: * DATE FIELDS REPRESENT *

2012-02-14 Thread cyber
No way! It doesn't work.


On 14 фев, 16:57, Ross Peoples  wrote:
> I don't know if this is the correct way, but I have done this before:
>
> {{=db.contracts.date_start.represent(row.date_start)}}


[web2py] * DATE FIELDS REPRESENT *

2012-02-13 Thread cyber
Hi there!
Please help me deal with date representation.

For example, I have a date field:
 Field('date_start', 'date', default = datetime.date.today())
 db.contracts.date_start.represent = lambda v:v.strftime('%d.%m.
%Y')

It works perfectly if I use SQLFORM.
But if I use just selection from db and do something like this in a
view:
 {{for row in contracts:}}
  {{=row.date_start}}
 {{pass}}
it turns to the defaul value representation: "%Y-%m-%d".
So in this case I should use strftime for correct all date values:
{{=row.date_start.strftime("%d.%m.%Y")}}
But maybe there is a better way to go!?!

And another question about datetime picker in forms.
By default input value looks like that "2012-02-14".
I need to change it to "14.02.2012".
How can I change it? Where should I look for?


I'll appreciate for any help. Thanks!


[web2py] CUSTOMIZE SQLFORM.grid

2012-01-20 Thread cyber

I need not VIEW / EDIT / DELETE records in selected db table.
I want user to be redirected to another page after clicking some link.
But I have no ideas of how to customise grid.

Is it possible to add some additional link to each record in
SQLFORM.GRID?


[web2py] AUTOCOMLETE widget doesn'n work with non latin chars

2012-01-14 Thread cyber
Hi there!

My table consists of some cyrrilic chars and when I try to select by
typing into the form nothing happened.
But if I fill the table with latin chars, it works perfetly.

For example, in models:

db.define_table('clients',
Field('client',   type='string',  label=T('Наименование
организации'), unique=True, notnull=True, length=25),
...
 )
db.clients.client.requires=IS_NOT_EMPTY(error_message='cannot be
empty')
db.clients.client.requires=IS_NOT_IN_DB(db, 'clients.client')
db.clients.client.widget = SQLFORM.widgets.autocomplete(request,
db.clients.client, limitby=(0,10), min_length=1)

... in controller:
form=SQLFORM.factory(db.clients, fields=['client'])

... in view:
{{=form}}

How can I deal with it?
Thanks in advance for any help!


[web2py] select by query in the link

2011-08-17 Thread cyber
How can I select rows from db using the link:

   
http://localhost:8000/init/default/select/db?query=db.autos.num.contains(...some...value...)

In the controller I have to describe current db, table and parse value
from the link.

So I need something like it is into appadmin but a little bit shorter.


[web2py] Re: export data to OOO and Excel

2011-07-23 Thread cyber
Say Dave, is xlwt included into current w2p version? Or I need to add
the library by myself?



On 22 июл, 05:05, Dave  wrote:
> I added these two lines and its working now!
>
>     response.headers['Content-Disposition']='attachment;
> filename=test.xls'
>     response.headers['Content-Title']='test.xls'
>
> Dave
>
> On Jul 21, 4:48 pm, Dave  wrote:
>
>
>
>
>
>
>
> > I added it to default.py controller, so it is working as an action
> > there.
>
> > When i go to that URL  (.../default/excel_report), the file downloads
> > as "excel_report" with no extension.  I am testing using Mac OS, so
> > not sure if that matters.  The file is fine.  When i rename it with
> > the .xls extension it opens in my spreadsheet application.
>
> > Thanks,
> > Dave
>
> > On Jul 21, 1:51 pm, Joaquin Orbe  wrote:
>
> > > On Thu, Jul 21, 2011 at 3:40 PM, Dave  
> > > wrote:
> > > > This works great, but when i download the file it is missing the 
> > > > extension.
> > > > Is there an easy way to add '.xls' to the file name?
>
> > > > Thanks,
> > > > Dave
>
> > > Hi Dave,
> > > how do you download the file? This method is an action in one controller, 
> > > ie:
>
> > >http://127.0.0.1:8000/myapp/printer/excel_report
>
> > > and the file is downloaded as XLS.
>
> > > Joaco.


[web2py] Re: select from db by list of id

2011-05-13 Thread cyber
Hmm...
Very nice! It works perfectly. As a matter of fact it was very easy.
Thank you Vasile.
**

On 13 май, 13:41, Vasile Ermicioi  wrote:
> id_list = [50, 45, 32, 11]
> rows=db(dv.autos.id.belongs(id_list)).select()


[web2py] select from db by list of id

2011-05-13 Thread cyber
Good day!

Is there a way to select rows from db if I have a list of id?
For example, there is a list [50, 45, 32, 11] and I want to make
selection by this list and save the result in one object.
How can I do that?

I tried:
 id_list = [50, 45, 32, 11]
 results=db(db.autos==id_list).select()
But there was an error "no tables selected".

Thanks in advance!


[web2py] export from current view

2011-05-10 Thread cyber
I'm at a loss.

I have a search view with two different forms. Description of the forms is 
in controller. Each form can select different rows from db and then that 
rows are shown at the bottom of the current view. 
So, the question is how to export received results? I tried to wrote special 
function with arg for this:
*

def export_search_results(res=None, eres=None):
response.headers['content-type']='text/csv' 
response.headers['Content-disposition'] = 'attachment; 
filename=export.csv'
if res is None:
response,flash = 'None'
else:
return '%s\n'%';'.join('id num ves dt 
usr'.split())+'\n'.join([';'.join(map(str,[r.id, r.num, r.ves, r.dt, 
r.usr])) for r in res])

if eres is None:
*
response,flash = 'None'
else:
return '%s\n'%';'.join('id num ves dt 
usr'.split())+'\n'.join([';'.join(map(str,[r.id, r.num, r.ves, r.dt, 
r.usr])) for r in eres])

Then in the search view page I wrote the links like that:
*{{for r in results:}}*
*   bla ... bla ... bla ... search results here ...*
*{{pass}}*
{{=A('export to CSV', _href=URL('export_search_results(results)'))}}

But that kind of link doesn't work because of invalid request error. After 
that I don't know how to settle the matter. 
Can anybody help me, please?


[web2py] Re: a chance to vote for web2py

2011-05-06 Thread cyber
top 8

On 6 май, 23:17, cyber  wrote:
> *
> Voted! Top 9!
> *
>
> On 6 май, 21:53, Ovidio Marinho  wrote:
>
>
>
>
>
>
>
> > top 9 voted.
>
> >         Ovidio Marinho Falcao Neto
> >              ovidio...@gmail.com
> >                      88269088
> >                    Paraiba-Brasil
>
> > 2011/5/6 Robert Kooij 
>
> > > Voted! :)


[web2py] Re: a chance to vote for web2py

2011-05-06 Thread cyber
*
Voted! Top 9!
*

On 6 май, 21:53, Ovidio Marinho  wrote:
> top 9 voted.
>
>         Ovidio Marinho Falcao Neto
>              ovidio...@gmail.com
>                      88269088
>                    Paraiba-Brasil
>
> 2011/5/6 Robert Kooij 
>
>
>
>
>
>
>
> > Voted! :)

[web2py] Re: deal with CSV

2011-05-03 Thread cyber
My experiments gave the following results.

def export_day():
response.headers['content-type']='text/csv'
response.headers['Content-disposition'] = 'attachment;
filename=export.csv'
results=db(db.autos.dt>=date).select(orderby=~db.autos.dt)
return '\n'.join([';'.join(map(str,['id','num','ves','dt','usr
\n']))])+'\n'.join([';'.join(map(str,[r.id, r.num, r.ves, r.dt,
r.usr])) for r in results])

I changed delimiter to ";" and added sepator to the header. Also I
wrote content-desposition for headers and now no need to right click
to the link to save file as.
So, it works perfectly! Thank you Denes for you help!
***

On 3 май, 18:37, DenesL  wrote:
> Are you running Windows?.
> Check that your list separator (which Excel uses) is set to a comma or
> change the delimiter used in the code.
> You can find the list separator in the Control Panel, under Regional
> Settings, Customize.
>
> On May 3, 7:38 am, cyber  wrote:
>
>
>
>
>
>
>
> > I mean that after export each row is located into one cell (if I open
> > *.csv file in ms excel).
> > For example, if result returns two rows all values from first row are
> > located into A1 cell and the second one - into A2 cell.
> > So, I need to divide each row by columns. Current divider is ",". Is
> > there a way to use another tabular separator if i want each value to
> > be placed into each cell?
> > *** 
> > **
>
> > On 3 май, 00:04, DenesL  wrote:
>
> > > Sorry, I don't understand what you mean by divide search results.
>
> > > As for headers, you could do:
>
> > > ...
> > > return 'A1,B1,C1\n' + '\n'.join([','.join(map(str,[r.id, r.num, r.ves,
> > > r.dt, r.usr])) for r in rr])
>
> > > On May 2, 2:42 pm, cyber  wrote:
>
> > > > Denes, it works. Thanks!
> > > > But how to divide search results?
> > > > Finaly I want each table field to be into personal column in the row
> > > > in csv file.
> > > > For example, r.id should be into A1, r.num should be into B1 etc.
> > > > Is it possible?
>
> > > > *
>
> > > > On 2 май, 00:27, DenesL  wrote:
>
> > > > > You can provide a link to the controller below, instructing the user
> > > > > to right click on it and then select 'save link as...', he can store
> > > > > the response in any selected directory using his choice of filename (a
> > > > > name ending in .csv):
>
> > > > > def tocsv():
> > > > >   response.headers['content-type']='text/csv'
> > > > >   rr=db((db.autos.dt>=t1) &
> > > > > (db.autos.dt<=t2)).select(orderby=~db.autos.dt)
> > > > >   return '\n'.join([','.join(map(str,[r.id, r.num, r.ves, r.dt,
> > > > > r.usr])) for r in rr])


[web2py] Re: deal with CSV

2011-05-03 Thread cyber
I mean that after export each row is located into one cell (if I open
*.csv file in ms excel).
For example, if result returns two rows all values from first row are
located into A1 cell and the second one - into A2 cell.
So, I need to divide each row by columns. Current divider is ",". Is
there a way to use another tabular separator if i want each value to
be placed into each cell?
*

On 3 май, 00:04, DenesL  wrote:
> Sorry, I don't understand what you mean by divide search results.
>
> As for headers, you could do:
>
> ...
> return 'A1,B1,C1\n' + '\n'.join([','.join(map(str,[r.id, r.num, r.ves,
> r.dt, r.usr])) for r in rr])
>
> On May 2, 2:42 pm, cyber  wrote:
>
>
>
>
>
>
>
> > Denes, it works. Thanks!
> > But how to divide search results?
> > Finaly I want each table field to be into personal column in the row
> > in csv file.
> > For example, r.id should be into A1, r.num should be into B1 etc.
> > Is it possible?
>
> > *
>
> > On 2 май, 00:27, DenesL  wrote:
>
> > > You can provide a link to the controller below, instructing the user
> > > to right click on it and then select 'save link as...', he can store
> > > the response in any selected directory using his choice of filename (a
> > > name ending in .csv):
>
> > > def tocsv():
> > >   response.headers['content-type']='text/csv'
> > >   rr=db((db.autos.dt>=t1) &
> > > (db.autos.dt<=t2)).select(orderby=~db.autos.dt)
> > >   return '\n'.join([','.join(map(str,[r.id, r.num, r.ves, r.dt,
> > > r.usr])) for r in rr])


[web2py] Re: deal with CSV

2011-05-02 Thread cyber
Denes, it works. Thanks!
But how to divide search results?
Finaly I want each table field to be into personal column in the row
in csv file.
For example, r.id should be into A1, r.num should be into B1 etc.
Is it possible?

*

On 2 май, 00:27, DenesL  wrote:
> You can provide a link to the controller below, instructing the user
> to right click on it and then select 'save link as...', he can store
> the response in any selected directory using his choice of filename (a
> name ending in .csv):
>
> def tocsv():
>   response.headers['content-type']='text/csv'
>   rr=db((db.autos.dt>=t1) &
> (db.autos.dt<=t2)).select(orderby=~db.autos.dt)
>   return '\n'.join([','.join(map(str,[r.id, r.num, r.ves, r.dt,
> r.usr])) for r in rr])


[web2py] Re: deal with CSV

2011-05-01 Thread cyber
Any ideas please!
*

On 1 май, 00:20, cyber  wrote:
> hi everyone!
>
> I need a help/hint/advase again.
>
> I have a code in the controller:
> results=db((db.autos.dt>=t1) &
> (db.autos.dt<=t2)).select(orderby=~db.autos.dt)
>     export = csv.writer(open('export.csv', 'wb'), delimiter=' ',
> quotechar='|', quoting=csv.QUOTE_MINIMAL)
>     for r in results:
>         export.writerow([r.id] + [r.num] + [r.ves] + [r.dt] + [r.usr])
>
> I want to export search results to csv file. But in this case
> export.csv file is created automaticly.
> And I want users to choose file name and destination folder. How to
> settle the matter?
>
> And another problem is: all results are wrote in a one cell. Is there
> a way to write each db.table.field value in one row but into each cell?


[web2py] deal with CSV

2011-04-30 Thread cyber
hi everyone!

I need a help/hint/advase again.

I have a code in the controller:
results=db((db.autos.dt>=t1) &
(db.autos.dt<=t2)).select(orderby=~db.autos.dt)
export = csv.writer(open('export.csv', 'wb'), delimiter=' ',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
for r in results:
export.writerow([r.id] + [r.num] + [r.ves] + [r.dt] + [r.usr])

I want to export search results to csv file. But in this case
export.csv file is created automaticly.
And I want users to choose file name and destination folder. How to
settle the matter?

And another problem is: all results are wrote in a one cell. Is there
a way to write each db.table.field value in one row but into each cell?


[web2py] Re: How to search by date?

2011-04-27 Thread cyber
Hmm... the same result.
And it's due to my db.table I think.

db.define_table('autos',
...
   Field('dt', 'datetime', default=now,
requires=IS_DATETIME(format='%d/%m/%Y %H:%M:%S'))
...
)

How to restyle form.vars (2011-04-27) to required format?

**


[web2py] Re: How to search by date?

2011-04-26 Thread cyber
Thank you Brian!
It works perfectly. But there is one trouble.

If I use query with two dates:
   results=db(db.autos.dt<=d1 & db.autos.dt>=d2).select()
there is no result at all.

But if I use only first date:
   results=db(db.autos.dt<=d1).select()
there is correct result.

*

On 27 апр, 01:15, Brian M  wrote:
> Tell web2py that those fields are supposed to be dates and it'll take care
> of the date format for you.
>
> Here's a form I use for finding stats between two dates, should be easy
> enough to modify for your purposes
>
> form = FORM(TABLE(TR(TD("First Date:"),
>                     TD(
>                         INPUT(_type="text",
>                             _name="start_date",
>                             _id="start_date",
>                             _class='date',
>                             _value=start_date,
>                             requires=[IS_DATE(error_message="Invalid Date
> Entered")]))),
>                 TR(
>                     TD("Second Date:"),
>                     TD(INPUT(_type="text",
>                         _name="end_date",
>                         _id="end_date",
>                         _class='date',
>                         _value=end_date,
>                         requires=[IS_DATE(error_message="Invalid Date
> Entered")]))),
>                 TR(INPUT(_type="submit", _value="Get Stats"
>
> Then when you validate the form, your dates will be converted to python date
> objects for you & your query should work.
>
> if form.accepts(request.vars, session, keepvalues=True):
>         start_date = form.vars.start_date
>         end_date = form.vars.end_date

[web2py] How to search by date?

2011-04-26 Thread cyber
I have a couple of  to search in a date range.







I thought over a search code like this:

def search_results():
d1=request.vars.date1
d2=request.vars.date2
results=db(db.autos.dt<=d1 & db.autos.dt>=d2).select()
return dict(results=results)

But it doesn't work because of unconvinuent date/object format.

So, how to convert d1 and d2 => [2011-04-26] => into the date and
build correct search code?
Any ideas!?!


[web2py] Re: how to parse rawsql results?

2011-04-25 Thread cyber
It's my mistake. Of course,  autos.out='T' and autos.svh='F'.
Thanks!


On 25 апр, 16:21, Massimo Di Pierro 
wrote:
> ... autos.out='T' and autos.out='F' ... ?
>
> On Apr 25, 12:34 am, cyber  wrote:
>
>
>
>
>
>
>
> > I used to use construction like this:
> > rows_count=db(db.autos.out=='T').count(), but my real query consists
> > of many conditions. So I decided to use executesql.
>
> > By the way, I wrote the code:
> >    rows_count = db.executesql("SELECT count(1) FROM autos WHERE
> > autos.out='T' and autos.out='F' and autos.idk='F' and autos.svh='F'
> > and autos.rad='F' and autos.out='F' and autos.tranzit='F'",
> > as_dict=False)
> >    rows_count=rows_count[0][0]
> > I think this construction is more preferable for me.
>
> > And thank you very much for the help. Your advice was very helpfull
> > for me.
> > **
>
> > On 23 апр, 21:35, Vasile Ermicioi  wrote:
>
> > > but it is nicer if you have models (you can generate them from database
> > > tables)
>
> > > print db(db.autos.out=='T').count()


[web2py] Re: how to parse rawsql results?

2011-04-24 Thread cyber
I used to use construction like this:
rows_count=db(db.autos.out=='T').count(), but my real query consists
of many conditions. So I decided to use executesql.

By the way, I wrote the code:
   rows_count = db.executesql("SELECT count(1) FROM autos WHERE
autos.out='T' and autos.out='F' and autos.idk='F' and autos.svh='F'
and autos.rad='F' and autos.out='F' and autos.tranzit='F'",
as_dict=False)
   rows_count=rows_count[0][0]
I think this construction is more preferable for me.

And thank you very much for the help. Your advice was very helpfull
for me.
**

On 23 апр, 21:35, Vasile Ermicioi  wrote:
> but it is nicer if you have models (you can generate them from database
> tables)
>
> print db(db.autos.out=='T').count()


[web2py] how to parse rawsql results?

2011-04-23 Thread cyber
I use a piece of code like this in controller:
ccc=db.executesql("SELECT count(*) FROM autos WHERE autos.out='T';")

And there is a result in a view:
[(10,)]

So, I want to have only digits in result without [(,)]. How can deal
with it?


[web2py] Re: exclude some chars on Form validation

2011-04-14 Thread cyber
It's OK now.
I added requires=IS_LENGTH(minsize=5)
*

On 14 апр, 10:15, cyber  wrote:
> Thanks, it's very helpfull!
>
> But it allows to insert SPACE_BAR gap and blank value.
> Is there decision for that?
>
> *
>
> On 14 апр, 09:55, Anthony  wrote:
>
>
>
>
>
>
>
> > There's an IS_ALPHANUMERIC validator for 
> > that:http://web2py.com/book/default/chapter/07#Validators
>
> > On Thursday, April 14, 2011 1:43:40 AM UTC-4, cyber wrote:
> > > I would like to exclude some chars when my form validates.
> > > I need to insert/update record value only with letters and digits.
> > > The undesirable chars are: [-](_)*/&%!@#$^ etc
>
> > > How can I validate form?


[web2py] Re: exclude some chars on Form validation

2011-04-13 Thread cyber
Thanks, it's very helpfull!

But it allows to insert SPACE_BAR gap and blank value.
Is there decision for that?

*

On 14 апр, 09:55, Anthony  wrote:
> There's an IS_ALPHANUMERIC validator for 
> that:http://web2py.com/book/default/chapter/07#Validators
>
>
>
>
>
>
>
> On Thursday, April 14, 2011 1:43:40 AM UTC-4, cyber wrote:
> > I would like to exclude some chars when my form validates.
> > I need to insert/update record value only with letters and digits.
> > The undesirable chars are: [-](_)*/&%!@#$^ etc
>
> > How can I validate form?


[web2py] exclude some chars on Form validation

2011-04-13 Thread cyber
I would like to exclude some chars when my form validates.
I need to insert/update record value only with letters and digits.
The undesirable chars are: [-](_)*/&%!@#$^ etc

How can I validate form?


[web2py] Re: rawsql & like operator

2011-04-05 Thread cyber
Denes, you opened my eyes to me again.
***
I tried to use %%s%% and there was an error message.
So, the only one character % separated me from the correct result!

And say what way is more preferable to use: db.select() or
db.executesql() ?

By the way, thank you very much!
***

On 5 апр, 23:48, DenesL  wrote:
> ... or the equivalent raw sql
>
> results=db.executesql("SELECT * FROM autos WHERE num LIKE %%%s%%;"
> %n)
>
> On Apr 5, 4:45 pm, DenesL  wrote:
>
>
>
>
>
>
>
> > I believe you want
>
> > results=db(db.autos.num.contains(n)).select()
>
> > On Apr 5, 3:58 pm, cyber  wrote:
>
> > > I need a hint!
>
> > > It seems that LIKE operator doesn't work.Or... I'm not so clever
> > > human...
>
> > > Say, how can I deal with rawsql query? I need to find all records but
> > > I know only some part of exact value. The code:
>
> > > n=request.vars.num  ### it returns only number
> > > results=db.executesql("SELECT * FROM autos WHERE num LIKE %s;" %(n))
> > > ### select
> > > return dict(results=results) ### it returns rows with exact n values
> > > only
>
> > > ... how can I find all records (not only n) including missed nums and
> > > chars?


[web2py] rawsql & like operator

2011-04-05 Thread cyber
I need a hint!

It seems that LIKE operator doesn't work.Or... I'm not so clever
human...

Say, how can I deal with rawsql query? I need to find all records but
I know only some part of exact value. The code:

n=request.vars.num  ### it returns only number
results=db.executesql("SELECT * FROM autos WHERE num LIKE %s;" %(n))
### select
return dict(results=results) ### it returns rows with exact n values
only

... how can I find all records (not only n) including missed nums and
chars?


[web2py] how to deal with hosting?

2011-03-30 Thread cyber
I would like to use my web2py project as internet site.

If it's possible, what are the rules for the operation?
And how can I choose correct hosting provider wich will be able to
start web2py files?


[web2py] update db.table from custom form

2011-03-22 Thread cyber
Hi there! Say guys how can I handle form.accepts if I need update
record in db from my custom form?

I have the custom form in one view:
{{from r in current_row:}}

   ...
   
   ...

{{pass}}

And I want to update db.table.enter from "False" to "True" when user
presses the button. How can I do that?


[web2py] Re: get vars from view to my def

2011-03-18 Thread cyber
WOW!
It works! It's so simple - I can't believe.
Thank you.
**

On 18 мар, 14:34, rochacbruno  wrote:
> http://.../default/work?number=3
>
> In controller
>
> i = request.vars.number
>
> > row=db(db.autos.id==i).select()
>
> Em 18/03/2011, às 08:16, cyber  escreveu:
>
>
>
>
>
>
>
> > Massimo, thanks for your correction, but I need code like that:
>
> > **
> > * def work(i):                       *
> > *    row=db(db.autos.id==i).select() *
> > *    return dict(row=row)            *
> > **
>
> > In this case "i" is a variable from the view "default/new.html". The
> > link is: "http://.../default/work?=3";. Figure 3 is an example.
> > In this code I want to use "i" as argument for "work()" but the result
> > is "invalid function(default/work)".
>
> > I hope my descriptions are clear for you :)
> > How can I set the value of variable from the current view to my def in
> > controller?
> > Thank you in advance...
> > _
>
> > On 18 мар, 00:03, Massimo Di Pierro 
> > wrote:
> >> My code in controller:
> >> ***
> >> 
> >> * def work():
> >> *    row=db(db.autos.id==20).select() < can be done with DAL
> >> *    return dict(row=row)
> >> ***
> >> 
> >> My code in the view (new.html):
> >> ***
> >> ****
> >> * {{for r in rows:}} <-- rows not records
> >> * {{=A(r.id,_href=URL('work', vars={'i':r.id}))}}
> >> * {{pass}} <--- missing
> >> ***
> >> 
>
> >> Anyway, your select returns at most one record.
>
> >> On Mar 17, 3:55 pm, cyber  wrote:
>
> >>> Hi there!
>
> >>> I need a hint of how to get variable value from view to my function in
> >>> controller.
>
> >>> My code in controller:
> >>> ***
> >>>  
> >>> * def work():
> >>> *    row=db.executesql('SELECT * FROM autos WHERE autos.id=20')
> >>> *    return dict(row=row)
> >>> ***
> >>>  
>
> >>> My code in the view (new.html):
> >>> ***
> >>>  
> >>> * {{for r in records:}}
> >>> * {{=A(r.id,_href=URL('work', vars={'i':r.id}))}}
> >>> ***
> >>>  
>
> >>> As you see I can select one row from db by id but I want work function
> >>> to get current id instead "autos.id=20"
> >>> I have no ideas of how to use variable from view in my controllers
> >>> def.
>
> >>> So, any proposals!?! Please...


[web2py] Re: get vars from view to my def

2011-03-18 Thread cyber
Massimo, thanks for your correction, but I need code like that:

 **
 * def work(i):   *
 *row=db(db.autos.id==i).select() *
 *return dict(row=row)*
 **

In this case "i" is a variable from the view "default/new.html". The
link is: "http://.../default/work?=3";. Figure 3 is an example.
In this code I want to use "i" as argument for "work()" but the result
is "invalid function(default/work)".

I hope my descriptions are clear for you :)
How can I set the value of variable from the current view to my def in
controller?
Thank you in advance...
_


On 18 мар, 00:03, Massimo Di Pierro 
wrote:
> My code in controller:
> ***
> 
> * def work():
> *    row=db(db.autos.id==20).select() < can be done with DAL
> *    return dict(row=row)
> ***
> 
> My code in the view (new.html):
> ***
> 
> * {{for r in rows:}} <-- rows not records
> * {{=A(r.id,_href=URL('work', vars={'i':r.id}))}}
> * {{pass}} <--- missing
> ***
> 
>
> Anyway, your select returns at most one record.
>
> On Mar 17, 3:55 pm, cyber  wrote:
>
>
>
>
>
>
>
> > Hi there!
>
> > I need a hint of how to get variable value from view to my function in
> > controller.
>
> > My code in controller:
> > *** 
> > 
> > * def work():
> > *    row=db.executesql('SELECT * FROM autos WHERE autos.id=20')
> > *    return dict(row=row)
> > *** 
> > 
>
> > My code in the view (new.html):
> > *** 
> > 
> > * {{for r in records:}}
> > * {{=A(r.id,_href=URL('work', vars={'i':r.id}))}}
> > *** 
> > 
>
> > As you see I can select one row from db by id but I want work function
> > to get current id instead "autos.id=20"
> > I have no ideas of how to use variable from view in my controllers
> > def.
>
> > So, any proposals!?! Please...


[web2py] get vars from view to my def

2011-03-17 Thread cyber
Hi there!

I need a hint of how to get variable value from view to my function in
controller.

My code in controller:
***
* def work():
*row=db.executesql('SELECT * FROM autos WHERE autos.id=20')
*return dict(row=row)
***

My code in the view (new.html):
***
* {{for r in records:}}
* {{=A(r.id,_href=URL('work', vars={'i':r.id}))}}
***

As you see I can select one row from db by id but I want work function
to get current id instead "autos.id=20"
I have no ideas of how to use variable from view in my controllers
def.

So, any proposals!?! Please...


[web2py] Re: about SQLFORM

2011-03-14 Thread cyber
Any piece of advise, please!

How can I update each row by changing checkbox states?

{{for nums in table:}}
{{=TR(
TD(nums.id),
TD(nums.num),
TD(nums.name),
TD(nums.dtime),
TD(INPUT(_type='checkbox',value=nums.enter)),
TD(A(nums.enter_d,_href=URL('index'))),
TD(INPUT(_type='checkbox',value=nums.idk)),
TD(A(nums.idk_d,_href=URL('index'))),
TD(INPUT(_type='checkbox',value=nums.svh)),
TD(A(nums.svh_d,_href=URL('index'))),
TD(INPUT(_type='checkbox',value=nums.reg)),
TD(A(nums.reg_d,_href=URL('index'))),
TD(INPUT(_type='checkbox',value=nums.out)),
TD(A(nums.out_d,_href=URL('index'
}}

How should I use SQLFORM update in this case?
*

On 14 мар, 15:51, cyber  wrote:
> How can I get current row id to update it?
> ***
>
> On 13 мар, 04:04, villas  wrote:
>
>
>
>
>
>
>
> > Do you need a custom form?  How about...
> > Use SQLFORM with 'keepvalues'. When user clicks checkbox, submit form
> > with jQuery.
> > Once that's working experiment with submitting form with ajax.
>
> > On Mar 12, 8:15 pm, cyber  wrote:
>
> > > I have few fields in db like this one:
> > >    Field('enter', 'boolean', default=False)
>
> > > And I made new page with selection result:
> > >    def table():
> > >        table=db().select(db.autos.ALL, orderby=~db.autos.dtime)
> > >        return dict(table=table)
>
> > > Then I wrote code for this new page to represent data from my db:
> > >     
> > >     {{for nums in table:}}
> > >     {{=TR(TD(nums.num),
> > >     TD(nums.name),
> > >     TD(nums.dtime),
> > >     TD(INPUT(_type="checkbox",value=nums.enter)),
> > >     TD(nums.enter_d),
> > >     TD(INPUT(_type="checkbox",value=nums.idk)),
> > >     TD(nums.idk_d),
> > >     TD(INPUT(_type="checkbox",value=nums.svh)),
> > >     TD(nums.svh_d),
> > >     TD(INPUT(_type="checkbox",value=nums.reg)),
> > >     TD(nums.reg_d),
> > >     TD(INPUT(_type="checkbox",value=nums.out)),
> > >     TD(nums.out_d))}}
> > >     {{pass}}
> > >     
>
> > > So, the matter is: how can I change checkboxes state and automaticaly
> > > update table in db?
> > > Can I add some action when user changes checkboxes state?
> > > ***
> > >  **
>
> > > On 11 мар, 12:53, cyber  wrote:
>
> > > > It works perfectly!
> > > > I understood your code. Many thanks and respects for you!!!
>
> > > > ***
>
> > > > Could you give me a piece of advise of how can I use checkboxes to
> > > > represent results of db selection?
> > > > I have some boolean fields in db and I want users to be able to check/
> > > > uncheck checkbox's state. Is it posible?
>
> > > > **
>
> > > > On 10 мар, 17:47, DenesL  wrote:
>
> > > > > After an insert, form.vars.id will have the new record's id.
>
> > > > > But to avoid another DB access you can make the changes before the
> > > > > record is written using the onvalidation parameter in the accepts.
>
> > > > > @auth.requires_login()
> > > > > def new():
> > > > >     def set_name(form):
> > > > >         form.vars.name=author
> > > > >         return
> > > > >     form = SQLFORM(db.autos, fields=['num'],
> > > > >            labels={'num':'Number'},
> > > > >            submit_button='GO',
> > > > >            formstyle='divs')
> > > > >     if form.accepts(request.vars, session,
> > > > >             onvalidation=set_name):
> > > > >         response.flash = 'Yoh-ho-ho!'
> > > > >     elif form.errors:
> > > > >         response.flash = 'Bad-bad-bad!'
> > > > >     else:
> > > > >         response.flash = 'Fill the form'
> > > > >     return dict(form=form)
>
> > > > > On Mar 10, 5:56 am, cyber  wrote:
>
> > > > > > The code in controller:
> > > > > > @auth.requires_lo

[web2py] Re: about SQLFORM

2011-03-14 Thread cyber
How can I get current row id to update it?
***

On 13 мар, 04:04, villas  wrote:
> Do you need a custom form?  How about...
> Use SQLFORM with 'keepvalues'. When user clicks checkbox, submit form
> with jQuery.
> Once that's working experiment with submitting form with ajax.
>
> On Mar 12, 8:15 pm, cyber  wrote:
>
>
>
>
>
>
>
> > I have few fields in db like this one:
> >    Field('enter', 'boolean', default=False)
>
> > And I made new page with selection result:
> >    def table():
> >        table=db().select(db.autos.ALL, orderby=~db.autos.dtime)
> >        return dict(table=table)
>
> > Then I wrote code for this new page to represent data from my db:
> >     
> >     {{for nums in table:}}
> >     {{=TR(TD(nums.num),
> >     TD(nums.name),
> >     TD(nums.dtime),
> >     TD(INPUT(_type="checkbox",value=nums.enter)),
> >     TD(nums.enter_d),
> >     TD(INPUT(_type="checkbox",value=nums.idk)),
> >     TD(nums.idk_d),
> >     TD(INPUT(_type="checkbox",value=nums.svh)),
> >     TD(nums.svh_d),
> >     TD(INPUT(_type="checkbox",value=nums.reg)),
> >     TD(nums.reg_d),
> >     TD(INPUT(_type="checkbox",value=nums.out)),
> >     TD(nums.out_d))}}
> >     {{pass}}
> >     
>
> > So, the matter is: how can I change checkboxes state and automaticaly
> > update table in db?
> > Can I add some action when user changes checkboxes state?
> > *** 
> > **
>
> > On 11 мар, 12:53, cyber  wrote:
>
> > > It works perfectly!
> > > I understood your code. Many thanks and respects for you!!!
>
> > > ***
>
> > > Could you give me a piece of advise of how can I use checkboxes to
> > > represent results of db selection?
> > > I have some boolean fields in db and I want users to be able to check/
> > > uncheck checkbox's state. Is it posible?
>
> > > **
>
> > > On 10 мар, 17:47, DenesL  wrote:
>
> > > > After an insert, form.vars.id will have the new record's id.
>
> > > > But to avoid another DB access you can make the changes before the
> > > > record is written using the onvalidation parameter in the accepts.
>
> > > > @auth.requires_login()
> > > > def new():
> > > >     def set_name(form):
> > > >         form.vars.name=author
> > > >         return
> > > >     form = SQLFORM(db.autos, fields=['num'],
> > > >            labels={'num':'Number'},
> > > >            submit_button='GO',
> > > >            formstyle='divs')
> > > >     if form.accepts(request.vars, session,
> > > >             onvalidation=set_name):
> > > >         response.flash = 'Yoh-ho-ho!'
> > > >     elif form.errors:
> > > >         response.flash = 'Bad-bad-bad!'
> > > >     else:
> > > >         response.flash = 'Fill the form'
> > > >     return dict(form=form)
>
> > > > On Mar 10, 5:56 am, cyber  wrote:
>
> > > > > The code in controller:
> > > > > @auth.requires_login()
> > > > > def new():
> > > > >     author=auth.user.username
> > > > >     form = SQLFORM(db.autos, fields=['num'], labels={'num':'Number'},
> > > > > submit_button='GO', formstyle='divs')
> > > > >     if form.accepts(request.vars, session):
> > > > >         response.flash = 'It's OK!'
> > > > >     elif form.errors:
> > > > >         response.flash = 'There is an error!'
> > > > >     else:
> > > > >         response.flash = 'Fill the form!'
> > > > >     rows=db(db.autos.id>0).select()
> > > > >     last_row=rows[-1]
> > > > >     last_row.update_record(name=author)
> > > > >     return dict(form=form)
>
> > > > > ***
> > > > > And the model piece of code is:
> > > > > import datetime
> > > > > now=datetime.datetime.today()
> > > > > db.define_table('autos',
> > > > >     Field('num&#

[web2py] Re: about SQLFORM

2011-03-14 Thread cyber
Hmmm... How can I do that?

I can update one record if I know row id:
   record = db.autos(request.args(0))
   form = SQLFORM(db.autos, record)
But I have table view and I need update every record in db.
User should press button or change checkbox state and current row have
to be updated.
I can't even imagin of how I could do that action!



On 13 мар, 04:04, villas  wrote:
> Do you need a custom form?  How about...
> Use SQLFORM with 'keepvalues'. When user clicks checkbox, submit form
> with jQuery.
> Once that's working experiment with submitting form with ajax.
>
> On Mar 12, 8:15 pm, cyber  wrote:
>
>
>
>
>
>
>
> > I have few fields in db like this one:
> >    Field('enter', 'boolean', default=False)
>
> > And I made new page with selection result:
> >    def table():
> >        table=db().select(db.autos.ALL, orderby=~db.autos.dtime)
> >        return dict(table=table)
>
> > Then I wrote code for this new page to represent data from my db:
> >     
> >     {{for nums in table:}}
> >     {{=TR(TD(nums.num),
> >     TD(nums.name),
> >     TD(nums.dtime),
> >     TD(INPUT(_type="checkbox",value=nums.enter)),
> >     TD(nums.enter_d),
> >     TD(INPUT(_type="checkbox",value=nums.idk)),
> >     TD(nums.idk_d),
> >     TD(INPUT(_type="checkbox",value=nums.svh)),
> >     TD(nums.svh_d),
> >     TD(INPUT(_type="checkbox",value=nums.reg)),
> >     TD(nums.reg_d),
> >     TD(INPUT(_type="checkbox",value=nums.out)),
> >     TD(nums.out_d))}}
> >     {{pass}}
> >     
>
> > So, the matter is: how can I change checkboxes state and automaticaly
> > update table in db?
> > Can I add some action when user changes checkboxes state?
> > *** 
> > **
>
> > On 11 мар, 12:53, cyber  wrote:
>
> > > It works perfectly!
> > > I understood your code. Many thanks and respects for you!!!
>
> > > ***
>
> > > Could you give me a piece of advise of how can I use checkboxes to
> > > represent results of db selection?
> > > I have some boolean fields in db and I want users to be able to check/
> > > uncheck checkbox's state. Is it posible?
>
> > > **
>
> > > On 10 мар, 17:47, DenesL  wrote:
>
> > > > After an insert, form.vars.id will have the new record's id.
>
> > > > But to avoid another DB access you can make the changes before the
> > > > record is written using the onvalidation parameter in the accepts.
>
> > > > @auth.requires_login()
> > > > def new():
> > > >     def set_name(form):
> > > >         form.vars.name=author
> > > >         return
> > > >     form = SQLFORM(db.autos, fields=['num'],
> > > >            labels={'num':'Number'},
> > > >            submit_button='GO',
> > > >            formstyle='divs')
> > > >     if form.accepts(request.vars, session,
> > > >             onvalidation=set_name):
> > > >         response.flash = 'Yoh-ho-ho!'
> > > >     elif form.errors:
> > > >         response.flash = 'Bad-bad-bad!'
> > > >     else:
> > > >         response.flash = 'Fill the form'
> > > >     return dict(form=form)
>
> > > > On Mar 10, 5:56 am, cyber  wrote:
>
> > > > > The code in controller:
> > > > > @auth.requires_login()
> > > > > def new():
> > > > >     author=auth.user.username
> > > > >     form = SQLFORM(db.autos, fields=['num'], labels={'num':'Number'},
> > > > > submit_button='GO', formstyle='divs')
> > > > >     if form.accepts(request.vars, session):
> > > > >         response.flash = 'It's OK!'
> > > > >     elif form.errors:
> > > > >         response.flash = 'There is an error!'
> > > > >     else:
> > > > >         response.flash = 'Fill the form!'
> > > > >     rows=db(db.autos.id>0).select()
> > > > >     last_row=rows[-1]
> > > > >     last_row.update_record(name=author)
> > > > >     return dict(

[web2py] Re: about SQLFORM

2011-03-12 Thread cyber
I have few fields in db like this one:
   Field('enter', 'boolean', default=False)

And I made new page with selection result:
   def table():
   table=db().select(db.autos.ALL, orderby=~db.autos.dtime)
   return dict(table=table)

Then I wrote code for this new page to represent data from my db:

{{for nums in table:}}
{{=TR(TD(nums.num),
TD(nums.name),
TD(nums.dtime),
TD(INPUT(_type="checkbox",value=nums.enter)),
TD(nums.enter_d),
TD(INPUT(_type="checkbox",value=nums.idk)),
TD(nums.idk_d),
TD(INPUT(_type="checkbox",value=nums.svh)),
TD(nums.svh_d),
TD(INPUT(_type="checkbox",value=nums.reg)),
TD(nums.reg_d),
TD(INPUT(_type="checkbox",value=nums.out)),
TD(nums.out_d))}}
{{pass}}


So, the matter is: how can I change checkboxes state and automaticaly
update table in db?
Can I add some action when user changes checkboxes state?
*****

On 11 мар, 12:53, cyber  wrote:
> It works perfectly!
> I understood your code. Many thanks and respects for you!!!
>
> ***
>
> Could you give me a piece of advise of how can I use checkboxes to
> represent results of db selection?
> I have some boolean fields in db and I want users to be able to check/
> uncheck checkbox's state. Is it posible?
>
> **
>
> On 10 мар, 17:47, DenesL  wrote:
>
>
>
>
>
>
>
> > After an insert, form.vars.id will have the new record's id.
>
> > But to avoid another DB access you can make the changes before the
> > record is written using the onvalidation parameter in the accepts.
>
> > @auth.requires_login()
> > def new():
> >     def set_name(form):
> >         form.vars.name=author
> >         return
> >     form = SQLFORM(db.autos, fields=['num'],
> >            labels={'num':'Number'},
> >            submit_button='GO',
> >            formstyle='divs')
> >     if form.accepts(request.vars, session,
> >             onvalidation=set_name):
> >         response.flash = 'Yoh-ho-ho!'
> >     elif form.errors:
> >         response.flash = 'Bad-bad-bad!'
> >     else:
> >         response.flash = 'Fill the form'
> >     return dict(form=form)
>
> > On Mar 10, 5:56 am, cyber  wrote:
>
> > > The code in controller:
> > > @auth.requires_login()
> > > def new():
> > >     author=auth.user.username
> > >     form = SQLFORM(db.autos, fields=['num'], labels={'num':'Number'},
> > > submit_button='GO', formstyle='divs')
> > >     if form.accepts(request.vars, session):
> > >         response.flash = 'It's OK!'
> > >     elif form.errors:
> > >         response.flash = 'There is an error!'
> > >     else:
> > >         response.flash = 'Fill the form!'
> > >     rows=db(db.autos.id>0).select()
> > >     last_row=rows[-1]
> > >     last_row.update_record(name=author)
> > >     return dict(form=form)
>
> > > ***
> > > And the model piece of code is:
> > > import datetime
> > > now=datetime.datetime.today()
> > > db.define_table('autos',
> > >     Field('num', length=8),
> > >     Field('name'),
> > >     Field('dtime', 'datetime', default=now),
> > >     Field('enter', 'boolean', default=False),
> > >     Field('enter_d'),
> > >     Field('idk', 'boolean', default=False),
> > >     Field('idk_d'),
> > >     Field('svh', 'boolean', default=False),
> > >     Field('svh_d'),
> > >     Field('reg', 'boolean', default=False),
> > >     Field('reg_d'),
> > >     Field('out', 'boolean', default=False),
> > >     Field('out_d')
> > >     )
>
> > > *
> > > And view file is:
> > > {{extend 'layout.html'}}
> > > {{=form}}
>
> > > So, I want user to enter only value 'num' in db.autos.
> > > But user_name (for current user) and date_time info have to be updated
> > > automaticly after user presses "GO" button.
> > > Could you check my code? Is it correct?
>
> > > On 9 мар, 17:27, DenesL  wrote:
>
> > > > Can you show us your current code?.
>
> > > > On Mar 9, 9:03 am, cyber  wrote:
>
> > > > > Hi
>
> > > > > How can I update new (just created) record in the table?
> > > > > Table consists of several fields but in the form page user have to
> > > > > enter only one value for one row.
> > > > > So, I need insert in the current row not only this value but user name
> > > > > and datetime.
> > > > > I can insert first value but I have no idea of how to auto update new
> > > > > row with required values.
>
> > > > > Any ideas?


[web2py] Re: about SQLFORM

2011-03-11 Thread cyber
It works perfectly!
I understood your code. Many thanks and respects for you!!!

***

Could you give me a piece of advise of how can I use checkboxes to
represent results of db selection?
I have some boolean fields in db and I want users to be able to check/
uncheck checkbox's state. Is it posible?

**

On 10 мар, 17:47, DenesL  wrote:
> After an insert, form.vars.id will have the new record's id.
>
> But to avoid another DB access you can make the changes before the
> record is written using the onvalidation parameter in the accepts.
>
> @auth.requires_login()
> def new():
>     def set_name(form):
>         form.vars.name=author
>         return
>     form = SQLFORM(db.autos, fields=['num'],
>            labels={'num':'Number'},
>            submit_button='GO',
>            formstyle='divs')
>     if form.accepts(request.vars, session,
>             onvalidation=set_name):
>         response.flash = 'Yoh-ho-ho!'
>     elif form.errors:
>         response.flash = 'Bad-bad-bad!'
>     else:
>         response.flash = 'Fill the form'
>     return dict(form=form)
>
> On Mar 10, 5:56 am, cyber  wrote:
>
>
>
>
>
>
>
> > The code in controller:
> > @auth.requires_login()
> > def new():
> >     author=auth.user.username
> >     form = SQLFORM(db.autos, fields=['num'], labels={'num':'Number'},
> > submit_button='GO', formstyle='divs')
> >     if form.accepts(request.vars, session):
> >         response.flash = 'It's OK!'
> >     elif form.errors:
> >         response.flash = 'There is an error!'
> >     else:
> >         response.flash = 'Fill the form!'
> >     rows=db(db.autos.id>0).select()
> >     last_row=rows[-1]
> >     last_row.update_record(name=author)
> >     return dict(form=form)
>
> > ***
> > And the model piece of code is:
> > import datetime
> > now=datetime.datetime.today()
> > db.define_table('autos',
> >     Field('num', length=8),
> >     Field('name'),
> >     Field('dtime', 'datetime', default=now),
> >     Field('enter', 'boolean', default=False),
> >     Field('enter_d'),
> >     Field('idk', 'boolean', default=False),
> >     Field('idk_d'),
> >     Field('svh', 'boolean', default=False),
> >     Field('svh_d'),
> >     Field('reg', 'boolean', default=False),
> >     Field('reg_d'),
> >     Field('out', 'boolean', default=False),
> >     Field('out_d')
> >     )
>
> > *
> > And view file is:
> > {{extend 'layout.html'}}
> > {{=form}}
>
> > So, I want user to enter only value 'num' in db.autos.
> > But user_name (for current user) and date_time info have to be updated
> > automaticly after user presses "GO" button.
> > Could you check my code? Is it correct?
>
> > On 9 мар, 17:27, DenesL  wrote:
>
> > > Can you show us your current code?.
>
> > > On Mar 9, 9:03 am, cyber  wrote:
>
> > > > Hi
>
> > > > How can I update new (just created) record in the table?
> > > > Table consists of several fields but in the form page user have to
> > > > enter only one value for one row.
> > > > So, I need insert in the current row not only this value but user name
> > > > and datetime.
> > > > I can insert first value but I have no idea of how to auto update new
> > > > row with required values.
>
> > > > Any ideas?


[web2py] Re: about SQLFORM

2011-03-10 Thread cyber
The code in controller:
@auth.requires_login()
def new():
author=auth.user.username
form = SQLFORM(db.autos, fields=['num'], labels={'num':'Number'},
submit_button='GO', formstyle='divs')
if form.accepts(request.vars, session):
response.flash = 'It's OK!'
elif form.errors:
response.flash = 'There is an error!'
else:
response.flash = 'Fill the form!'
rows=db(db.autos.id>0).select()
last_row=rows[-1]
last_row.update_record(name=author)
return dict(form=form)

***
And the model piece of code is:
import datetime
now=datetime.datetime.today()
db.define_table('autos',
Field('num', length=8),
Field('name'),
Field('dtime', 'datetime', default=now),
Field('enter', 'boolean', default=False),
Field('enter_d'),
Field('idk', 'boolean', default=False),
Field('idk_d'),
Field('svh', 'boolean', default=False),
Field('svh_d'),
Field('reg', 'boolean', default=False),
Field('reg_d'),
Field('out', 'boolean', default=False),
Field('out_d')
)

*
And view file is:
{{extend 'layout.html'}}
{{=form}}

So, I want user to enter only value 'num' in db.autos.
But user_name (for current user) and date_time info have to be updated
automaticly after user presses "GO" button.
Could you check my code? Is it correct?



On 9 мар, 17:27, DenesL  wrote:
> Can you show us your current code?.
>
> On Mar 9, 9:03 am, cyber  wrote:
>
>
>
>
>
>
>
> > Hi
>
> > How can I update new (just created) record in the table?
> > Table consists of several fields but in the form page user have to
> > enter only one value for one row.
> > So, I need insert in the current row not only this value but user name
> > and datetime.
> > I can insert first value but I have no idea of how to auto update new
> > row with required values.
>
> > Any ideas?


[web2py] Re: about SQLFORM

2011-03-10 Thread cyber
The code in controller is:

@auth.requires_login()
def new():

form = SQLFORM(db.autos, fields=['num'], labels={'num':'Number'},
submit_button='GO', formstyle='divs')
if form.accepts(request.vars, session):
response.flash = 'Yoh-ho-ho!'
elif form.errors:
response.flash = 'Bad-bad-bad!'
else:
response.flash = 'Fill the form'
rows=db(db.autos.id>0).select()
last_row=rows[-1]
last_row.update_record(name=author)
return dict(form=form)


On 9 мар, 17:27, DenesL  wrote:
> Can you show us your current code?.
>
> On Mar 9, 9:03 am, cyber  wrote:
>
>
>
>
>
>
>
> > Hi
>
> > How can I update new (just created) record in the table?
> > Table consists of several fields but in the form page user have to
> > enter only one value for one row.
> > So, I need insert in the current row not only this value but user name
> > and datetime.
> > I can insert first value but I have no idea of how to auto update new
> > row with required values.
>
> > Any ideas?


[web2py] about SQLFORM

2011-03-09 Thread cyber
Hi

How can I update new (just created) record in the table?
Table consists of several fields but in the form page user have to
enter only one value for one row.
So, I need insert in the current row not only this value but user name
and datetime.
I can insert first value but I have no idea of how to auto update new
row with required values.

Any ideas?