[web2py] Internalization for text containing link

2016-08-17 Thread Marko Seppälä
What is the standard way to use T helper with text containing links:

Please click here my friend.

Do I need to have three separate T elements, like this:

{{=T('Please click ')}}{{=T('here')}}{{=T(' my friend.')}}

Or is there possible better syntax to handle this kind of cases?

Thanks

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Include tag doesn't preserve indentation level on included text

2016-09-25 Thread Marko Seppälä
Hi,

Not sure if this is expected behavior but I can't figure out any reason why 
it is done like this.

Currently include tag messes up the indentation level. Only first line of 
included file is indented same level as parent file, other lines start from 
zero. I think indentation level should be preserved, so that indentation in 
include tag is added to every line in included file.


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Include tag doesn't preserve indentation level on included text

2016-09-26 Thread Marko Seppälä


maanantai 26. syyskuuta 2016 14.17.24 UTC+3 Anthony kirjoitti:
>
> On Sunday, September 25, 2016 at 11:56:33 PM UTC-4, Marko Seppälä wrote:
>>
>> Hi,
>>
>> Not sure if this is expected behavior but I can't figure out any reason 
>> why it is done like this.
>>
>> Currently include tag messes up the indentation level. Only first line of 
>> included file is indented same level as parent file, other lines start from 
>> zero. I think indentation level should be preserved, so that indentation in 
>> include tag is added to every line in included file.
>>
>> How to fix that problem?
>>
>
> The {{include}} statement is intended to include exactly what is in the 
> included file, starting at the point of the {{include}} -- if the text in 
> the included file is not indented, then neither will it be indented once 
> included. If you want it indented, then you must indent the text in the 
> included file.
>
> Also, note that if you are producing HTML, indenting is not necessary 
> anyway.
>
> Anthony
>

Yes I'm producing HTML and I know it's not a big problem since it's not 
affecting to functionality. But still I prefer end result which looks clean 
and is indented in a proper manner. Indenting matters for the readability 
of HTML so I want it to be right.

I could get a right end result if I manually indent every other than first 
line in a included file so that it match to indentation level in file where 
it is included. But I think this is even worse since it mixes up my 
original source code. In my opinion, include statement should work so that 
it preserves the original indentation. So if include statement is indented 
for example three tabs, then every line in included file should be indented 
three tabs plus their indentation in original file. This way your source 
code and end result looks always right.

 Is there any quick fix how I could implement that? I haven't check web2py 
template engine yet.

- Marko

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Include tag doesn't preserve indentation level on included text

2016-09-26 Thread Marko Seppälä


maanantai 26. syyskuuta 2016 16.55.13 UTC+3 Anthony kirjoitti:
>
>
> The {{include}} statement is intended to include exactly what is in the 
>>> included file, starting at the point of the {{include}} -- if the text in 
>>> the included file is not indented, then neither will it be indented once 
>>> included. If you want it indented, then you must indent the text in the 
>>> included file.
>>>
>>> Also, note that if you are producing HTML, indenting is not necessary 
>>> anyway.
>>>
>>> Anthony
>>>
>>
>> Yes I'm producing HTML and I know it's not a big problem since it's not 
>> affecting to functionality. But still I prefer end result which looks clean 
>> and is indented in a proper manner. Indenting matters for the readability 
>> of HTML so I want it to be right.
>>
>
> Readability is most important in the files you edit (i.e., the view 
> files). Why do you need the final HTML to be so readable? If it's for 
> debugging, I suppose you could always pass the output through something 
> like Beautiful Soup prettify() 
>  
> when in development.
>  
>
>> I could get a right end result if I manually indent every other than 
>> first line
>>
>
> Or indent everything (including the first line) in the included file but 
> don't indent the {{include}} in the extended view.
>  
>
>> In my opinion, include statement should work so that it preserves the 
>> original indentation. So if include statement is indented for example three 
>> tabs, then every line in included file should be indented three tabs plus 
>> their indentation in original file.
>>
>
> That would not be good default behavior because we can't always assume 
> leading space represents indentation. Indentation would need to be an 
> option triggered by some kind of flag.
>  
>
>> Is there any quick fix how I could implement that?
>>
>
> I don't think so. I would suggest using an alternative templating engine, 
> but I don't think others (e.g., Django, Jinja2, Mako) provide this option 
> either (solutions I've seen require you to specify the indentation level, 
> somewhat defeating the purpose).
>
> You could probably write a function to add the indentation, but it would 
> have to be called dynamically on the included template, which would kill 
> the speed benefit of compiled views.
>
> Anthony
>

It actually doesn't matter that much for me, I only work with web2py 
templates.  End result just looks little unprofessional since it's not 
formatted properly and I couldn't figure out any reason why not to do so. 
But I understand now your point. Django doesn't have this feature either.

I think this would be a nice to have feature in production to get cleaner 
and more professional looking end result. And human readable HTML helps 
also in development, especially if you're working with someone who is not 
familiar with web2py templates. Optional flag solution would be good which 
could be set if we want to preserve the indentation.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Include tag doesn't preserve indentation level on included text

2016-09-26 Thread Marko Seppälä


maanantai 26. syyskuuta 2016 20.11.06 UTC+3 Anthony kirjoitti:
>
>
> It actually doesn't matter that much for me, I only work with web2py 
>> templates.  End result just looks little unprofessional since it's not 
>> formatted properly and I couldn't figure out any reason why not to do so.
>>
>
> "Unprofessional" to whom? Who's looking at the page source that you're 
> trying to impress (that wouldn't understand the nature of template engines 
> and the unimportance of indentation)?
>  
>
>> I think this would be a nice to have feature in production to get cleaner 
>> and more professional looking end result.
>>
>
> Production is the one place you probably don't want this feature, as it 
> would require a little extra processing and increase the payload.
>  
>
>> And human readable HTML helps also in development, especially if you're 
>> working with someone who is not familiar with web2py templates.
>>
>
> Again, keep in mind that you can just indent the content in the included 
> file. Any decent code editor will let you quickly indent multiple lines 
> simultaneously.
>
> Anthony
>

Yes I know I can indent multiple lines simultaneously but it's still manual 
and unnecessary work, also messes up my source so not really an option. The 
whole point was that if there is no harm to indent everything properly by 
template engine, then why not to do it. But I understood your point why 
it's not implemented by default so basically it answers to my question.

Not sure how much more processing and payload is needed if this is 
implemented. If it's practically zero then I would do it but of course if 
it's significant then it's better to let it be like it's now.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Setup web2py in Vagrant provision phase

2016-10-04 Thread Marko Seppälä
Hi,

I'm using Vagrant to create Ubuntu 14.04 virtual server. I use 
setup-web2py-ubuntu.sh 
script in provision phase but it doesn't work out of the box with Vagrant. If 
I ssh to virtual server and run the script, everything works. But in "creating 
a self signed certificate" phase script asks some information about 
country, email etc. If I run the script through vagrant provision, then 
those are not asked but left empty instead. I guess that is the reason why 
script fails and gives me an error:

==> default: You are about to be asked to enter information that will be 
incorporated
==> default: into your certificate request.
==> default: What you are about to enter is what is called a Distinguished 
Name or a DN.
==> default: There are quite a few fields but you can leave some blank
==> default: For some fields there will be a default value,
==> default: If you enter '.', the field will be left blank.
==> default: -
==> default: Country Name (2 letter code) [AU]:
==> default: problems making Certificate Request
==> default: unable to load certificate
==> default: 139944983766688:error:0906D06C:PEM routines:PEM_read_bio:no 
start line:pem_lib.c:703:Expecting: TRUSTED CERTIFICATE
==> default: rewriting your apache config file to use mod_wsgi
==> default: =
==> default: Enabling site default.
==> default: To activate the new configuration, you need to run:
==> default:   service apache2 reload
==> default: restarting apache
==> default: 
==> default:  * Restarting web server apache2
==> default:...fail!
==> default:  * The apache2 configtest failed.
==> default: Output of config test was:
==> default: AH00526: Syntax error on line 27 of 
/etc/apache2/sites-enabled/default.conf:
==> default: SSLCertificateFile: file '/etc/apache2/ssl/self_signed.cert' 
does not exist or is empty
==> default: Action 'configtest' failed.
==> default: The Apache error log may have more information.
==> default: admin password:
==> default: Traceback (most recent call last):
==> default:   File "", line 1, in 
==> default: EOFError
==> default: :
==> default: EOF when reading a line
==> default: done!

How I could fix that problem? I'm not too familiar with bash scripting and 
just started to learn Vagrant so I'm having problems to figure out how to 
proceed.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Setup web2py in Vagrant provision phase

2016-10-05 Thread Marko Seppälä
Hi Richard,

Thanks for your reply. Unfortunately your answer is not detailed enough to 
make it sure that I did everything correctly.

I managed to make it work by just adding -batch option to "openssl reg -new 
..." command. Also everything seems to work when I ssh to server and try 
wget to 127.0.0.1. But i'm not sure if the certificate 
is done properly this way.

Could you verify if this method is okay for development?

tiistai 4. lokakuuta 2016 21.17.57 UTC+3 Richard kirjoitti:
>
> prompt and read, then 
> http://stackoverflow.com/questions/15476479/sign-certificate-without-prompt-in-shell-script
>
> Richard
>
> On Tue, Oct 4, 2016 at 2:04 PM, Marko Seppälä  > wrote:
>
>> Hi,
>>
>> I'm using Vagrant to create Ubuntu 14.04 virtual server. I use 
>> setup-web2py-ubuntu.sh 
>> script in provision phase but it doesn't work out of the box with Vagrant. 
>> If 
>> I ssh to virtual server and run the script, everything works. But in 
>> "creating 
>> a self signed certificate" phase script asks some information about 
>> country, email etc. If I run the script through vagrant provision, then 
>> those are not asked but left empty instead. I guess that is the reason why 
>> script fails and gives me an error:
>>
>> ==> default: You are about to be asked to enter information that will be 
>> incorporated
>> ==> default: into your certificate request.
>> ==> default: What you are about to enter is what is called a 
>> Distinguished Name or a DN.
>> ==> default: There are quite a few fields but you can leave some blank
>> ==> default: For some fields there will be a default value,
>> ==> default: If you enter '.', the field will be left blank.
>> ==> default: -
>> ==> default: Country Name (2 letter code) [AU]:
>> ==> default: problems making Certificate Request
>> ==> default: unable to load certificate
>> ==> default: 139944983766688:error:0906D06C:PEM routines:PEM_read_bio:no 
>> start line:pem_lib.c:703:Expecting: TRUSTED CERTIFICATE
>> ==> default: rewriting your apache config file to use mod_wsgi
>> ==> default: =
>> ==> default: Enabling site default.
>> ==> default: To activate the new configuration, you need to run:
>> ==> default:   service apache2 reload
>> ==> default: restarting apache
>> ==> default: 
>> ==> default:  * Restarting web server apache2
>> ==> default:...fail!
>> ==> default:  * The apache2 configtest failed.
>> ==> default: Output of config test was:
>> ==> default: AH00526: Syntax error on line 27 of 
>> /etc/apache2/sites-enabled/default.conf:
>> ==> default: SSLCertificateFile: file '/etc/apache2/ssl/self_signed.cert' 
>> does not exist or is empty
>> ==> default: Action 'configtest' failed.
>> ==> default: The Apache error log may have more information.
>> ==> default: admin password:
>> ==> default: Traceback (most recent call last):
>> ==> default:   File "", line 1, in 
>> ==> default: EOFError
>> ==> default: :
>> ==> default: EOF when reading a line
>> ==> default: done!
>>
>> How I could fix that problem? I'm not too familiar with bash scripting 
>> and just started to learn Vagrant so I'm having problems to figure out how 
>> to proceed.
>>
>> -- 
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to web2py+un...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Custom formstyle for auth

2016-10-25 Thread Marko Seppälä
Hi,

I'm trying to set custom form styles for auth, like register or login form. 
I would like to set completely new formstyle function for that, so that 
it's easy to use over and over again just setting formstyle = my_formstyle 
in appconfig.ini.

How I could do that? I can use formstyle_bootstrap3_inline_factory 
from sqlhtml.py as a starting point for my own function. But where should I 
put that function? And how to tell web2py where to look for that function? 
Obviously I don't want to touch original source code.

Thanks!

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] How to translate dynamic data with web2py

2016-11-05 Thread Marko Seppälä


Let's say we have a table

db.define_table('thing',
Field('name'),
Field('description', 'text'),Field('age', 
'integer'))


and we need to translate this to X amount of different languages and there 
could be potentially huge amount of these objects in database. How I should 
handle internalization/translations of these objects? Not all fields need 
to be translated, for example in that case age is language neutral 
information.

I know I could mark these with T and do something like {{=T(thing.name)}} in 
views for example. But it means that translation files are growing huge and 
managing translations isn't so easy. Also I'm not able to search objects 
from database based on translated information, for example if I want to 
find all things which have keywords x, y and z in their description and I 
want to use Germany as a search language. At least I've understood this so.


Other approach would be to take care of internalization in database level, 
either with "multiple column approach" or "multiple table approach" 
described very well in here: 
https://www.sofokus.com/en/localizing-dynamic-content-in-web-apps/
Multiple column approach is not really an option for X amount of languages 
but multiple table approach would work. The problem is that number of 
models get multiplied almost by two if content is in separate model and 
also controllers gets more complex, especially because I need fallback to 
default language in case of there is no translation. And inserting new data 
to database is more complex too since we need to add data to more than one 
table at time.

I'm wondering, is there any ready-made standard solution for this problem 
which would make this all easy to implement and manage in web2py? This is 
very standard need so for sure I'm not the first one to implement something 
like this. In Django, they have Parler 
(https://pypi.python.org/pypi/django-parler) for example which solves this 
problem very well and it's easy to use.

I think ideal solution is something where I wouldn't need care about 
internalization in views. So I could iterate over all things in views 
normally as I would do just in case of single language and names and 
descriptions would be in language user wants, or with fallback language if 
translation is not found. For example:

{{for thing in things:}}
{{=thing.name}}
{{=thing.description}}
{{=thing.age}}
{{pass}}


Also managing translations should be easy. Interface presented in picture below 
would work very well (from 
https://www.sofokus.com/en/localizing-dynamic-content-in-web-apps/)



Any help is appreciated! I'm sure many of you have done this before so I'm 
willing to hear how you solve this. Also, is there any plans to implement 
something similar like Django Parler for web2py?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to translate dynamic data with web2py

2016-11-12 Thread Marko Seppälä
Thanks Leanel, I'll try your approaches. Especially second approach looks 
great!

Any idea why that kind of solution isn't part of standard web2py and 
documented in web2py book?

lauantai 5. marraskuuta 2016 19.56.03 UTC+2 Leonel Câmara kirjoitti:
>
> https://groups.google.com/forum/#!topic/web2py/y1QYmM4HfeM
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] How to upload files programmatically from file system?

2016-03-31 Thread Marko Seppälä
Hi,

I want to upload some of the images programmatically from file system, when 
initializing the database. Not the actual file though, just normal upload 
so that file stays in file system but it's accessible via database for 
every user.

I tried something like this:

db.define_table('image',
Field('name'),
Field('file', 'upload')
)

FILES = [
['apple', 'apple.png'],
['dog', 'gog-image.png'],
...
]

if db(db.image.id>0).count() == 0:
for file in FILES:
filename = URL('static','images/files/{}'.format(file[1]))
stream = open(filename, 'rb')
db.image.insert(name=file[0], file=stream)

I'll get an error:
* [Errno 2] No such file or directory: 
'/example/static/images/files/apple.png'*

It looks like my path is broken and I should use os.path.join etc. to get 
the whole path. But I couldn't make this work.
What is the correct way to set that path? For example, how it is done by 
web2py since everything works normally if I upload those images via admin 
interface? I'm working on Windows environment.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] How to upload files programmatically from file system?

2016-03-31 Thread Marko Seppälä
Hi Richard,

I was finally able to make this work this way:
filename = 
os.path.join(request.folder,'static/images/files/{}'.format(file[1]))
stream = open(filename, 'rb')
db.vendor.insert(default_name = vendor[0], logo=stream)

When I print the path, there is both forward slashes and backslashes in the 
path. I'm not sure if that is correct behaviour, but it works.

Any suggestions how you could do this in a better way?

- Marko

torstai 31. maaliskuuta 2016 16.26.09 UTC+3 Richard kirjoitti:
>
> Should be URL('static','images/files/{*0*}'.format(file[1]))
>
> Richard
>
> On Thu, Mar 31, 2016 at 6:34 AM, Marko Seppälä  > wrote:
>
>> Hi,
>>
>> I want to upload some of the images programmatically from file system, 
>> when initializing the database. Not the actual file though, just normal 
>> upload so that file stays in file system but it's accessible via database 
>> for every user.
>>
>> I tried something like this:
>>
>> db.define_table('image',
>> Field('name'),
>> Field('file', 'upload')
>> )
>>
>> FILES = [
>> ['apple', 'apple.png'],
>> ['dog', 'gog-image.png'],
>> ...
>> ]
>>
>> if db(db.image.id>0).count() == 0:
>> for file in FILES:
>> filename = URL('static','images/files/{}'.format(file[1]))
>> stream = open(filename, 'rb')
>> db.image.insert(name=file[0], file=stream)
>>
>> I'll get an error:
>> * [Errno 2] No such file or directory: 
>> '/example/static/images/files/apple.png'*
>>
>> It looks like my path is broken and I should use os.path.join etc. to get 
>> the whole path. But I couldn't make this work.
>> What is the correct way to set that path? For example, how it is done by 
>> web2py since everything works normally if I upload those images via admin 
>> interface? I'm working on Windows environment.
>>
>> -- 
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to web2py+un...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Using site packages with web2py

2016-04-14 Thread Marko Seppälä
Hi,

I'm trying to import openpyxl to web2py without success. What is the right 
way to do it?

I have working openpyxl in my Windows environment and I'm able to use it 
without problems when testing it without web2py. If I understood right, I 
can either install openpyxl to web2py site packages and run web2py.exe, or 
I can run web2py from source and then it should be able to use already 
installed openpyxl. Neither of these methods is working. I followed the 
instructions in the book and installed pywin32 before running from source, 
but it won't help. When I run "python web2py.py", it says:
no file locking, you must install the win32 extensions from: 
http://sourceforge.
net/projects/pywin32/files/

So looks like there is something wrong with the pywin32 installation, even 
though I've installed it for sure. Any ideas what could be wrong? And why I 
cant import openpyxl even though I installed it to web2py's site-packages 
folder?

I'm using Python 3.3.3 and Windows-bit.

Thanks,
- Marko 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Using site packages with web2py

2016-04-14 Thread Marko Seppälä
Hi,

Just found that, I've always run web2py from exe-file so far, so didn't 
realize that before...

torstai 14. huhtikuuta 2016 19.56.34 UTC+3 Niphlod kirjoitti:
>
> first of all, web2py is not python 3 compatible.
>
> On Thursday, April 14, 2016 at 6:02:20 PM UTC+2, Marko Seppälä wrote:
>>
>> Hi,
>>
>> I'm trying to import openpyxl to web2py without success. What is the 
>> right way to do it?
>>
>> I have working openpyxl in my Windows environment and I'm able to use it 
>> without problems when testing it without web2py. If I understood right, I 
>> can either install openpyxl to web2py site packages and run web2py.exe, or 
>> I can run web2py from source and then it should be able to use already 
>> installed openpyxl. Neither of these methods is working. I followed the 
>> instructions in the book and installed pywin32 before running from source, 
>> but it won't help. When I run "python web2py.py", it says:
>> no file locking, you must install the win32 extensions from: 
>> http://sourceforge.
>> net/projects/pywin32/files/
>>
>> So looks like there is something wrong with the pywin32 installation, 
>> even though I've installed it for sure. Any ideas what could be wrong? And 
>> why I cant import openpyxl even though I installed it to web2py's 
>> site-packages folder?
>>
>> I'm using Python 3.3.3 and Windows-64bit.
>>
>> Thanks,
>> - Marko 
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Multi language database query

2016-04-22 Thread Marko Seppälä
Hi,

I have a following database:

db.define_table('language',
Field('code', 'string', unique=True)
)

db.define_table('translation',
Field('language_id', 'reference language', notnull=True, readable=True, 
writable=True),
auth.signature
)

db.define_table('language_tr',
Field('translation_id', 'reference translation', notnull=True, 
readable=True, writable=True),
Field('language_id', 'reference language', notnull=True, readable=True, 
writable=True),
Field('name', notnull=True)
)

So basically I have a list of supported languages in the language table. 
Then language_tr table has all names for those languages, in every possible 
language. language_id references to the language which is translated and 
translation_id references to the translation, which has language_id for the 
language which is used for the translation.

In database this works great, but I'm having problems to build a simple 
enough database query to get all translations whit selected language only. 
For example, user wants to use English and sets that to system language. So 
I want to show translations only in English, not with all possible 
languages.

What is the most efficient way to get only translations in English? 
Basically I'm looking for a list of language_tr elements which has a 
translation_id 
which has a language_id which is same than users selected system language.

- Marko

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multi language database query

2016-04-22 Thread Marko Seppälä
I think that that reference in language_tr table is needed. Otherwise there 
is no way to translate those for more than one language I think.

For example, if we have two languages, let's say English and German, and we 
want to translate both languages to both languages. So for example language 
with code "en" would be translated to "English" with 
translation.language_id.code == "en" and to "Englisch" 
with translation.language_id.code == "de". But language_tr would be 
referencing to language_id.code == "en" in both cases.

Otherwise your answer is very good! I'm still very beginner with this so 
step by step instructions are very welcome :)

I was able to make it work this way:
languages = db((db.language_tr.id>0)).select()
for language in languages.exclude(lambda language: 
language.translation_id.language_id!=system_language_id):
pass

This looks somewhat ugly, I'm sure that there is a better way.

perjantai 22. huhtikuuta 2016 22.02.40 UTC+3 Niphlod kirjoitti:
>
> imho there's a reference not needed (the language_id in the language_tr 
> table)
>
> that being said...let's build queries, step by step
>
> """
> Basically I'm looking for a list of language_tr elements which has a 
> translation_id which has a language_id which is same than users selected 
> system language.
> """
> start backwards:
> . let's name tables with a shorter name (we don't want to die in the 
> process of typing)
> lng = db.language
> trs = db.translation
> ltr = db.language_tr
> . what's the Query we need to filter out of the language the user selects 
> ? 
> lng.code == 'user_selected_language'
> . what's the translation row(s) related to that record ?
> .. we need to join by the link between lng and trs
>(lng.id == trs.language_id)
> . what are language_tr row(s) related to the trs record ?
> .. we need to join by the link between trs and ltr 
>(trs.id == ltr.translation_id)
> . summing up all relations, we now have
>(lng.id == trs.language_id) & (trs.id == ltr.translation_id) 
> . we append our Query
>(lng.id == trs.language_id) & (trs.id == ltr.translation_id) & 
> (lng.code == 'user_selected_language')
> . what do we want ? ltr.ALL, let's select it
> . cook it up alltogether
> db(
>  (lng.id == trs.language_id) & (trs.id == ltr.translation_id) & 
> (lng.code == 'user_selected_language')
>  ).select(ltr.ALL)
>
> On Friday, April 22, 2016 at 3:51:51 PM UTC+2, Marko Seppälä wrote:
>>
>> Hi,
>>
>> I have a following database:
>>
>> db.define_table('language',
>> Field('code', 'string', unique=True)
>> )
>>
>> db.define_table('translation',
>> Field('language_id', 'reference language', notnull=True, 
>> readable=True, writable=True),
>> auth.signature
>> )
>>
>> db.define_table('language_tr',
>> Field('translation_id', 'reference translation', notnull=True, 
>> readable=True, writable=True),
>> Field('language_id', 'reference language', notnull=True, 
>> readable=True, writable=True),
>> Field('name', notnull=True)
>> )
>>
>> So basically I have a list of supported languages in the language table. 
>> Then language_tr table has all names for those languages, in every 
>> possible language. language_id references to the language which is 
>> translated and translation_id references to the translation, which has 
>> language_id 
>> for the language which is used for the translation.
>>
>> In database this works great, but I'm having problems to build a simple 
>> enough database query to get all translations whit selected language only. 
>> For example, user wants to use English and sets that to system language. So 
>> I want to show translations only in English, not with all possible 
>> languages.
>>
>> What is the most efficient way to get only translations in English? 
>> Basically I'm looking for a list of language_tr elements which has a 
>> translation_id 
>> which has a language_id which is same than users selected system 
>> language.
>>
>> - Marko
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] How to get rows in right format

2016-04-30 Thread Marko Seppälä
Hi,

I have a database where following structure is quite common:

db.define_table('thing',
Field('name)
)

db.define_table('property',
Field('name)
)

db.define_table('thing_has_property',
Field('thing_id', 'reference thing'),
Field('property_id', 'reference property'),
Field('order_number', 'integer', default=1, notnull=True)
)

Order number is not always present, but in many cases it's necessary. 
Basically it tells the order of properties for the given thing.

I want to get listing of all things and their properties. I can do the 
following:

query = (db.thing.id == db.thing_has_property.thing_id) &
(db.thing_has_property.property_id == db.property.id)
things_and_their_properties = db(query).select()

However, I would like to get the data in a format where I have each thing 
listed only once and all it's properties are in the same row in right order 
based on the order number. Like
things_and_their_properties = [
 ['thing1', 'p1', 'p2', 'p7'],
 ['thing2', 'p1', 'p4'],
 etc...
 ]

Currently I'm doing this kind of restructuring manually and sometimes it's 
quite complicated since some of those datastructures are way more complex 
than this. I'm wondering, is there any way to do this kind of sorting with 
web2py? So that I could get rows which are already in format I need in my 
application. I think that my need is quite common so I guess there is some 
kind of standard way to do this.

Thanks in advance!

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to get rows in right format

2016-05-01 Thread Marko Seppälä
It works, thanks! I forgot the whole thing. When I started with web2py, one 
expert recommended me not to use list references but do all intermediary 
tables yourself.

Is there any drawbacks to use list reference instead of doing those 
intermediary tables yourself?


lauantai 30. huhtikuuta 2016 17.09.05 UTC+3 Pierre kirjoitti:
>
> this might help:
>
>
>
>
> *db.define_table('thing_has_property',  
> Field('property_ids','list:reference property')*it allows you to manage 
> properties order like so : p1 = row.property_ids[0],  
> p2=row.property_ids[1]...etc
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to get rows in right format

2016-05-04 Thread Marko Seppälä
I need to do very complex queries. Actually so complex that I don't even 
know how to do it properly, even though I managed to get it work without 
list reference. I discussed with one expert yesterday and he recommended 
not to use list reference in my case.

So currently I'm wondering what is the efficient way to reorganize my data 
to right format. Following example from web2py book's is usually part of my 
queries:

>>> persons_and_things = db((db.person.id == db.ownership.person) &
(db.thing.id == db.ownership.thing))

>>> for row in persons_and_things.select():
print row.person.name, row.thing.name
Alex BoatAlex ChairBob ShoesCurt Boat

Is there any "standard" way to get the results in the following format, 
even though you're not using list reference? That format is more natural to 
handle in controllers and views, so I need to reorganize the data somehow.

Alex Boat, ChairBob ShoesCurt Boat


Should be probably some kind of dictionary containing keys person and 
things, and then things is list of individual things.


maanantai 2. toukokuuta 2016 20.11.33 UTC+3 Anthony kirjoitti:
>
> On Sunday, May 1, 2016 at 3:17:49 PM UTC-4, Marko Seppälä wrote:
>>
>> It works, thanks! I forgot the whole thing. When I started with web2py, 
>> one expert recommended me not to use list references but do all 
>> intermediary tables yourself.
>>
>> Is there any drawbacks to use list reference instead of doing those 
>> intermediary tables yourself?
>>
>
> It depends on how you will need to query the data. If you typically just 
> need to list the property IDs for individual "things", then list:reference 
> might be a reasonable approach. However, if you need to do more complex 
> queries involving attributes of things and their properties, then your 
> original approach will allow more flexibility.
>
> Anthony
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.