[web2py] Re: Web2py uploads and downloads

2013-07-02 Thread Domagoj Kovač
For the moment i will leave this upload with DAL, in the future i will make 
upload class. I still have a problem with this:
def nt_download():
return response.stream(open(os.path.join(request.folder, 'uploads',
 request.args(0))), attachment=True)
This code doesn't work properly for files like pdf, xls, docx, png. How i 
can fix this? On my file system file is ok, but when i try to download it 
trough browser i always end up with 0 bytes file.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Web2py uploads and downloads

2013-07-01 Thread Domagoj Kovač
Is there any way that i can control this generated filename? For example my 
filenames can be some sort of hash from current timestamp. 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Web2py uploads and downloads

2013-07-01 Thread Domagoj Kovač
Yes. i am running windows. Can anyone explain how web2py creates does 
filenames?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Web2py uploads and downloads

2013-07-01 Thread Domagoj Kovač
I also noticed one more thing, looks like web2py brakes when i try to 
upload file with extralong filename. 
If i try to upload a file with name "extra long filename, 123 dsadsa 
dsadsadsadsa, dsadsadsa3r 342 432432342, 43232.txt" i receive an error:
 [Errno 2] No such file or directory: 
'C:\\development\\web2py\\applications\\init\\databases\\..\\uploads\\entry.entry_label.897c6d62aa3aa998.6578747261206c6f6e672066696c656e616d652c2031323320647361647361206473616473616473616473612c20647361647361647361337220333432203433323433323334322c2034333233322e747874.txt'
If i try to upload the same file with shorter name, everything works 
properly.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Web2py uploads and downloads

2013-07-01 Thread Domagoj Kovač
Hi,

I have a problem. I created multiple files upload like this:
if "attachments" in request.vars:
attachments = request.vars.attachments
if type(attachments) is list:
for attachment in attachments:
Attachment.save(attachment.file, attachment.filename
, request.args(0))
else:
Attachment.save(attachments.file, 
attachments.filename,request
.args(0))

return Redirect.to(request.env.http_referer)

save method:
def save(file, filename, entry_id):
image = db.entry.entry_label.store(file, filename)
attachment_dict = dict()
attachment_dict["entry_id"] = bson.ObjectId(oid=str(entry_id))
attachment_dict["file"] = image
attachment_dict["filename"] = filename
mongo.attachment.save(attachment_dict)

First of all i would like to avoid using DAL when saving images. 
image = db.entry.entry_label.store(file, filename)
Does web2py have any mechanism for uploading? I would be great to have a 
class that handles uploads For my point of view framework needs to be set 
of tools for the developer, although storing images this way could be nice 
in some case, i think upload and download must not be connected to DAL. I 
want to store my image on the filesystem, i don't see what that has to do 
with DAL.

I have download function:
def nt_download():
return response.stream(open(os.path.join(request.folder, 'uploads',request
.args(0))), attachment=True)
This code doesn't work properly for files like pdf, xls. How i can fix this?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Storing attachments

2013-06-26 Thread Domagoj Kovač
Hi,

I have a question:
if request.env.request_method == "POST":
attachments = request.vars.attachments
if len(attachments) > 0:
for attachment in attachments:
image = db.entry_value.upload_value.store(attachment.
file, attachment.filename)
I have a code like this, i would like to use store() without any relation 
to database.
db.entry_value.upload_value.store(attachment.file, attachment.filename)

I am not using DAL, i am using pymongo directly, all i need is to store 
image on the filesystem and then write the filename in MongoDB with 
pymongo. Is it possible to upload the file without any relation to database?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Multiple files upload

2013-06-26 Thread Domagoj Kovač
I have one more question, is it possible to disable this uploading feature? 
I thought i can add attachment field manually in my form, not 
trought SQLFORM.factory, but if i add this field manually, i still get an 
error. This basically means that if i want to have multiple uploads the way 
i imagined i can't use SQLFORM.factory at all and need to make everything 
custom (validators, etc..) 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Multiple files upload

2013-06-26 Thread Domagoj Kovač
Ok, thanks. I would be great if upload would be mapped to list.


On Wednesday, June 26, 2013 12:34:38 PM UTC+2, Niphlod wrote:
>
> just handle it outside web2py. Building a form with SQLFORM changing the 
> widget at your will is not going to work.
> it's like you asking for a checkbox field but using a textarea to do 
> it.it doesn't make any sense...
>
> Maybe we'll have in the future an upload mapped to a list:string (sounds 
> about right) and something that processes that accordingly, but out of the 
> box right now you just can't use SQLFORM facilities for this expecting it 
> to work. 
>
> AFAIK cgi.FieldStorage can't process out of the box HTML5's multiple input 
> files.
>
> On Wednesday, June 26, 2013 12:24:17 PM UTC+2, Domagoj Kovač wrote:
>>
>> Hi Niphlod, 
>>
>> I reviewed your code, in your test method you have: 
>> form = SQLFORM.factory(
>> Field('an_integer', 'integer'),
>> Field('upload_1', 'upload', uploadfolder=upf),
>> Field('upload_2', 'upload', uploadfolder=upf),
>> table_name='an_entry'
>> )
>> i don't want two field, i only want one field.
>> form = SQLFORM.factory(
>> Field('an_integer', 'integer'),
>> Field('attachment', 'upload', uploadfolder=upf),
>> table_name='an_entry'
>> )
>> and in my view
>> {{form.custom.widget["attachment"]['_multiple'] = "multiple"}}
>>
>> Now this attachment has multiple attribute, multiple is HTML 5 attribute 
>> and it enables me to select more than one file.
>>
>> When i add multiple attribute and select more than one file, web2py gives 
>> me an error:
>>  local variable 'source_file' 
>> referenced before assignment
>>
>> This is the code listing with the problem:
>>
>>  (source_file, original_filename) = (f.file, f.filename)
>>  elif isinstance(f, (str, unicode)):
>>  ### do not know why this happens, it should not
>>  (source_file, original_filename) = \
>>  (cStringIO.StringIO(f), 'file.txt')
>>
>>  newfilename = field.store(source_file, original_filename,
>>  field.uploadfolder)
>>  # this line was for backward compatibility but problematic
>>  # self.vars['%s_newfilename' % fieldname] = newfilename
>>  fields[fieldname] = newfilename
>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Multiple files upload

2013-06-26 Thread Domagoj Kovač
Hi Niphlod, 

I reviewed your code, in your test method you have: 
form = SQLFORM.factory(
Field('an_integer', 'integer'),
Field('upload_1', 'upload', uploadfolder=upf),
Field('upload_2', 'upload', uploadfolder=upf),
table_name='an_entry'
)
i don't want two field, i only want one field.
form = SQLFORM.factory(
Field('an_integer', 'integer'),
Field('attachment', 'upload', uploadfolder=upf),
table_name='an_entry'
)
and in my view
{{form.custom.widget["attachment"]['_multiple'] = "multiple"}}

Not this attachment has multiple attribute, multiple is HTML 5 attribute 
and it enables me to select more than one file.

When i add multiple attribute and select more than one files, web2py gives 
me an error:
 local variable 'source_file' 
referenced before assignment

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: pymongo

2013-06-18 Thread Domagoj Kovač
I re-installed python, it works now. Looks like i did not configure 
everything properly. Massimo thanks for fast reply's.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: pymongo

2013-06-18 Thread Domagoj Kovač
Yes it is installed. Python version 2.7. I can import from normal Python 
shell. Web2py version 2.4.5.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] pymongo

2013-06-18 Thread Domagoj Kovač
Hi,

i would like to use mongoDB directly without DAL.

I added this to the bottom of my model/0.py

# connect to mongoDB
connection = pymongo.MongoClient('localhost', 27017)

# attach to test database
mongo = connection.asset


- this gives me an error
name 'pymongo' is not defined

if i add
import pymongo

# connect to mongoDB
connection = pymongo.MongoClient('localhost', 27017)

# attach to test database
mongo = connection.asset


then i get the error: 
Cannot import module 'pymongo'
What is worng?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Multiple files upload

2013-06-14 Thread Domagoj Kovač
This is really important to me, can anyone help me?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Multiple files upload

2013-06-14 Thread Domagoj Kovač
Yes i searched there also, but i did not find anything that fits my needs. 
All uploads work the same way, there is no multiple upload. Files are sent 
to server one by one. I want to upload the files directly, not with some 
jquery combination.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Multiple files upload

2013-06-13 Thread Domagoj Kovač
Does anyone have any advice on this topic? I really must be able to do this 
somehow.

I think the problem happens in form.validate() function, because web2py is 
trying to validate everything and in there he is trying to save the file. 
I see two options:

   1. Somehow disable web2py automatic file saving.
   2. Do nos use form.validate() and validate form manually, is it possible 
   to use built in validators like that?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Multiple files upload

2013-06-13 Thread Domagoj Kovač
I have a problem once again :).

I have a code:
for entry_class_attribute in entry_class_attributes:
if entry_class_attribute.entry_label:
entry_label = entry_class_attribute.entry_attribute_id.name
fields.append(EntryValue.get_field(entry_class_attribute))

form = SQLFORM.factory(*fields, table_name='entry_value')

This attributes are my form fields, fields are dynamically generated from 
the database trough get_field function. 

In my view i have:

{{for entry_class_attribute in entry_class_attributes:}}

{{entry_attribute_id = entry_class_attribute.
entry_attribute_id}}
{{field_name = entry_class_attribute.entry_attribute_id.
name}}
{{field_label = entry_class_attribute.entry_attribute_id
.description}}
{{field_type = entry_class_attribute.entry_attribute_id.
field_type}}
{{if field_type != "UPLOAD":}}
{{=form.custom.label[field_name]}}
{{=form.custom.widget[field_name]}}
{{elif field_type == "UPLOAD":}}
{{=field_label}}


{{if uploads.has_key(entry_attribute_id) and len
(uploads[entry_attribute_id]) > 0:}}

{{for upload in uploads[
entry_attribute_id]:}}
{{=LI(upload.upload_filename,
" ",
A(T("Preuzmi"), _href=URL(
"default", "download", args=upload.upload_value), _target="blank", _class=
"download"),
" ",
A(T("Obriši"), _href=URL(
"entry_value", "delete_value", args=upload.id), _class="delete"),
)}}
{{pass}}

{{pass}}

{{pass}}

{{pass}}

But i am still getting the error:

127.0.0.1.2013-06-13.10-21-44.b2fb8130-4fad-444b-9246-f481539fa1ec
 local variable 'source_file' 
referenced before assignmentVersionweb2py™Version 
2.4.5-stable+timestamp.2013.04.01.19.18.09PythonPython 2.7.3: 
C:\Anaconda\Python.exe (prefix: C:\Anaconda)Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.

Traceback (most recent call last):
  File "C:\development\web2py\gluon\restricted.py", line 212, in restricted
exec ccode in environment
  File "C:/development/web2py/applications/init/controllers/entry_value.py" 
, 
line 453, in 
  File "C:\development\web2py\gluon\globals.py", line 194, in 
self._caller = lambda f: f()
  File "C:\development\web2py\gluon\tools.py", line 2976, in f
return action(*a, **b)
  File "C:/development/web2py/applications/init/controllers/entry_value.py" 
, 
line 96, in form
if form.validate():
  File "C:\development\web2py\gluon\html.py", line 2123, in validate
if self.accepts(**kwargs):
  File "C:\development\web2py\gluon\sqlhtml.py", line 1468, in accepts
newfilename = field.store(source_file, original_filename,
UnboundLocalError: local variable 'source_file' referenced before assignment

This looks like web2py is still trying to handle the file on its own. Am I 
right?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Multiple files upload

2013-06-13 Thread Domagoj Kovač
Thanks Niplod, looks like i must handle this on my own. It would be great 
if web2py could do this out of the box.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Multiple files upload

2013-06-12 Thread Domagoj Kovač
I have a filed:

field = Field(field_name, "upload",
requires=IS_NOT_EMPTY(),
uploadfolder=os.path.join(request.folder
, 'uploads'),
label=LABEL(field_description, _for=
input_id))

Does this have anything to do with the second error? From error i can 
assume that web2py is trying to upload the file itself, but when i select 
multiple files list is sent and there is the problem, i assume. 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Multiple files upload

2013-06-12 Thread Domagoj Kovač
Hi,

I have a question. I want to enable multiple files upload. I will not be 
using any jQuery/ajax script. I am using HTML5 multiple attribute on my 
input field, and then. Html 5 File API just for displaying files below my 
form.

$(".upload").change(function(evt) {
var button = $(this);
var files = evt.target.files;

button.next("ul.new").remove();

var output = [];
for (var i = 0, f; f = files[i]; i++) {
output.push('', f.name, '');
}

button.after('' + output.join('') + '');
})

In my form i want to have a field names attachment[] instead of attachment, 
so i can receive multiple files. When i add [] to my file input name i 
receive an error:
 invalid table or field name: attachment[]
If i try to upload multiple files without changing the name, i receive an 
error:
 local variable 'source_file' 
referenced before assignment
How could i do this?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Default template file

2013-06-12 Thread Domagoj Kovač
Yes i see it now, i totally forgot about that :).

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Default template file

2013-06-12 Thread Domagoj Kovač
Hi,

I have a question. Currently there is a file views/layout.html, default 
view is possible to change with response.view = 
'shared/entry_value_grid.html' is it possible to change default template 
view?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multitenancy

2013-06-10 Thread Domagoj Kovač
I found the solution to my problem but i still dont understand why this 
doesnt workd like it should.

Line:
rows = db().select(db.country.ALL, limitby=limit_by)

Must be:
rows = db(db.country.id > 0).select(db.country.ALL, limitby=limit_by)

And then request_teneant = 3 is added as a condition giving me what i want.

SELECT  country.id, country.name, country.alpha_2_code, country.alpha_3_code, 
country.numeric_code, country.request_tenant FROM country WHERE ((country.id > 
0) AND (country.request_tenant = '3')) ORDER BY country.id LIMIT 30 OFFSET 0;


Why multitenancy doesnt work without any extra conditions?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Multitenancy

2013-06-10 Thread Domagoj Kovač
Hi,

I have multitenancy application, in my application i have a table called 
countries where i have fields:
id
name
alpha_2_code
alpha_3_code
numeric_code
request_tenant

My loged user has request tenant value of 3 but in my log i see query 
without this condition:
SELECT country.id, country.name, country.alpha_2_code, 
country.alpha_3_code,country
.numeric_code, country.request_tenant FROM country ORDER BY country.id 
LIMIT 30 OFFSET 0;
SELECT count(*) FROM country WHERE ((country.id > 0) AND 
(country.request_tenant 
= '3'));


Count works like it should but regular select doesn't.

This is the code in my controler
@auth.requires_login()
def grid():
if len(request.args):
page = int(request.args[0])
else:
page = 0

limit_by = (page * settings["items_per_page"], (page + 1) * settings[
"items_per_page"])
rows = db().select(db.country.ALL, limitby=limit_by)
number_of_records = db(db.country.id > 0).count()

return dict(rows=rows, number_of_records=number_of_records)

What is wrong?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: in a view

2013-06-04 Thread Domagoj Kovač
This works. Thanks

On Monday, June 3, 2013 5:14:37 PM UTC+2, villas wrote:
>
> Try this:
>
> {{cell_value = XML("".join(map(str, cell_value)))}}
>
>
>
>
> On Monday, 3 June 2013 16:03:01 UTC+1, Domagoj Kovač wrote:
>>
>> Hi,
>>
>> I have a code like this:
>> {{for row in table:}}
>> 
>> {{for report_attribute in report_attributes:}}
>> {{cell_value = table[row][
>> report_attribute.report_attribute.id]["cell_value"]}}
>> {{if type(cell_value) is list:}}
>> {{cell_value = "".join(map(str, 
>> cell_value))}}
>> {{pass}}
>> {{=TD(cell_value, _class=table[row][
>> report_attribute.report_attribute.id]["css_class"])}}
>> {{pass}}
>> 
>> {{pass}}
>>
>> This line is used to join list and  is used as separator 
>> {{cell_value = "".join(map(str, cell_value))}}
>>
>> The problem i have is that  is escaped and in my browser i get 
>> result like "2013-04-042013-05-312013-05-162013-06-01> />2013-05-012013-05-03". 
>> I assume that this escaping is some security feature. Is there a way that 
>> i could print this without escaping? 
>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] in a view

2013-06-03 Thread Domagoj Kovač
Hi,

I have a code like this:
{{for row in table:}}

{{for report_attribute in report_attributes:}}
{{cell_value = 
table[row][report_attribute.report_attribute.id]["cell_value"]}}
{{if type(cell_value) is list:}}
{{cell_value = "".join(map(str, 
cell_value))}}
{{pass}}
{{=TD(cell_value, 
_class=table[row][report_attribute.report_attribute.id]["css_class"])}}
{{pass}}

{{pass}}

This line is used to join list and  is used as separator 
{{cell_value = "".join(map(str, cell_value))}}

The problem i have is that  is escaped and in my browser i get result 
like "2013-04-042013-05-312013-05-162013-06-012013-05-012013-05-03". 
I assume that this escaping is some security feature. Is there a way that i 
could print this without escaping? 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] request.get_vars

2013-05-23 Thread Domagoj Kovač
{{export_get_vars = request.get_vars}}
{{export_get_vars.export_format = "csv"}}
{{export_get_vars.export_format = "xls"}}
{{=request.get_vars}}
I have a code like this, i dont understand what is going on. I assign 
request.get_vars to export_get_vars, when i add seomething to 
export_get_vars request.get_vars is also changed, How is this possible?

Example above outputs: 


Althought my url is:
http://127.0.0.1:8000/init/entry_value/grid/13

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: System logout

2013-05-22 Thread Domagoj Kovač
Thanks Anthony now i understand what is going on. In my 0.py i added:

if session.company_url:
auth.settings.login_url = URL("default", "login", args=session.
company_url)
else:
auth.settings.login_url = URL("default", "login")

session.company_url is set on login. This works like i wanted. 

Thanks!

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: System logout

2013-05-22 Thread Domagoj Kovač
Looking at my function and your replies i can set:
auth.settings.logout_next = URL("default", "login", "company")
and this should redirect the user after he is logged out automatically. But 
this doesn't happen. Althought something like this should work i don't want 
to do it that way, i want to set default.logout as my application logout 
function, and all logouts are handled trough that function.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: System logout

2013-05-22 Thread Domagoj Kovač
I want to set the location of my logout function. 

I have my own logout function:
def logout():
if 'url_suffix' in request.cookies:

url_suffix = request.cookies['url_suffix'].value

response.cookies['url_suffix'] = ""
response.cookies['url_suffix']['expires'] = -1000
response.cookies['url_suffix']['path'] = '/'

auth.logout(next=URL("default", "login", url_suffix))
else:
auth.logout(next=URL("default", "login"))

return dict()

if i set:
auth.settings.expiration = 10

After 10 seconds i want user to be logged out with my own function.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: System logout

2013-05-22 Thread Domagoj Kovač
You misunderstood me :D, of course it is not possible to do anything on 
users computer, that would be scary :), although as a developer i would 
like it :). 
I did not mean system logout like user system logout i thought 
system logout like framework logout function, here system refers to my 
application.

I am trying to find a way to define my application logout function, so i 
can use my own logout function.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: System logout

2013-05-22 Thread Domagoj Kovač
auth.settings.logged_url = URL("default", "logout")

I see now that this line is not what i thought it was. For some reason i 
thought this line is actual system logout function.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] System logout

2013-05-22 Thread Domagoj Kovač
Hi,

I have multi tenant application where i have two logins. 
One login is only for super user and can be found on mydomain.com/login. 
Other login is for regular users and can be found on 
mydomain.com/company/login or mydomain/company2/login.

I have my own login and logout function, my login function sets the cookie 
with the name of the company. In my logout function name of the company 
is retrieved, cookie is destroyed and user is redirected to login for that 
user/company - mydomain.com/company/login.

in my 0.py i have:

auth.settings.login_url = URL("default", "login")
auth.settings.logged_url = URL("default", "logout")
auth.settings.expiration = 10 - this is only for testing purpose

How do i set system logout function? Because when user is logged out he is 
redirected to mydomain.com/login.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] CSV special characters

2013-05-17 Thread Domagoj Kovač
Hi,

I am working on CSV export.

I have a function that returns a string.
output_string = StringIO.StringIO()

csv_writer = csv.writer(output_string, delimiter=';', quotechar=' 
',quoting
=csv.QUOTE_MINIMAL)
csv_writer.writerows(output)

contents = output_string.getvalue()

output_string.close()

return contents

In my controller i have:
response.headers["Content-Type"] = gluon.contenttype.contenttype(".csv") 
+ ";charset=utf-8"
response.headers["Content-disposition"] = "attachment; filename=" 
+entry_class
.name + ".csv"

output = CSV.get_entries_content(entries, 
entry_class_attributes,entries_values
)

return str(output)

But when content is outputed i get KljuÄŤ Ĺ˝itnjak when it should be ključ 
žitnjak, how can i fix this?


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Re: Helper classes

2013-05-16 Thread Domagoj Kovač
I like add_method :).

Thanks Anthony.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Helper classes

2013-05-16 Thread Domagoj Kovač
Anthony thanks. Previously i worked with various languages and frameworks 
and my general practice was to use models only for things related to data 
model. Here i am not sure for what models are intended, firstly i used them 
for create_table definitions, but as my code grew i moved this definitions 
to 0.py. Now i use models like Classes that work with data from db.

class EntryClassAttribute():

@staticmethod
def get_by_entry_class_id(entry_class_id, grid=True):

query = (db.entry_class_attribute.entry_class_id == entry_class_id)

if grid:
query &= (db.entry_class_attribute.grid == True)

entry_class_attributes = db(query).select(db.entry_class_attribute.
ALL,
  orderby=db.
entry_class_attribute.field_position)

return entry_class_attributes

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Helper classes

2013-05-16 Thread Domagoj Kovač
They are currently in models, but i don't think models are the best place. 
Is it possible to make one extra folder names "helpers" and put them there, 
and how to include them?

I moved all my create_table definitions to 0.py model, is this preffered 
way, or they should be in associated models?


On Thursday, May 16, 2013 3:40:06 PM UTC+2, Anthony wrote:
>
> You could put them in a model file, which will make them available 
> everywhere on every request, or you can put them in a module and import 
> them when needed.
>
> Anthony
>
> On Thursday, May 16, 2013 9:13:05 AM UTC-4, Domagoj Kovač wrote:
>>
>> Hi,
>> i have bunch of functions that i would like to extract to helper classes.
>>
>> Where should i put this helpers and how to include them?
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Helper classes

2013-05-16 Thread Domagoj Kovač
Hi,
i have bunch of functions that i would like to extract to helper classes.

Where should i put this helpers and how to include them?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Self reference select

2013-05-15 Thread Domagoj Kovač
Hi,

i have a table of locations:

db.define_table('entry_location',
Field('name', 'string',
required=True,
requires=IS_NOT_EMPTY(),
label=LABEL(T("Naziv"), _for="entry_location_name")),
Field('parent_id', 'reference entry_location',
requires=IS_NULL_OR(IS_IN_DB(db, 'entry_location.id', 
'%(name)s', zero=T("Molimo odaberite roditeljsku lokaciju"))),
label=LABEL(T("Roditelj"), _for=
"entry_location_parent_id")),
Field('gps_x', 'double',
label=LABEL(T("GPS X koordinata"), _for=
"entry_location_address_2")),
Field('gps_y', 'double',
label=LABEL(T("GPS Y koordinata"), _for=
"entry_location_address_3")),
Field('zoom', 'integer'),
)

Is there any way that i could select all child's of certain location?


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: IS IN DB

2013-05-08 Thread Domagoj Kovač
OK, i will try. Thanks!

On Wednesday, May 8, 2013 4:02:47 PM UTC+2, Anthony wrote:
>
> OK, looks like you can't do a join. Instead, you can just use recursive 
> selects (though this will do a separate select for each item in the list):
>
> requires=IS_IN_DB(db, "report_attribute.id", lambda row: row.
> entry_attribute_id.name,
>   zero=T("-- Odaberite --"))
>
> row.entry_attribute_id.name does a select from the db.entry_attribute 
> table for each item. The other alternative is to build the set yourself 
> (using a join) and use IS_IN_SET() instead.
>
> Anthony
>
> On Wednesday, May 8, 2013 8:41:32 AM UTC-4, Domagoj Kovač wrote:
>>
>> This gives:
>>
>>  'Row' object has no attribute 
>> 'entry_attribute'
>> On Wednesday, May 8, 2013 2:37:54 PM UTC+2, Anthony wrote:
>>>
>>>
>>> requires=IS_IN_DB(db(db.report_attribute.entry_attribute_id == db.
>>>> entry_attribute.id), "report_attribute.id", '%(entry_attribute.name)s',zero
>>>> =T("-- Odaberite --"))
>>>>
>>>>
>>> How about:
>>>
>>> requires=IS_IN_DB(db(db.report_attribute.entry_attribute_id == db.
>>> entry_attribute.id), "report_attribute.id",
>>>   lambda row: row.entry_attribute.name, zero=T("-- 
>>> Odaberite --"))
>>>
>>> Anthony
>>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: IS IN DB

2013-05-08 Thread Domagoj Kovač
This gives:

 'Row' object has no attribute 
'entry_attribute'
On Wednesday, May 8, 2013 2:37:54 PM UTC+2, Anthony wrote:
>
>
> requires=IS_IN_DB(db(db.report_attribute.entry_attribute_id == db.
>> entry_attribute.id), "report_attribute.id", '%(entry_attribute.name)s',zero
>> =T("-- Odaberite --"))
>>
>>
> How about:
>
> requires=IS_IN_DB(db(db.report_attribute.entry_attribute_id == db.
> entry_attribute.id), "report_attribute.id",
>   lambda row: row.entry_attribute.name, zero=T("-- 
> Odaberite --"))
>
> Anthony
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] IS IN DB

2013-05-08 Thread Domagoj Kovač
db.define_table("entry_attribute",
Field('name', 'string',
  required=True,
  requires=[IS_NOT_EMPTY(),
IS_ALPHANUMERIC()],
  label=LABEL(T("Naziv"), _for="entry_attribute_type")),
Field('description', 'text',
  required=True,
  requires=IS_NOT_EMPTY(),
  label=LABEL(T("Opis"), _for="entry_attribute_type")),
Field('field_type', 'string',
  required=True,
  requires=IS_IN_SET(("STRING",
  "LOV",
  "TEXT",
  "BOOLEAN",
  "INTEGER",
  "DECIMAL",
  "DATE",
  "TIME",
  "DATETIME",
  "UPLOAD",
  "LOCATION",
  "PARTNER",
  "MANUFACTURER"), zero=T("Odaberite 
tip polja")),
  label=LABEL(T("Tip polja"), _for=
"entry_attribute_field_type")),
Field('field_size', 'integer',
  label=LABEL(T("Veličina polja"), _for=
"entry_attribute_field_size")),
)


db.define_table('report',
Field('name', 'string',
  required=True,
  requires=IS_NOT_EMPTY(),
  label=LABEL(T("Naziv"), _for="report_name")),
Field('description', 'string',
  required=False,
  label=LABEL(T("Opis"), _for="report_description")),
Field('entry_class_id', 'reference entry_class',
  required=True,
  requires=IS_IN_DB(db, "entry_class.id", '%(name)s',zero
=T("-- Odaberite --")),
  label=LABEL(T("Klasa"), _for="report_entry_class_id"
)),
)


db.define_table('report_attribute',
Field('report_id', 'reference report',
  required=True,
  requires=IS_IN_DB(db, "report.id", '%(name)s', zero=T("-- 
Odaberite --")),
  label=LABEL(T("Izvještaj"), _for="report_report_id")),
Field('entry_attribute_id', 'reference entry_attribute',
  requires=IS_IN_DB(db, "entry_attribute.id",
'%(name)s',
zero=T("-- Odaberite --")),
  label=LABEL(T("Atribut"), _for=
"report_entry_attribute_id")),
Field('sorting', 'string',
  required=False,
  requires=IS_EMPTY_OR(IS_IN_SET(("ASC",
  "DESC"), 
zero=T("Odaberite 
sortiranje"))),
  label=LABEL(T("Sortiranje"), _for=
"report_attribute_sorting")),
)


db.define_table('report_attribute_filter',
Field('report_attribute_id', 'reference report_attribute',
  required=True,
  
requires=IS_IN_DB(db(db.report_attribute.entry_attribute_id 
== db.entry_attribute.id), "report_attribute.id", "%(entry_attribute_id)s",zero
=T("-- Odaberite --")),
  label=LABEL(T("Attribut"), _for=
"report_attribute_filter_report_attribute_id")),
Field('filter_type', 'string',
  requires=IS_IN_SET(("LIKE",
  "=",
  "<",
  ">",
  "<=",
  ">="), zero=T("Odaberite filter"
)),
  label=LABEL(T("TIP FILTERA"), _for=
"report_attribute_filter_filter_type")),
Field('filter_name', 'string',
  required=True,
  requires=IS_NOT_EMPTY(),
  label=LABEL(T("Naziv filtera"), _for=
"report_attribute_filter_filter_name")),
)



-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: IS IN DB

2013-05-08 Thread Domagoj Kovač
This also gives the same error.

requires=IS_IN_DB(db(db.report_attribute.entry_attribute_id == db.
entry_attribute.id).select(db.report_attribute.ALL, db.entry_attribute.ALL), 
"report_attribute.id", '%(entry_attribute.name)s', zero=T("-- Odaberite --"
)),


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] IS IN DB

2013-05-08 Thread Domagoj Kovač
 'Table' object has no attribute 
'entry_attribute.name'

This is the error.

On Wednesday, May 8, 2013 1:39:55 PM UTC+2, viniciusban wrote:
>
> Why doen't it work? 
>
> What it shows? What should be shown? What error does it report? 
>
> -- 
> Vinicius Assef 
>
>
>
> On Wed, May 8, 2013 at 5:20 AM, Domagoj Kovač 
> > 
> wrote: 
> > Hi, 
> > 
> > i have three tables 
> > entry_attribute 
> > idint 
> > name  varchar 
> > description   longtext 
> > field_typevarchar 
> > field_sizeint 
> > 
> > report_attribute 
> > idint 
> > report_id int 
> > entry_attribute_idint 
> > sorting   varchar 
> > 
> > and report_attribute_filter 
> > idint 
> > report_attribute_id   int 
> > filter_type   varchar 
> > 
> > On my report attribute_filter i have a select where user can select 
> report 
> > attribute with name from entry attribute. 
> > I would like to do something like this. 
> > 
> > requires=IS_IN_DB(db(db.report_attribute.entry_attribute_id == 
> > db.entry_attribute.id), "report_attribute.id", '%(entry_attribute.name)s', 
>
> > zero=T("-- Odaberite --")) 
> > 
> > Code above doesn't work. How can i do this? 
> > 
> > -- 
> > 
> > --- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "web2py-users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to web2py+un...@googlegroups.com . 
> > For more options, visit https://groups.google.com/groups/opt_out. 
> > 
> > 
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] IS IN DB

2013-05-08 Thread Domagoj Kovač
Hi,

i have three tables 
entry_attribute
idint
name  varchar
description   longtext
field_typevarchar
field_sizeint

report_attribute
idint 
report_id int
entry_attribute_idint
sorting   varchar

and report_attribute_filter
idint
report_attribute_id   int
filter_type   varchar

On my report attribute_filter i have a select where user can select report 
attribute with name from entry attribute.
I would like to do something like this.

requires=IS_IN_DB(db(db.report_attribute.entry_attribute_id == db.
entry_attribute.id), "report_attribute.id", '%(entry_attribute.name)s', zero
=T("-- Odaberite --"))

Code above doesn't work. How can i do this?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: form.vars form type GET

2013-05-03 Thread Domagoj Kovač
I needed to add keepvalues

form.validate(request_vars=request.get_vars, keepvalues=True)


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: form.vars form type GET

2013-05-03 Thread Domagoj Kovač
I have a problem, form.validate(request_vars=request.get_vars) works but 
only when form is not submitted, when i submit my form my values are 
erased. 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: form.vars form type GET

2013-05-03 Thread Domagoj Kovač
request.get_vars.repeated - i have my value here,

but doesn't work.
form.vars.repeated = request.get_vars.repeated

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Dynamic IS_IN_DB

2013-05-03 Thread Domagoj Kovač
Thanks, i used first method.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] form.vars form type GET

2013-05-03 Thread Domagoj Kovač
Hi,

i have a form like this.

fields.append(Field("date_from", "date",
requires=IS_DATE(),
label=LABEL("Datum od", _for=
"no_table_date_from")))

fields.append(Field("date_to", "date",
requires=IS_DATE(),
label=LABEL("Datum do", _for="no_table_date_to"
)))

fields.append(Field("location_id", "reference asset_location",
required=True,
requires=IS_NULL_OR(IS_IN_DB(db, 
'asset_location.id', '%(name)s', zero=T("Molimo odaberite lokaciju"))),
label=LABEL("Lokacija", _for=
"no_table_location_id")))

fields.append(Field("repeated", "boolean",
label=LABEL("Ponovljene", _for=
"no_table_repeated")))

form = SQLFORM.factory(*fields, _method="GET")

and then i have:

if request.get_vars.date_from or request.get_vars.date_to:

query &= (db.asset_value.asset_attribute_id == 27)

if request.get_vars.date_from:
query &= (db.asset_value.date_value > request.get_vars.
date_from)
form.vars.date_from = request.get_vars.date_from

if request.get_vars.date_to:
query &= (db.asset_value.date_value < request.get_vars.
date_to)
form.vars.date_from = request.get_vars.date_from

if request.get_vars.location_id:
query &= (db.asset_value.location_value == request.get_vars.
location_id)
form.vars.location_id = request.get_vars.location_id

if request.get_vars.repeated:
query &= (db.asset_value.boolean_value == request.get_vars.
repeated)
form.vars.repeated = request.get_vars.repeated

Queries are fine and they work, but form.vars are always empty, does that 
have anything to do with form type being GET?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Dynamic IS_IN_DB

2013-05-02 Thread Domagoj Kovač
Hi,

i want to have dynamic query in my IS_IN_DB validator:
requires = IS_IN_DB(db((db.asset_class.id == 10) |
   (db.asset_class.id == 9) | 
   (db.asset_class.id == 7)), 'asset_class.id', 
'%(name)s', zero=T("-- Odaberite --"))

I want to have query like this but, right now my values are hardcoded, how 
can i generate something like (db.asset_class.id == 10) | (db.asset_class.
id == 9) | (db.asset_class.id == 7) 

Lets say that i have a list of ids in available_classes = 
db(db.asset_class.id > 0).select()

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Empty IS IN DB

2013-05-02 Thread Domagoj Kovač
Maybe i can remove options after they are created:

Something like: 
for option in form.elements('select[name=m_id] option'):
option.update(_class='repeated')

but i don't know what is the method for option delete. I can always add 
some class, called hidden, but i want to remove this options.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Empty IS IN DB

2013-05-02 Thread Domagoj Kovač
Hi,

i have code like this.

fields.append(Field("m_class_id", "reference asset_class",
required=True,
requires=IS_IN_DB(db, 'asset_class.id', '%(name)s',zero
=T("-- Odaberite --")),
label=LABEL("M CLASS", _for="no_table_m_class_id")))


if request.env.request_method == "POST" and request.post_vars.m_class_id
:
fields.append(Field("m_id", "reference asset",
required=True,
requires=IS_IN_DB(db(db.asset.asset_class_id 
==request
.post_vars.m_class_id), 'asset.id', '%(asset_label)s', zero=T("-- Odaberite 
--")),
label=LABEL("M", _for="no_table_m_id")))
else:
fields.append(Field("m_id", "reference asset",
required=True,
requires=IS_IN_DB(db, 'asset.id', 
'%(asset_label)s', zero=T("---")),
label=LABEL("M", _for="no_table_m_id")))


I am trying to make dependent selects. This means when i change m_class_id 
the m_id is populated based on m_class_id. I do this with jQuery and i 
don't have problems there. 
I want to make something like this, when user visits the form, he will see 
only two selects, M CLASS - this is initial select, M ID - this one is 
dependent on M CLASS and is populated only if M CLASS value is present, in 
M ID i want to have requires=IS_IN_DB(db, 'asset.id', '%(asset_label)s',
 zero=T("---")) validator but with empty select initially, something like 
in the code above.


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Form method = GET and keepvalues

2013-04-29 Thread Domagoj Kovač
Hi, 

In my grid i have a search form that filters grid results.
Is it possible to have SQLFORM.factory to have _method=GET and to keep 
values on form.validate:

Something like:
fields = []

fields.append(Field("asset_id",
requires=IS_EMPTY_OR(IS_IN_DB(db, 'asset.id', 
'%(asset_label)s', zero=T("-- Odaberite --"))),
label=LABEL("Imovina", 
_for="event_value_asset_id")))

fields.append(Field("event_class_id",
requires=IS_IN_DB(db, 'event_class.id', '%(name)s', 
zero=T("-- Odaberite --")),
label=LABEL("Vrsta događaja", 
_for="event_value_event_class_id")))

form = SQLFORM.factory(*fields, _method='GET')

if form.validate(keepvalues=True):
search = True #this i just a code example
Above code doesn't work, do i need to set form.vars manually?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Re: response.download

2013-04-29 Thread Domagoj Kovač
Thanks!

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: response.download

2013-04-29 Thread Domagoj Kovač
Where can i open a ticket about this?

I am not sure now. I have an image, lets say logo. I want to display this 
image via: 
{{=IMG(_src=URL("default", "download", args="logo.png"), _width="170px")}}

I thought if i move my image to static/images folder then this would work.

{{=IMG(_src="/static/images/logo.png", _width="170px")}}

But this also doesn't work.

If i want to display image that is manually uploaded, what is the best 
approach?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: IS IN DB

2013-04-29 Thread Domagoj Kovač
Thanks Anthony,

I did it like this: 
for option in form.elements('select[name=event_class_id] option'):
if option['_value'] and db.event_class(option['_value']).repeated:
option.update(_class='repeated')

Database query for each option is not problematic, because i don't have so 
much options, 10 at most.

Thanks!


On Friday, April 26, 2013 1:38:11 PM UTC+2, Anthony wrote:
>
> If you are using SQLFORM to generate the form, one option is to manipulate 
> the form DOM after it has been created:
>
> form = SQLFORM(...)
> [op.update(_class='repeated') for op in 
> form.elements('select[name=event_class_id] 
> option')
> if op['_value'] and db.event_class(op['_value']).repeated]
>
> form.elements('select[name=event_class_id] option') returns a list of all 
> the option elements within the event_class_id select, and the list 
> comprehension updates the _class attribute if the value stored in the 
> option element is associated with an event_class record with a True value 
> in the "repeated" field. Warning: that will do a db query for each option 
> in the list.
>
> Another option would be to create a custom widget for the field. You can 
> base it on the 
> OptionsWidget<https://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#224>.
>  
> You can subclass that class and replace the widget method.
>
> Anthony
>
> On Friday, April 26, 2013 5:47:26 AM UTC-4, Domagoj Kovač wrote:
>>
>> Hi,
>>
>> i have a question. I have a IS_IN_DB validator.
>> fields.append(Field("event_class_id", "reference event_class",
>> required=True,
>> requires=IS_IN_DB(db, 'event_class.id', 
>> '%(name)s', zero=T("-- Odaberite --")),
>> label=LABEL("Vrsta događaja", _for=
>> "event_value_event_class_id")))
>>
>> In my event class i have a structure like: 
>> db.define_table('event_class',
>> Field('name', 'string',
>> required=True,
>> requires=IS_NOT_EMPTY(),
>> label=LABEL(T("Naziv"), _for="event_class_name")),
>> Field('repeated', 'boolean',
>>   label=LABEL(T("Ponavljanje"), _for="event_repeated"
>> )),
>> )
>>
>> Repeated field is a field that tells me weather do display one field on a 
>> form. I want to have HTML like this. 
>> 
>> Name
>> Name 2
>> Name 3
>> Name 4
>> Name 5
>> 
>> so when users selects a value i can check if i need to display repeated 
>> field based on the class
>>
>> Is this possible somehow?
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] IS IN DB

2013-04-26 Thread Domagoj Kovač
Hi,

i have a question. I have a IS_IN_DB validator.
fields.append(Field("event_class_id", "reference event_class",
required=True,
requires=IS_IN_DB(db, 'event_class.id', '%(name)s',zero
=T("-- Odaberite --")),
label=LABEL("Vrsta događaja", _for=
"event_value_event_class_id")))

In my event class i have a structure like: 
db.define_table('event_class',
Field('name', 'string',
required=True,
requires=IS_NOT_EMPTY(),
label=LABEL(T("Naziv"), _for="event_class_name")),
Field('repeated', 'boolean',
  label=LABEL(T("Ponavljanje"), _for="event_repeated")),
)

Repeated field is a field that tells me weather do display one field on a 
form. I want to have HTML like this. 

Name
Name 2
Name 3
Name 4
Name 5

so when users selects a value i can check if i need to display repeated 
field based on the class

Is this possible somehow?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Count and distinct

2013-04-25 Thread Domagoj Kovač
I understand now, there are two pepople named Alex and one named Bob. Much 
better example would be to put example like:

>>> for row in db(db.person.id==db.thing.owner_id).select(
db.person.name, count, groupby=db.person.name):
print row.person.name, row[count]
Alex 2
Bob 4 

Here is much more obvious what is going on, because result revels that 
count is actually number of the people with the name in that row.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Count and distinct

2013-04-25 Thread Domagoj Kovač


count = db.person.id.count()

I understand this line of code, it is obvious that limitby clause here 
would be stupid.

>>> for row in db(db.person.id==db.thing.owner_id).select(
db.person.name, count, groupby=db.person.name):
print row.person.name, row[count]
Alex 2
Bob 1

I don't understand what is the purpose of the count here, and is this count 
related to the count above.


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Count and distinct

2013-04-25 Thread Domagoj Kovač
You misunderstood me. In the post above there is a regular select without 
limitby clause, i want to limit number of records in that select, so i 
assume count will be also limit? 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Count and distinct

2013-04-25 Thread Domagoj Kovač
In documentation i see:

>>> count = db.person.id.count()
>>> for row in db(db.person.id==db.thing.owner_id).select(
db.person.name, count, groupby=db.person.name):
print row.person.name, row[count]
Alex 2
Bob 1


but i need to limit the number of rows

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Count and distinct

2013-04-25 Thread Domagoj Kovač
Hi,

i have a count problem.

I have two queries.

assets = db((db.asset.asset_class_id == asset_class_id) &
(db.asset_value.asset_id == db.asset.id) &
(db.asset_value.location_value == 
location_id)).select(db.asset.ALL,

   orderby=~db.asset.id,

   limitby=limit_by,

   groupby=db.asset.id)

number_of_records = db((db.asset.asset_class_id == 
asset_class_id) &
   (db.asset_value.asset_id == db.asset.id) 
&
   (db.asset_value.location_value == 
location_id)).count(distinct=True)

If i turn off distinct i get number_od_records = 3, if i turn on distinct 
then i get number_od_records = 1, but asset returns 2 records with the same 
conditions.
What am i doing worng?
 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: paging

2013-04-24 Thread Domagoj Kovač
Thanks Massimo, 

I saw there is a system of plugins, but i wasn't sure are they the right 
choice for something like this. I will check them one more time.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] paging

2013-04-24 Thread Domagoj Kovač
Hi guys.

I have this code in my view:

{{if rows:}}

{{number_of_pages = int(math.floor(number_of_records/
settings["items_per_page"]))}}
{{if request.args:}}
{{current_page = int(request.args[0])}}
{{else:}}
{{current_page = 0}}
{{pass}}

Prikazujem: {{=settings[
"items_per_page"]*current_page}} - {{=settings["items_per_page"]*(current_page 
+ 1)}} od {{=number_of_records}}

{{for x in range(0, number_of_pages):}}
{{if current_page is x:}}
{{=A(x+1, _href=URL(request.controller, request.
function, args=[x]), _class="current")}}
{{else:}}
{{=A(x+1, _href=URL(request.controller, request.
function, args=[x]))}}
{{pass}}
{{pass}}



{{pass}}

This code is basically universal. If i want to make some kind of paging 
plug in, what would be the best approach? Easiest thing at the moment would 
be make just a view and move this code there and then include this view in 
every grid page.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: placeholder

2013-04-23 Thread Domagoj Kovač
Thanks man,i know placeholders don't work in all browsers. I can handle 
that via javascript if tag is present, although i don't think that is 
necessary.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] placeholder

2013-04-23 Thread Domagoj Kovač
Hi,

i have a code:

{{form.custom.widget.email["_placeholder"] = T("E-mail adresa")}}
{{=form.custom.widget.email}}

And here i get placeholder attribute on my input element, while here:

{{form.custom.widget.password["_placeholder"] = T("Lozinka")}}
{{=form.custom.widget.password}}

i don't get placeholder attribute. What is the issue?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] response.download

2013-04-23 Thread Domagoj Kovač
Hi,

I have a download function.

def download():
return response.download(request, db)

in my controller i have a line of code:

elif field_type == "UPLOAD":
field_value = A(T("Download attachment"), _href=URL("default", 
"download", args=asset_value.upload_value), _target="blank")

Generated link is:
http:
//127.0.0.1:8000/init/default/download/no_table.attachment.8c9b795c20c58264.4173736573736d656e7454797065732e786c7378.xlsx

When i try to download this file i get 404 error, although file is uploaded 
where it should be. 

What am i doing wrong, is it because of xlsx extension?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Custom IS IN DB

2013-04-19 Thread Domagoj Kovač
Thanks, that is what i need.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Custom IS IN DB

2013-04-19 Thread Domagoj Kovač
Hi,

i have a table of attributes like this:

ID field_name field_type

4 name STRING 
5 description TEXT 
6 power INTEGER 
7 available BOOLEAN 
8 price DECIMAL 
9 date_of_entry DATE 
11 companies STRING-LOV 

Each of this entries represents field on a form.
Type STRING-LOV is actually reference to asset_attribute_lov table. Is 
there a way that i can do something like:

Field('asset_attribute_id', 'reference asset_attribute',
requires=IS_IN_DB(db, 'asset_attribute.id'),
label=LABEL(T("Atribut"), _for=
"asset_attribute_asset_attribute_id")),

but i want IS_IN_DB to display only values from asset attribute where 
field_type="STRING-LOV", is this possible?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: SQLFORM.factory

2013-04-17 Thread Domagoj Kovač
This works:

{{=form.custom.label[asset_class_attribute.
asset_attribute_id.name]}}
{{=form.custom.widget[asset_class_attribute.
asset_attribute_id.name]}}

Thanks!

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: SQLFORM.factory

2013-04-17 Thread Domagoj Kovač
Thanks guys! I will try it.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] SQLFORM.factory

2013-04-17 Thread Domagoj Kovač
Hi,

i am trying to make a form with dinamic fields and i am using 
SQLFORM.factory. I have a table where i have a list of fields in my form.

in my controller i have:

fields = []

for asset_class_attribute in asset_class_attributes:

field_name = asset_class_attribute.asset_attribute_id.name

fields.append(Field(field_name, requires=IS_NOT_EMPTY()))

form = SQLFORM.factory(*fields)

I my view u would like to do something like this:



{{if asset_class_attributes:}}
{{for asset_class_attribute in asset_class_attributes:}}

{{name = asset_class_attribute.asset_attribute_id.name}}
{{=form.custom.label.name}}
{{=form.custom.widget.name}}


{{pass}}
{{pass}}


{{form.custom.submit['_value'] = T("Spremi")}}
{{=form.custom.submit}}



I want to make name dynamic:

{{name = asset_class_attribute.asset_attribute_id.name}}
{{=form.custom.label.name}}
{{=form.custom.widget.name}}

How can i accomplish that?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Routes

2013-04-15 Thread Domagoj Kovač
In routes.example.py folder i found:

This simple router is used for setting languages from app/languages 
directory
as a part of the application path:  app//controller/function
Language from default.py or 'en' (if the file is not found) is used as
a default_language

If i understand correctly this file can only be used for setting languages. 
Am i right? If so, this is very strange because this way application is not 
portable.. In my main application i must be very specific. For example:

routes_in = (
('/$u/login', '/init/default/login/$u/'),
('/login/$u', '/init/default/login/$u/'),
('/$u/default/login', '/init/default/login/$u/'),
('/login', '/init/default/login'),
('/logout', '/init/default/logout'),
)

This actually means that if i change the name of my application my routing 
will not work until i change routings in base routes.py file. Is this 
correct?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Routes

2013-04-15 Thread Domagoj Kovač
Hi,

i have a problem. In my routes.py file in root folder i have:

routers = dict(
# base router
BASE=dict(default_application='init'),
)

in routes in my application i have:
routes_in = (
('/$u/login', '/default/login/$u/'),
)


I want to have url like /username/login and this is translated into 
default/login/username.

When i try to access http://127.0.0.1:8000/tvrtka_2/login or 
http://127.0.0.1:8000/init/tvrtka_2/login i get an error saying:

invalid function (default/tvrtka_2)

I don't understand what is wrong.


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: request.env.http_referrer

2013-04-12 Thread Domagoj Kovač
I have a typo :(, request.env.http_referer works.

On Friday, April 12, 2013 1:27:10 PM UTC+2, Domagoj Kovač wrote:
>
> Hi,
>
> i am using request.env.http_referrer, and i always get None, is there 
> something i did wrong?
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] request.env.http_referrer

2013-04-12 Thread Domagoj Kovač
Hi,

i am using request.env.http_referrer, and i always get None, is there 
something i did wrong?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Form hidden field

2013-04-11 Thread Domagoj Kovač
I managed to do it with:

{{form.custom.widget.zoom["_hidden"] = "hidden"}}



On Thursday, April 11, 2013 4:46:44 PM UTC+2, Domagoj Kovač wrote:
>
> Hi,
>
> i have a problem. 
>
> This is my table definition.
>
> db.define_table('locations',
> Field('name', 'string',
> required=True,
> requires=IS_NOT_EMPTY(),
> label=LABEL(T("Naziv"), _for="locations_name")),
> Field('parent_id', 'reference locations',
> requires=IS_NULL_OR(IS_IN_DB(db, 'locations.id', 
> '%(name)s', zero=T("Molimo odaberite roditeljsku lokaciju"))),
> label=LABEL(T("Roditelj"), _for="locations_parent_id"
> )),
> Field('gps_x', 'double',
> label=LABEL(T("GPS X koordinata"), _for=
> "locations_address_2")),
> Field('gps_y', 'double',
> label=LABEL(T("GPS Y koordinata"), _for=
> "locations_address_3")),
> Field('zoom', 'integer'),
> )
>
> Gps_x and gps_y are coordinates that i set with google maps API and they 
> are visible to the user.
> Zoom field is a property from google maps API so when user goes to edit 
> form i can show him the map he saw when record was inserted. 
>
> How can i make zoom field hidden, there are properties readable and 
> writeable, but they are not what i want. I want a field like  type="text" hidden="hidden" />.
> How can i accomplish this?
>
> Is there i way that i could make my gps_x and gps_y fields read-only so 
> field are rendered as 
>
> Thanks.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Form hidden field

2013-04-11 Thread Domagoj Kovač
Hi,

i have a problem. 

This is my table definition.

db.define_table('locations',
Field('name', 'string',
required=True,
requires=IS_NOT_EMPTY(),
label=LABEL(T("Naziv"), _for="locations_name")),
Field('parent_id', 'reference locations',
requires=IS_NULL_OR(IS_IN_DB(db, 'locations.id', 
'%(name)s', zero=T("Molimo odaberite roditeljsku lokaciju"))),
label=LABEL(T("Roditelj"), _for="locations_parent_id")),
Field('gps_x', 'double',
label=LABEL(T("GPS X koordinata"), _for=
"locations_address_2")),
Field('gps_y', 'double',
label=LABEL(T("GPS Y koordinata"), _for=
"locations_address_3")),
Field('zoom', 'integer'),
)

Gps_x and gps_y are coordinates that i set with google maps API and they 
are visible to the user.
Zoom field is a property from google maps API so when user goes to edit 
form i can show him the map he saw when record was inserted. 

How can i make zoom field hidden, there are properties readable and 
writeable, but they are not what i want. I want a field like .
How can i accomplish this?

Is there i way that i could make my gps_x and gps_y fields read-only so 
field are rendered as 

Thanks.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Preorder tree traversal

2013-04-11 Thread Domagoj Kovač
HI,

i saw there was a discussion about preorder tree traversal 
https://groups.google.com/forum/?fromgroups=#!topic/web2py/Bw792rYt_nM. 
The thing that i don't understand is how to display this data in a form in 
a select dropdown. I think i must use SQLForm.factory but i am not sure if 
i must create  and 's manually or is there some better 
solution. 

It would be great if anyone can point me in right direction.

Thanks.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Default login script

2013-04-11 Thread Domagoj Kovač
I found it:

auth.settings.login_url = URL('user', args='login')


On Thursday, April 11, 2013 9:35:09 AM UTC+2, Domagoj Kovač wrote:
>
> Hi,
>
> is there anyway that i could change default login script. So when session 
> expires user is logged out and redirected to page i provide.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Default login script

2013-04-11 Thread Domagoj Kovač
Hi,

is there anyway that i could change default login script. So when session 
expires user is logged out and redirected to page i provide.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] db.count()

2013-04-10 Thread Domagoj Kovač
I tried Antonies code and it works. Thanks.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] db.count()

2013-04-10 Thread Domagoj Kovač
Hi,

i have this line of code:

number_of_records = db().count(db.countries.id)

i am receiving an error:
 near ";": syntax error
(self=, *a=('SELECT count(DISTINCT 
countries.id) FROM ;',), **b={})

What is wrong?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multi-tenany and url routing

2013-04-08 Thread Domagoj Kovač
For now i will try a bit different approach.

I will have myapp/company_name_value/login when user logs in i will set a 
cookie with company_name_value and session.company_id. When user is logged 
out, i will use cookie value for redirection to proper login page. 

My initial idea was to handle everything based on subdomain for example 
company_name_value.my_domain.com but this creates a different problem, so 
for now only possible solution is the one explained above. Is there any 
better way?  

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: auth.settings.extra_fields

2013-04-08 Thread Domagoj Kovač
I added companies definition in db.py. It will be ok for now. Thanks.

On Monday, April 8, 2013 11:05:22 AM UTC+2, Domagoj Kovač wrote:
>
> Is there any way to load models manually? 
>
> On Monday, April 8, 2013 10:23:55 AM UTC+2, Niphlod wrote:
>>
>> uhm. if you want that field to be a reference to the values on the table, 
>> the table must be defined, so I don't see how a SQLFORM.factory could help 
>> you with that.
>> You simply have a conditional model that for your app logic doesn't need 
>> to be conditional .
>>
>> On Monday, April 8, 2013 10:20:56 AM UTC+2, Domagoj Kovač wrote:
>>>
>>> I see it now. Thanks man! I have a different problem now, now i don't 
>>> get any errors immediately but when i go on users/create i get an error 
>>> saying:
>>>  'DAL' object has no attribute 
>>> 'companies'
>>> obviously companies model is not loaded, i am thinking on switching to 
>>> SQLform.factory, would this be a better solution? In models i define my 
>>> tables and then in my controller i make a form, then insert and updated 
>>> goes manually, but this is not so problematic.
>>>
>>>
>>> On Monday, April 8, 2013 9:52:24 AM UTC+2, Niphlod wrote:
>>>>
>>>> too many db. 
>>>>
>>>> requires=IS_IN_DB(db, (db, 'companies.id', '%(name)s'))
>>>>
>>>> needs to be
>>>>
>>>> requires=IS_IN_DB(db, 'companies.id', '%(name)s')
>>>>
>>>>
>>>>
>>>> On Monday, April 8, 2013 9:39:15 AM UTC+2, Domagoj Kovač wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> i tried moving companies outside of db.py. 
>>>>>
>>>>> In db.py i have:
>>>>>
>>>>> auth.settings.extra_fields['auth_user'] = [Field('deleted', 'boolean', 
>>>>> default=False),
>>>>>Field('company_id', 'reference 
>>>>> companies', requires=IS_IN_DB(db, (db, 'companies.id', '%(name)s')))]
>>>>>
>>>>> Error i am receiving now is:
>>>>>  too many values to unpack
>>>>> What is wrong now?
>>>>>
>>>>> On Friday, April 5, 2013 7:09:28 PM UTC+2, Anthony wrote:
>>>>>>
>>>>>> Note, simply doing (db, 'companies.id', ...) may not completely 
>>>>>> resolve the problem. Even doing that, the db.companies table is only 
>>>>>> getting defined conditionally when the "companies" controller is called, 
>>>>>> but the db.auth_user table is defined on every request, and it could be 
>>>>>> used by other controllers. If the auth_user table links to another 
>>>>>> table, 
>>>>>> it may be a good idea to make sure that other table is defined whenever 
>>>>>> the 
>>>>>> auth_user table is defined (i.e., maybe move the db.companies table 
>>>>>> definition into db.py or some other model that isn't conditionally 
>>>>>> executed).
>>>>>>
>>>>>> Anthony
>>>>>>
>>>>>> On Friday, April 5, 2013 11:30:38 AM UTC-4, Niphlod wrote:
>>>>>>>
>>>>>>> Nope.
>>>>>>> when "auth" definition is encountered, if you want to use 
>>>>>>> db.companies.id written as it is, db.define_table('companies') 
>>>>>>> should have been executead already.
>>>>>>> You need to change your IS_IN_DB call to (db, 'companies.id', 
>>>>>>> '%(name)s') ... notice the ticks around companies.id, it's a 
>>>>>>> string
>>>>>>> When you do it that way, the db.companies table will be called not 
>>>>>>> at "models definition" time, but at the time the page is rendered (so, 
>>>>>>> allowing all the models to be executed before --> having at your 
>>>>>>> disposition the companies table)
>>>>>>>
>>>>>>> On Friday, April 5, 2013 5:11:32 PM UTC+2, Domagoj Kovač wrote:
>>>>>>>>
>>>>>>>> Thanks guys,
>>>>>>>>
>>>>>>>> right now my db.py looks li

[web2py] Re: auth.settings.extra_fields

2013-04-08 Thread Domagoj Kovač
Is there any way to load models manually? 

On Monday, April 8, 2013 10:23:55 AM UTC+2, Niphlod wrote:
>
> uhm. if you want that field to be a reference to the values on the table, 
> the table must be defined, so I don't see how a SQLFORM.factory could help 
> you with that.
> You simply have a conditional model that for your app logic doesn't need 
> to be conditional .
>
> On Monday, April 8, 2013 10:20:56 AM UTC+2, Domagoj Kovač wrote:
>>
>> I see it now. Thanks man! I have a different problem now, now i don't get 
>> any errors immediately but when i go on users/create i get an error saying:
>>  'DAL' object has no attribute 
>> 'companies'
>> obviously companies model is not loaded, i am thinking on switching to 
>> SQLform.factory, would this be a better solution? In models i define my 
>> tables and then in my controller i make a form, then insert and updated 
>> goes manually, but this is not so problematic.
>>
>>
>> On Monday, April 8, 2013 9:52:24 AM UTC+2, Niphlod wrote:
>>>
>>> too many db. 
>>>
>>> requires=IS_IN_DB(db, (db, 'companies.id', '%(name)s'))
>>>
>>> needs to be
>>>
>>> requires=IS_IN_DB(db, 'companies.id', '%(name)s')
>>>
>>>
>>>
>>> On Monday, April 8, 2013 9:39:15 AM UTC+2, Domagoj Kovač wrote:
>>>>
>>>> Hi,
>>>>
>>>> i tried moving companies outside of db.py. 
>>>>
>>>> In db.py i have:
>>>>
>>>> auth.settings.extra_fields['auth_user'] = [Field('deleted', 'boolean', 
>>>> default=False),
>>>>Field('company_id', 'reference 
>>>> companies', requires=IS_IN_DB(db, (db, 'companies.id', '%(name)s')))]
>>>>
>>>> Error i am receiving now is:
>>>>  too many values to unpack
>>>> What is wrong now?
>>>>
>>>> On Friday, April 5, 2013 7:09:28 PM UTC+2, Anthony wrote:
>>>>>
>>>>> Note, simply doing (db, 'companies.id', ...) may not completely 
>>>>> resolve the problem. Even doing that, the db.companies table is only 
>>>>> getting defined conditionally when the "companies" controller is called, 
>>>>> but the db.auth_user table is defined on every request, and it could be 
>>>>> used by other controllers. If the auth_user table links to another table, 
>>>>> it may be a good idea to make sure that other table is defined whenever 
>>>>> the 
>>>>> auth_user table is defined (i.e., maybe move the db.companies table 
>>>>> definition into db.py or some other model that isn't conditionally 
>>>>> executed).
>>>>>
>>>>> Anthony
>>>>>
>>>>> On Friday, April 5, 2013 11:30:38 AM UTC-4, Niphlod wrote:
>>>>>>
>>>>>> Nope.
>>>>>> when "auth" definition is encountered, if you want to use 
>>>>>> db.companies.id written as it is, db.define_table('companies') 
>>>>>> should have been executead already.
>>>>>> You need to change your IS_IN_DB call to (db, 'companies.id', 
>>>>>> '%(name)s') ... notice the ticks around companies.id, it's a 
>>>>>> string
>>>>>> When you do it that way, the db.companies table will be called not at 
>>>>>> "models definition" time, but at the time the page is rendered (so, 
>>>>>> allowing all the models to be executed before --> having at your 
>>>>>> disposition the companies table)
>>>>>>
>>>>>> On Friday, April 5, 2013 5:11:32 PM UTC+2, Domagoj Kovač wrote:
>>>>>>>
>>>>>>> Thanks guys,
>>>>>>>
>>>>>>> right now my db.py looks like this:
>>>>>>>
>>>>>>> from gluon.tools import Auth, Crud, Service, PluginManager, 
>>>>>>> prettydate
>>>>>>> auth = Auth(db)
>>>>>>> crud, service, plugins = Crud(db), Service(), PluginManager()
>>>>>>>
>>>>>>> db.define_table('companies',
>>>>>>> Field('name', 'string',
>>>>>>>  

[web2py] Re: auth.settings.extra_fields

2013-04-08 Thread Domagoj Kovač
I see it now. Thanks man! I have a different problem now, now i don't get 
any errors immediately but when i go on users/create i get an error saying:
 'DAL' object has no attribute 'companies'
obviously companies model is not loaded, i am thinking on switching to 
SQLform.factory, would this be a better solution? In models i define my 
tables and then in my controller i make a form, then insert and updated 
goes manually, but this is not so problematic.


On Monday, April 8, 2013 9:52:24 AM UTC+2, Niphlod wrote:
>
> too many db. 
>
> requires=IS_IN_DB(db, (db, 'companies.id', '%(name)s'))
>
> needs to be
>
> requires=IS_IN_DB(db, 'companies.id', '%(name)s')
>
>
>
> On Monday, April 8, 2013 9:39:15 AM UTC+2, Domagoj Kovač wrote:
>>
>> Hi,
>>
>> i tried moving companies outside of db.py. 
>>
>> In db.py i have:
>>
>> auth.settings.extra_fields['auth_user'] = [Field('deleted', 'boolean', 
>> default=False),
>>Field('company_id', 'reference 
>> companies', requires=IS_IN_DB(db, (db, 'companies.id', '%(name)s')))]
>>
>> Error i am receiving now is:
>>  too many values to unpack
>> What is wrong now?
>>
>> On Friday, April 5, 2013 7:09:28 PM UTC+2, Anthony wrote:
>>>
>>> Note, simply doing (db, 'companies.id', ...) may not completely resolve 
>>> the problem. Even doing that, the db.companies table is only getting 
>>> defined conditionally when the "companies" controller is called, but the 
>>> db.auth_user table is defined on every request, and it could be used by 
>>> other controllers. If the auth_user table links to another table, it may be 
>>> a good idea to make sure that other table is defined whenever the auth_user 
>>> table is defined (i.e., maybe move the db.companies table definition into 
>>> db.py or some other model that isn't conditionally executed).
>>>
>>> Anthony
>>>
>>> On Friday, April 5, 2013 11:30:38 AM UTC-4, Niphlod wrote:
>>>>
>>>> Nope.
>>>> when "auth" definition is encountered, if you want to use 
>>>> db.companies.id written as it is, db.define_table('companies') should 
>>>> have been executead already.
>>>> You need to change your IS_IN_DB call to (db, 'companies.id', 
>>>> '%(name)s') ... notice the ticks around companies.id, it's a string
>>>> When you do it that way, the db.companies table will be called not at 
>>>> "models definition" time, but at the time the page is rendered (so, 
>>>> allowing all the models to be executed before --> having at your 
>>>> disposition the companies table)
>>>>
>>>> On Friday, April 5, 2013 5:11:32 PM UTC+2, Domagoj Kovač wrote:
>>>>>
>>>>> Thanks guys,
>>>>>
>>>>> right now my db.py looks like this:
>>>>>
>>>>> from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
>>>>> auth = Auth(db)
>>>>> crud, service, plugins = Crud(db), Service(), PluginManager()
>>>>>
>>>>> db.define_table('companies',
>>>>> Field('name', 'string',
>>>>>   required=True,
>>>>>   requires=IS_NOT_EMPTY(),
>>>>>   label=LABEL(T("Naziv"), _for="companies_name")),
>>>>> Field('url_sufix', 'string',
>>>>>   required=True,
>>>>>   requires=IS_NOT_EMPTY(),
>>>>>   unique=True,
>>>>>   label=LABEL(T("Url-sufix"), 
>>>>> _for="companies_url_sufix")),
>>>>> Field('logo', 'upload',
>>>>>   label=LABEL(T("Logo"), _for="companies_logo")),
>>>>> Field('deleted', 'boolean'))
>>>>>
>>>>>
>>>>> auth.settings.extra_fields['auth_user'] = [Field('deleted', 'boolean', 
>>>>> default=False),
>>>>>Field('company_id', 
>>>>> 'reference companies', requires=IS_IN_DB(db, db.companies.id, 
>>>>> '%(name)s'))]
>>>>>
>>>>> ## create all tables needed by auth if not custom tables
>>>>> auth.define_tables(username=False, signature=False)
>>>>>
>>>>> Is there any way i could have my companies definition in 
>>>>> /companies/companies.py but still do this.
>>>>>
>>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: auth.settings.extra_fields

2013-04-08 Thread Domagoj Kovač
Hi,

i tried moving companies outside of db.py. 

In db.py i have:

auth.settings.extra_fields['auth_user'] = [Field('deleted', 'boolean', 
default=False),
   Field('company_id', 'reference 
companies', requires=IS_IN_DB(db, (db, 'companies.id', '%(name)s')))]

Error i am receiving now is:
 too many values to unpack
What is wrong now?

On Friday, April 5, 2013 7:09:28 PM UTC+2, Anthony wrote:
>
> Note, simply doing (db, 'companies.id', ...) may not completely resolve 
> the problem. Even doing that, the db.companies table is only getting 
> defined conditionally when the "companies" controller is called, but the 
> db.auth_user table is defined on every request, and it could be used by 
> other controllers. If the auth_user table links to another table, it may be 
> a good idea to make sure that other table is defined whenever the auth_user 
> table is defined (i.e., maybe move the db.companies table definition into 
> db.py or some other model that isn't conditionally executed).
>
> Anthony
>
> On Friday, April 5, 2013 11:30:38 AM UTC-4, Niphlod wrote:
>>
>> Nope.
>> when "auth" definition is encountered, if you want to use 
>> db.companies.idwritten as it is, db.define_table('companies') should have 
>> been executead 
>> already.
>> You need to change your IS_IN_DB call to (db, 'companies.id', 
>> '%(name)s') ... notice the ticks around companies.id, it's a string
>> When you do it that way, the db.companies table will be called not at 
>> "models definition" time, but at the time the page is rendered (so, 
>> allowing all the models to be executed before --> having at your 
>> disposition the companies table)
>>
>> On Friday, April 5, 2013 5:11:32 PM UTC+2, Domagoj Kovač wrote:
>>>
>>> Thanks guys,
>>>
>>> right now my db.py looks like this:
>>>
>>> from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
>>> auth = Auth(db)
>>> crud, service, plugins = Crud(db), Service(), PluginManager()
>>>
>>> db.define_table('companies',
>>> Field('name', 'string',
>>>   required=True,
>>>   requires=IS_NOT_EMPTY(),
>>>   label=LABEL(T("Naziv"), _for="companies_name")),
>>> Field('url_sufix', 'string',
>>>   required=True,
>>>   requires=IS_NOT_EMPTY(),
>>>   unique=True,
>>>   label=LABEL(T("Url-sufix"), 
>>> _for="companies_url_sufix")),
>>> Field('logo', 'upload',
>>>   label=LABEL(T("Logo"), _for="companies_logo")),
>>> Field('deleted', 'boolean'))
>>>
>>>
>>> auth.settings.extra_fields['auth_user'] = [Field('deleted', 'boolean', 
>>> default=False),
>>>Field('company_id', 
>>> 'reference companies', requires=IS_IN_DB(db, db.companies.id, 
>>> '%(name)s'))]
>>>
>>> ## create all tables needed by auth if not custom tables
>>> auth.define_tables(username=False, signature=False)
>>>
>>> Is there any way i could have my companies definition in 
>>> /companies/companies.py but still do this.
>>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multi-tenany and url routing

2013-04-05 Thread Domagoj Kovač
Does anyone have any advice?

On Thursday, April 4, 2013 2:29:55 PM UTC+2, Domagoj Kovač wrote:
>
> Hi Guys,
>
> i am new to web2py. I have a problem and i am not sure how to approach it. 
> I am working on a multitenant application.
>
> I have two tables:
>
> Tenants
>
>- id
>- name
>- url_sufix
>- active
>- deleted
>
> Tenans_users
>
>- tenant_id
>- user_id
>
> in tenants table url_sufix is a url_sufix, for example, my base 
> application is on 127.0.0.1.:8000/myapp, and login for the tenant is on 
> 127.0.0.1.:8000/myapp/url_sufix for example 127.0.0.1.:8000/myapp/tenant_1. 
> Lets say we have one user that has two tenants. When user logs in trought 
> 127.0.0.1.:8000/myapp/tenant_1 he is also logged in 
> 127.0.0.1.:8000/myapp/tenant_2 because he has two tenants, but if user goes 
> to 127.0.0.1.:8000/myapp/tenant_3 he receives the login form and if 
> he tries to login, he will receive an error saying "credential are wrong". 
>
> I don't need a working code, just an advice how this could be done.
>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: auth.settings.extra_fields

2013-04-05 Thread Domagoj Kovač
Thanks man!

On Friday, April 5, 2013 5:30:38 PM UTC+2, Niphlod wrote:
>
> Nope.
> when "auth" definition is encountered, if you want to use 
> db.companies.idwritten as it is, db.define_table('companies') should have 
> been executead 
> already.
> You need to change your IS_IN_DB call to (db, 'companies.id', '%(name)s') 
> ... notice the ticks around companies.id, it's a string
> When you do it that way, the db.companies table will be called not at 
> "models definition" time, but at the time the page is rendered (so, 
> allowing all the models to be executed before --> having at your 
> disposition the companies table)
>
> On Friday, April 5, 2013 5:11:32 PM UTC+2, Domagoj Kovač wrote:
>>
>> Thanks guys,
>>
>> right now my db.py looks like this:
>>
>> from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
>> auth = Auth(db)
>> crud, service, plugins = Crud(db), Service(), PluginManager()
>>
>> db.define_table('companies',
>> Field('name', 'string',
>>   required=True,
>>   requires=IS_NOT_EMPTY(),
>>   label=LABEL(T("Naziv"), _for="companies_name")),
>> Field('url_sufix', 'string',
>>   required=True,
>>   requires=IS_NOT_EMPTY(),
>>   unique=True,
>>   label=LABEL(T("Url-sufix"), 
>> _for="companies_url_sufix")),
>> Field('logo', 'upload',
>>   label=LABEL(T("Logo"), _for="companies_logo")),
>> Field('deleted', 'boolean'))
>>
>>
>> auth.settings.extra_fields['auth_user'] = [Field('deleted', 'boolean', 
>> default=False),
>>Field('company_id', 'reference 
>> companies', requires=IS_IN_DB(db, db.companies.id, '%(name)s'))]
>>
>> ## create all tables needed by auth if not custom tables
>> auth.define_tables(username=False, signature=False)
>>
>> Is there any way i could have my companies definition in 
>> /companies/companies.py but still do this.
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: auth.settings.extra_fields

2013-04-05 Thread Domagoj Kovač
Thanks guys,

right now my db.py looks like this:

from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db)
crud, service, plugins = Crud(db), Service(), PluginManager()

db.define_table('companies',
Field('name', 'string',
  required=True,
  requires=IS_NOT_EMPTY(),
  label=LABEL(T("Naziv"), _for="companies_name")),
Field('url_sufix', 'string',
  required=True,
  requires=IS_NOT_EMPTY(),
  unique=True,
  label=LABEL(T("Url-sufix"), 
_for="companies_url_sufix")),
Field('logo', 'upload',
  label=LABEL(T("Logo"), _for="companies_logo")),
Field('deleted', 'boolean'))


auth.settings.extra_fields['auth_user'] = [Field('deleted', 'boolean', 
default=False),
   Field('company_id', 'reference 
companies', requires=IS_IN_DB(db, db.companies.id, '%(name)s'))]

## create all tables needed by auth if not custom tables
auth.define_tables(username=False, signature=False)

Is there any way i could have my companies definition in 
/companies/companies.py but still do this.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] auth.settings.extra_fields

2013-04-05 Thread Domagoj Kovač
Hi,

i have a problem.

In my models/db.py file i have this code: 

auth.settings.extra_fields['auth_user'] = [Field('deleted', 'boolean', 
default=False),
   Field('company_id', 'reference 
companies', requires=IS_IN_DB(db,db.companies.id))]

In my models/companies/comanies.py file i have:

db.define_table('companies',
Field('name', 'string',
  required=True,
  requires=IS_NOT_EMPTY(),
  label=LABEL(T("Naziv"), _for="companies_name")),
Field('url_sufix', 'string',
  required=True,
  requires=IS_NOT_EMPTY(),
  unique=True,
  label=LABEL(T("Url-sufix"), _for="companies_url_sufix"
)),
Field('logo', 'upload',
  label=LABEL(T("Logo"), _for="companies_logo")),
Field('deleted', 'boolean'))

I am receiving an error saying: 
 'DAL' object has no attribute 'companies'

What is wrong?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: auth.settings.extra_fields['auth_user']

2013-04-04 Thread Domagoj Kovač
Thanks guys, i solved it other way.

On Thursday, April 4, 2013 3:17:49 AM UTC+2, 黄祥 wrote:
>
> please try this in your db.py:
>
> db.define_table('company',
> Field('company_name'),
> Field('website'),
> format='%(company_name)s')
>
> auth.settings.extra_fields['auth_user']=[
> Field('gender', 'list:string'),
> Field('address', 'text'),
> Field('zip'),
> Field('city'),
> Field('country'),
> Field('phone'),
> Field('company', 'reference company')]
>
> auth.define_tables(username=False, signature=True)
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Multi-tenany and url routing

2013-04-04 Thread Domagoj Kovač
Hi Guys,

i am new to web2py. I have a problem and i am not sure how to approach it. 
I am working on a multitenant application.

I have two tables:

Tenants

   - id
   - name
   - url_sufix
   - active
   - deleted

Tenans_users

   - tenant_id
   - user_id

in tenants table url_sufix is a url_sufix, for example, my base application 
is on 127.0.0.1.:8000/myapp, and login for the tenant is on 
127.0.0.1.:8000/myapp/url_sufix for example 127.0.0.1.:8000/myapp/tenant_1. 
Lets say we have one user that has two tenants. When user logs in trought 
127.0.0.1.:8000/myapp/tenant_1 he is also logged in 
127.0.0.1.:8000/myapp/tenant_2 because he has two tenants, but if user goes 
to 127.0.0.1.:8000/myapp/tenant_3 he receives the login form and if 
he tries to login, he will receive an error saying "credential are wrong". 

I don't need a working code, just an advice how this could be done.


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] auth.settings.extra_fields['auth_user']

2013-04-03 Thread Domagoj Kovač
Hi folks,

i have a problem. I am using form widget i am trying to customize 
registration form. I my model i added 

auth.settings.extra_fields['auth_user'] = [Field('company_id', 'string',required
=True)]

in my register.html view i have. 

{{form.custom.widget.company_id['_class'] = 'w70'}}
TvrtkaOdaberite tvrtku
{{=form.custom.widget.company_id}}



when i submit the form i am not receiving any error messages. Am i missing 
something?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.