[web2py] Re: Long text internationalization

2019-02-12 Thread Dave S


On Tuesday, February 12, 2019 at 3:57:36 AM UTC-8, Jonsubs wrote:
>
> Hi everyone,
> Which is the common practice when facing long text internationalization?
>
> For instance, What should be done when you want to render a web page, 
> sharing a common layout, that has several paragraphs that must be 
> completelly translated?
>
> Based on the manual ( 
> http://www.web2py.com/books/default/chapter/29/04/the-core#Internationalization-and-Pluralization-with-T
>  
> ) only string constants should be used with T. My guess is that large texts 
> should be treated differently.
>
> Thanks & Regards, Jon.
>


It looks like you're set for paragraphs of [previously] translated text.  
For really large pieces (pages long), you can take a look at how the web2py 
book does it:
https://github.com/web2py/web2py-book>
(just another web2py app, but the book content is in the sources 
sub-directory)

Does Google Translate have an API?  If it does, that would probably be like 
using jQuery divs.

FWIW, there's an interesting article (one of 3, it seems) about using a VPN 
to block app's from accessing Google resources;
https://gizmodo.com/i-cut-google-out-of-my-life-it-screwed-up-everything-1839565500>
[It would certainly be hard to use this group for support if you blocked 
access to Google servers.]
[[ Google controls 8,699,648 IP addresses, per the article]]

/dps

-- 
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] Re: Splitting form

2019-02-12 Thread Ben Duncan
Ok, got it thanks ...

*Ben Duncan*
DBA / Chief Software Architect
Mississippi State Supreme Court
Electronic Filing Division


On Tue, Feb 12, 2019 at 4:23 PM Dave S  wrote:

>
>
> On Tuesday, February 12, 2019 at 1:40:25 PM UTC-8, Dave S wrote:
>>
>> On Tuesday, February 12, 2019 at 5:19:54 AM UTC-8, Ben Duncan wrote:
>>>
>>> Excuse my ignorance (Being a NEWBIE is irritating to me after having
>>> done CS stuff for 30+ years)
>>> But, Dave, exactly whats is turning on left-colum / right column support
>>> ?
>>>
>>> Thanks ..
>>>
>>>
>> The correct term is "sidebar", but it behaves like columns (magazine
>> style, rather than newspaper style, I'd say), so I ask for your indulgence.
>>
>> In 2.17.1, the welcome app no longer has this present-but-disabled, but
>> you can look at the examples app.  layout.html has conditionals for
>> left_sidebar_enabled and right_sidebar_enabled, and several views in the
>> default subdir have {{ block sidebar}} {{end}} (take a look at  what.html,
>> for instance).
>>
>>
> In one of my apps, but not one I can reach from this location, I use the
> left sidebar to  show a list of links, which is a common style, but my
> sidebar isn't set off with a different background like them thar fancy
> sites.
>
> /dps
>
> --
> 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.
>

-- 
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] Re: Splitting form

2019-02-12 Thread Dave S


On Tuesday, February 12, 2019 at 1:40:25 PM UTC-8, Dave S wrote:
>
> On Tuesday, February 12, 2019 at 5:19:54 AM UTC-8, Ben Duncan wrote:
>>
>> Excuse my ignorance (Being a NEWBIE is irritating to me after having done 
>> CS stuff for 30+ years)
>> But, Dave, exactly whats is turning on left-colum / right column support ?
>>
>> Thanks ..
>>
>>
> The correct term is "sidebar", but it behaves like columns (magazine 
> style, rather than newspaper style, I'd say), so I ask for your indulgence.
>
> In 2.17.1, the welcome app no longer has this present-but-disabled, but 
> you can look at the examples app.  layout.html has conditionals for 
> left_sidebar_enabled and right_sidebar_enabled, and several views in the 
> default subdir have {{ block sidebar}} {{end}} (take a look at  what.html, 
> for instance).
>
>
In one of my apps, but not one I can reach from this location, I use the 
left sidebar to  show a list of links, which is a common style, but my 
sidebar isn't set off with a different background like them thar fancy 
sites.

/dps

-- 
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] Re: Splitting form

2019-02-12 Thread Dave S
On Tuesday, February 12, 2019 at 5:19:54 AM UTC-8, Ben Duncan wrote:
>
> Excuse my ignorance (Being a NEWBIE is irritating to me after having done 
> CS stuff for 30+ years)
> But, Dave, exactly whats is turning on left-colum / right column support ?
>
> Thanks ..
>
>
The correct term is "sidebar", but it behaves like columns (magazine style, 
rather than newspaper style, I'd say), so I ask for your indulgence.

In 2.17.1, the welcome app no longer has this present-but-disabled, but you 
can look at the examples app.  layout.html has conditionals for 
left_sidebar_enabled and right_sidebar_enabled, and several views in the 
default subdir have {{ block sidebar}} {{end}} (take a look at  what.html, 
for instance).

/dps

-- 
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] Re: Long text internationalization

2019-02-12 Thread Jon Subscripted
Thanks Leonel!!
I'll use your plugin then.
Regards, Jon.

On Tue, Feb 12, 2019 at 1:37 PM Leonel Câmara 
wrote:

> Large texts are actually fine as long as they're kind of static.
>
> For dynamic long texts I store them in a JSON field where I have a dict
> with a key for each language I want to support, I actually made a plugin
> which gives you a nice widget for this field json field which you can put
> in your modules folder and import it. I'll annex it.
>
> Example usage:
>
> from plugin_json_translation import TranslateWidget
>
> def represent_lang(v, row):
> if v is None:
> return v
> if T.accepted_language[:2] in v:
> return v[LANG]
> else:
> return v['en']
>
> db.define_table('my_test',
> Field('body', 'json', widget=TranslateWidget().widget, requires=
> IS_EMPTY_OR(IS_JSON()), represent=represent_lang),
> )
>
>
> Then you just need to call render when you get my_test rows and you will
> get a translated version.
>
>
> --
> 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.
>

-- 
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] Accessing MySQL data without define tables

2019-02-12 Thread Jon Subscripted
Thanks Ben,
I'll try what you suggest.
Regards, Jon.

On Tue, Feb 12, 2019 at 2:17 PM Ben Duncan  wrote:

> Here is the TOP of what I use.
> You will  need the migrate commands in your connections tring
>
>
> --
>
>
> import os, sys, string, copy, time
> import getopt
> from types import *
>
> from pydal import DAL, Field
>
> db = DAL("postgres://postgres:postgres@localhost:7103/ac03303_live",
> pool_size=10, migrate_enabled=False, fake_migrate_all=True )
> print db._uri
> print db._dbname
>
>
> db.define_table('company',
> Field('company_number', type='integer'),
> Field('company_name', type='string', length=255),
> Field('address_1', type='string', length=255),
> Field('address_2', type='string', length=255),
> Field('city', type='string', length=255),
> Field('state', type='string', length=20),
> Field('zip', type='string', length=10),
> .
>
>
> *Ben Duncan*
> DBA / Chief Software Architect
> Mississippi State Supreme Court
> Electronic Filing Division
>
>
> On Tue, Feb 12, 2019 at 4:26 AM Jon Subscripted <
> jonsubscripti...@gmail.com> wrote:
>
>> Hi,
>> BTW I was checking "sql.log" file just in case I had unintentionally
>> messed up redefining the fen field twice and saw that every execution of
>> the script in my previous email led to a CREATE TABLE (see below). There's
>> more than one (one per each test I performed with the script).
>>
>> Is this normal? Should the table definition in the script outside
>> web2py-app lead to a CREATE TABLE?
>>
>> I also realized that the original CREATE TABLE statement created by
>> web2py (at the very top of the "sql.log" file, right after auth tables are
>> created) does have a different length VARCHAR( `fen` VARCHAR(512),).
>>
>> Can this kind of length difference lead to MySQL to create a duplicated
>> field?
>>
>> Thanks in advance.
>> Regards, Jon.
>>
>> timestamp: 2019-02-11T16:33:57.499000
>> CREATE TABLE problem(
>> id INT AUTO_INCREMENT NOT NULL,
>> question_hint VARCHAR(255),
>> fen VARCHAR(255),
>> solutionSAN LONGTEXT,
>> solutionUCI LONGTEXT,
>> solordered CHAR(1),
>> pcomment VARCHAR(255),
>> previousFEN VARCHAR(255),
>> previousSAN VARCHAR(255),
>> previousUCI VARCHAR(255),
>> game_control VARCHAR(255),
>> ply_control INT,
>> PRIMARY KEY(id)
>> ) ENGINE=InnoDB CHARACTER SET utf8;
>>
>> On Tue, Feb 12, 2019 at 10:49 AM Jon Subscripted <
>> jonsubscripti...@gmail.com> wrote:
>>
>>> Thanks Ben,
>>> I did what you suggested and somehow I think I moved on.
>>>
>>> Still I got a weird error: InternalError: (1060, u"Duplicate column name
>>> 'fen__tmp'")
>>>
>>> import sys
>>>
>>> sys.path.append(r'C:\Users\Jon\Downloads\web2py_src\web2py\gluon')
>>>
>>> from gluon import DAL,Field
>>> from gluon import *
>>>
>>> dbpath =
>>> r'C:\Users\Jon\Downloads\web2py_src\web2py\applications\xakemate_scratch\databases'
>>> problemsuri = 'mysql://root:web2py@localhost/xakemate'
>>> posFEN = 'rnb2rk1/pp4pp/1qpbp3/3p4/4P3/3P1NP1/PPPN1RBP/R1BQ3K b - - 0 13'
>>>
>>>
>>> db = DAL(problemsuri)#,folder=dbpath)#,auto_import=True)
>>>
>>> db.define_table(
>>> "problem",
>>> Field("question_hint",type="string"),
>>>
>>> Field("fen",type="string"),#,requires=(IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'problem.fen'))),
>>> Field("solutionSAN",type="list:string",requires=IS_NOT_EMPTY()),
>>> Field("solutionUCI",type="list:string",requires=IS_NOT_EMPTY()),
>>> Field("solordered",type="boolean",default=True),
>>> Field("pcomment",type="string"),
>>> Field("previousSAN",type="string",default=''),
>>> Field("previousUCI",type="string",default=''),
>>> Field("previousFEN",type="string",default=''),
>>> Field("game_control",type="string",default=''),
>>> Field("ply_control",type="integer",default=0)
>>> )
>>>
>>> query = (db.problem.fen == posFEN)
>>> problem = db(query).select(orderby=db.problem.id).first()
>>>
>>> No handlers could be found for logger "web2py"
>>> WARNING:root:Unable to import plural rules: No module named plural_rules
>>>
>>> Traceback (most recent call last):
>>>   File "C:\Python27\withoutdefine.py", line 27, in 
>>> Field("ply_control",type="integer",default=0)
>>>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 7085, in
>>> define_table
>>> table = self.lazy_define_table(tablename,*fields,**args)
>>>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 7117, in
>>> lazy_define_table
>>> polymodel=polymodel)
>>>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 948, in
>>> create_table
>>> fake_migrate=fake_migrate)
>>>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 1054, in
>>> migrate_table
>>> self.execute(sub_query)
>>>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 1693, in
>>> execute
>>> return self.log_execute(*a, **b)
>>>   File 

[web2py] Re: Record Versioning ON, result 'id'

2019-02-12 Thread Andy W
Have you changed the structure of the table being archived?
I have had instances in the past where I have added an extra field to my 
table and all works OK until I change a record. At that point, archiving 
fails because there is now a mismatch between the structure of the table 
and the corresponding archive_table. In this case, adding the same new 
field to the archive_table solves the issue.

Andy

On Monday, February 11, 2019 at 6:02:40 PM UTC+3, Ben Lawrence wrote:
>
> Hi
> Using Python 3.7, anyone has Record Versioning working ok?  Using 
> POSTGRESQL, error is there.
>
> http://www.web2py.com/books/default/chapter/29/09/access-control?search=versioning#Record-versioning
> Whenever I change a record under versioning, say with SQLFORM.grid(), I 
> will get a key error 'id'
> thanks for your time,
> Ben
>
> Traceback (most recent call last):
> File "/home/www-data/web2py/gluon/restricted.py", line 219, in restricted
> exec(ccode, environment)
> File "/home/www-data/web2py/applications/timecard/controllers/admin.py" 
> , line 154, 
> in 
> File "/home/www-data/web2py/gluon/globals.py", line 421, in 
> self._caller = lambda f: f()
> File "/home/www-data/web2py/gluon/tools.py", line 3867, in f
> return action(*a, **b)
> File "/home/www-data/web2py/applications/timecard/controllers/admin.py" 
> , line 18, 
> in co_accounts
> ,showbuttontext = False)
> File "/home/www-data/web2py/gluon/sqlhtml.py", line 2594, in grid
> next=referrer)
> File "/home/www-data/web2py/gluon/html.py", line 2302, in process
> self.validate(**kwargs)
> File "/home/www-data/web2py/gluon/html.py", line 2240, in validate
> if self.accepts(**kwargs):
> File "/home/www-data/web2py/gluon/sqlhtml.py", line 1973, in accepts
> self.id_field_name]).update(**fields)
> File "/home/www-data/web2py/gluon/packages/dal/pydal/objects.py", line 
> 2312, in update
> if any(f(self, row) for f in table._before_update):
> File "/home/www-data/web2py/gluon/packages/dal/pydal/objects.py", line 
> 2312, in 
> if any(f(self, row) for f in table._before_update):
> File "/home/www-data/web2py/gluon/packages/dal/pydal/objects.py", line 
> 433, in 
> archive_record(qset, fs, db[an], cn))
> File "/home/www-data/web2py/gluon/packages/dal/pydal/helpers/methods.py", 
> line 132, in archive_record
> if fields[k] != v:
> KeyError: 'id'
>
>
>

-- 
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] Re: Splitting form

2019-02-12 Thread Ben Duncan
Excuse my ignorance (Being a NEWBIE is irritating to me after having done
CS stuff for 30+ years)
But, Dave, exactly whats is turning on left-colum / right column support ?

Thanks ..


*Ben Duncan*
DBA / Chief Software Architect
Mississippi State Supreme Court
Electronic Filing Division


On Mon, Feb 11, 2019 at 4:11 PM Dave S  wrote:

>
>
> On Monday, February 11, 2019 at 9:13:48 AM UTC-8, Ben Duncan wrote:
>>
>> Ok, any ideas of how I can split my form down the middle using sqlform ?
>>
>> I need the left 50% for login input and the right  50% for a NEWS coulumn:
>>
>> ie:
>>
>> MY HEADER TOP LINE STUFF HERE
>>
>> -+
>> User ID  |
>> (a pic) NEWS
>> []
>> |Headline Next Line
>> Password
>> |--
>> []
>> |   Blah Blah Blah Blah .
>>
>> |
>>  |
>>
>> 
>>
>> ANY help is appreciated
>>
>> Thanks ...
>>
>> *Ben Duncan*
>> DBA / Chief Software Architect
>> Mississippi State Supreme Court
>> Electronic Filing Division
>>
>
> Turning on the left-column support in the example views doesn't work for
> you?
>
> (There is also right-column support, if being left isn't enough for you.)
>
> /dps
>
> --
> 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.
>

-- 
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] Accessing MySQL data without define tables

2019-02-12 Thread Ben Duncan
Here is the TOP of what I use.
You will  need the migrate commands in your connections tring

--


import os, sys, string, copy, time
import getopt
from types import *

from pydal import DAL, Field

db = DAL("postgres://postgres:postgres@localhost:7103/ac03303_live",
pool_size=10, migrate_enabled=False, fake_migrate_all=True )
print db._uri
print db._dbname


db.define_table('company',
Field('company_number', type='integer'),
Field('company_name', type='string', length=255),
Field('address_1', type='string', length=255),
Field('address_2', type='string', length=255),
Field('city', type='string', length=255),
Field('state', type='string', length=20),
Field('zip', type='string', length=10),
.


*Ben Duncan*
DBA / Chief Software Architect
Mississippi State Supreme Court
Electronic Filing Division


On Tue, Feb 12, 2019 at 4:26 AM Jon Subscripted 
wrote:

> Hi,
> BTW I was checking "sql.log" file just in case I had unintentionally
> messed up redefining the fen field twice and saw that every execution of
> the script in my previous email led to a CREATE TABLE (see below). There's
> more than one (one per each test I performed with the script).
>
> Is this normal? Should the table definition in the script outside
> web2py-app lead to a CREATE TABLE?
>
> I also realized that the original CREATE TABLE statement created by web2py
> (at the very top of the "sql.log" file, right after auth tables are
> created) does have a different length VARCHAR( `fen` VARCHAR(512),).
>
> Can this kind of length difference lead to MySQL to create a duplicated
> field?
>
> Thanks in advance.
> Regards, Jon.
>
> timestamp: 2019-02-11T16:33:57.499000
> CREATE TABLE problem(
> id INT AUTO_INCREMENT NOT NULL,
> question_hint VARCHAR(255),
> fen VARCHAR(255),
> solutionSAN LONGTEXT,
> solutionUCI LONGTEXT,
> solordered CHAR(1),
> pcomment VARCHAR(255),
> previousFEN VARCHAR(255),
> previousSAN VARCHAR(255),
> previousUCI VARCHAR(255),
> game_control VARCHAR(255),
> ply_control INT,
> PRIMARY KEY(id)
> ) ENGINE=InnoDB CHARACTER SET utf8;
>
> On Tue, Feb 12, 2019 at 10:49 AM Jon Subscripted <
> jonsubscripti...@gmail.com> wrote:
>
>> Thanks Ben,
>> I did what you suggested and somehow I think I moved on.
>>
>> Still I got a weird error: InternalError: (1060, u"Duplicate column name
>> 'fen__tmp'")
>>
>> import sys
>>
>> sys.path.append(r'C:\Users\Jon\Downloads\web2py_src\web2py\gluon')
>>
>> from gluon import DAL,Field
>> from gluon import *
>>
>> dbpath =
>> r'C:\Users\Jon\Downloads\web2py_src\web2py\applications\xakemate_scratch\databases'
>> problemsuri = 'mysql://root:web2py@localhost/xakemate'
>> posFEN = 'rnb2rk1/pp4pp/1qpbp3/3p4/4P3/3P1NP1/PPPN1RBP/R1BQ3K b - - 0 13'
>>
>>
>> db = DAL(problemsuri)#,folder=dbpath)#,auto_import=True)
>>
>> db.define_table(
>> "problem",
>> Field("question_hint",type="string"),
>>
>> Field("fen",type="string"),#,requires=(IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'problem.fen'))),
>> Field("solutionSAN",type="list:string",requires=IS_NOT_EMPTY()),
>> Field("solutionUCI",type="list:string",requires=IS_NOT_EMPTY()),
>> Field("solordered",type="boolean",default=True),
>> Field("pcomment",type="string"),
>> Field("previousSAN",type="string",default=''),
>> Field("previousUCI",type="string",default=''),
>> Field("previousFEN",type="string",default=''),
>> Field("game_control",type="string",default=''),
>> Field("ply_control",type="integer",default=0)
>> )
>>
>> query = (db.problem.fen == posFEN)
>> problem = db(query).select(orderby=db.problem.id).first()
>>
>> No handlers could be found for logger "web2py"
>> WARNING:root:Unable to import plural rules: No module named plural_rules
>>
>> Traceback (most recent call last):
>>   File "C:\Python27\withoutdefine.py", line 27, in 
>> Field("ply_control",type="integer",default=0)
>>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 7085, in
>> define_table
>> table = self.lazy_define_table(tablename,*fields,**args)
>>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 7117, in
>> lazy_define_table
>> polymodel=polymodel)
>>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 948, in
>> create_table
>> fake_migrate=fake_migrate)
>>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 1054, in
>> migrate_table
>> self.execute(sub_query)
>>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 1693, in execute
>> return self.log_execute(*a, **b)
>>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 1687, in
>> log_execute
>> ret = self.cursor.execute(*a, **b)
>>   File "C:\Python27\lib\site-packages\pymysql\cursors.py", line 170, in
>> execute
>> result = self._query(query)
>>   File "C:\Python27\lib\site-packages\pymysql\cursors.py", line 328, 

[web2py] Re: Long text internationalization

2019-02-12 Thread Leonel Câmara
Large texts are actually fine as long as they're kind of static.

For dynamic long texts I store them in a JSON field where I have a dict 
with a key for each language I want to support, I actually made a plugin 
which gives you a nice widget for this field json field which you can put 
in your modules folder and import it. I'll annex it.

Example usage:

from plugin_json_translation import TranslateWidget

def represent_lang(v, row):
if v is None:
return v
if T.accepted_language[:2] in v:
return v[LANG]
else:
return v['en']

db.define_table('my_test',
Field('body', 'json', widget=TranslateWidget().widget, requires=
IS_EMPTY_OR(IS_JSON()), represent=represent_lang),
)


Then you just need to call render when you get my_test rows and you will 
get a translated version.


-- 
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.
# -*- coding: utf-8 -*-
# author: Leonel Câmara
"""
You can also use it with plugin_ckeditor example:
db.thing.body.widget=TranslateWidget(input_widget=ckeditor.widget).widget
"""
from gluon.html import *
from gluon.sqlhtml import FormWidget
from gluon import current
import json

LANGS = ['en' , 'pt']


class TranslateWidget(FormWidget):
_class = 'string'

def __init__(self, langs=None, input_widget=None):
self.input_widget = input_widget
self.langs = langs or LANGS

def widget(self, field, value, **attributes):
"""
Generates an INPUT text tag.

see also: `FormWidget.widget`
"""

default = dict(
_type='hidden',
value=(value is not None and str(value)) or '',
)
attr = FormWidget._attributes(field, default, **attributes)

realvalue = INPUT(**attr)
_id = attr['_id']


nav_tabs = UL(
  *[LI(A(lang, **{'_href': '#' + _id + '_' + lang, '_data-toggle':'tab', '_class': 'nav-link'}), _class='nav-item') for lang in self.langs],
  _class='nav nav-tabs', _role="tablist"
  )

values = json.loads(value) if value else {lang:'' for lang in self.langs}

if self.input_widget is None:
tab_content = DIV(
*[DIV(TEXTAREA(values[lang], _name=_id + '_' + lang, _class='form-control', _placeholder=current.T('Write me...'), _rows=2), _id=_id + '_' + lang, _class='tab-pane fade') for lang in self.langs],

_class='tab-content')
else:
tab_content = DIV(_class='tab-content')
for lang in self.langs:
attributes = {'_id': _id + '_' + lang + '_widget',
  '_name':_id + '_' + lang, 
  '_placeholder':current.T('Write me...')
 }
tab_content.append(
DIV(self.input_widget(field, values[lang], **attributes), _class='tab-pane fade', _role='tabpanel', _id=_id + '_' + lang)
)


script = SCRIPT("""
$('#%(_id)s').closest('form').submit(function(){
$('#%(_id)s').val(JSON.stringify({
%(langvals)s
}));
%(removelangvals)s;
});
// This bullshit is needed for tabs with widgets using plugin simplemde
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  var target = $(e.target).attr("href") // activated tab
  window[target.substring(1) + "_widget_mde"].codemirror.refresh();
});
""" % { '_id': _id, 
'langvals': ','.join('"%s":$("[name=\'%s\']").val()' % (lang, _id + '_' + lang) for lang in self.langs), 
'removelangvals': ';'.join('$("[name=\'%s\']").remove()' % (_id + '_' + lang) for lang in self.langs)
   }
   )
nav_tabs[0][0]['_class'] +=' active'
tab_content[0]['_class'] += ' show active'
if current.request.post_vars:
# Make sure we validate our extra inputs for IS_JSON
for lang in self.langs:
name=_id + '_' + lang
current.request.post_vars[name] = '{}'
return CAT(nav_tabs, tab_content, realvalue, script)


[web2py] Long text internationalization

2019-02-12 Thread Jon Subscripted
Hi everyone,
Which is the common practice when facing long text internationalization?

For instance, What should be done when you want to render a web page,
sharing a common layout, that has several paragraphs that must be
completelly translated?

Based on the manual (
http://www.web2py.com/books/default/chapter/29/04/the-core#Internationalization-and-Pluralization-with-T
) only string constants should be used with T. My guess is that large texts
should be treated differently.

Thanks & Regards, Jon.

-- 
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] Error importing csv file in python3.6

2019-02-12 Thread Maurice Waka
When I search for an item it returns blank. However I see that the upload
to the db took place.
When I try to add data to the database, where other data was uploaded, I
get this error

1.
2.
3.
4.
5.
6.

Traceback (most recent call last):
  File "/home/mauricewaka/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
  File 
"/home/mauricewaka/web2py/applications/Hestque_Wellness/views/generic.html"
,
line 81, in 
TypeError: 'dict_values' object does not support indexing


On Mon, Feb 11, 2019 at 10:04 PM sandeep patel 
wrote:

> @Lovedie
> Can you explain a little bit more? What you mean by can't access the data?
>
> If you getting the error to import data from CSV. You can try this as well.
>
>  form = FORM(DIV(LABEL('File
> input',_for='exampleInputFile'),INPUT(_type='file',_name='csvsheet',_id="exampleInputFile"),_class='from-group'),BUTTON('Submit',_type='submit',_class="btn
> btn-primary"))
> if form.process().accepted:
> try:
> for i in
> csv.DictReader(codecs.iterdecode(request.vars.csvsheet.file,'utf-8')):
> db['table name'].insert(**i)
> except Exception as e:
> print(e)
> form.errors.csvfile = 'Invalid file format.'
>
> Thanks
> SP
>
> On Mon, Feb 11, 2019 at 11:45 PM Lovedie JC  wrote:
>
>> Works.
>> But I can't access the data.
>>
>> On Mon, 11 Feb 2019, 21:02 sandeep patel > wrote:
>>
>>> In fact, this is an open issue
>>>  for the same problem.
>>> You can check that as well
>>>
>>> On Mon, Feb 11, 2019 at 11:27 PM sandeep patel <
>>> patelsandeep...@gmail.com> wrote:
>>>
 I had the same issue. I have solved this way.
 Please try this
 You have to changing line 926 of gluon/packages/dal/pydal/objects.py
 from
 reader = csv.reader(csvfile, delimiter=delimiter,
 quotechar=quotechar, quoting=quoting)
 to
 reader = csv.reader(codecs.iterdecode(csvfile,'utf-8'),
 delimiter=delimiter,
 quotechar=quotechar, quoting=quoting)

 After changes done, you have to execute the  web2py.py

 Thanks
 SP

 On Mon, Feb 11, 2019 at 11:04 PM Maurice Waka 
 wrote:

> I shifted to web2py/python3. In python2.7 I was able to upload csv
> files but using the same code below I get an error.
> For example:
> def import_csv():
> form = FORM(INPUT(_type = 'file', _name = 'csv_file'),
>  INPUT(_type = 'submit', _value = T('Import')))
> return dict(form=form)
> @mobilize
> @auth.requires_login()
> def index1():
> if request.vars.csvfile != None:
> # set values
> table = db[request.vars.table]
> file = request.vars.csvfile.file
> # import csv file
> table.import_from_csv_file(file)
> # update who imported
> query = db.food_data.protein==""
> db(query).update(protein="")
> response.flash = 'Data uploaded'
> return dict()
>
> The error is this
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
>
> Traceback (most recent call last):
>   File "/home/mauricewaka/web2py/gluon/restricted.py", line 219, in 
> restricted
> exec(ccode, environment)
>   File 
> "/home/mauricewaka/web2py/applications/Hestque_Wellness/controllers/default.py"
>  
> ,
>  line 479, in 
>   File "/home/mauricewaka/web2py/gluon/globals.py", line 421, in 
> self._caller = lambda f: f()
>   File "/home/mauricewaka/web2py/gluon/contrib/user_agent_parser.py", 
> line 695, in __call__
> return self.func()
>   File "/home/mauricewaka/web2py/gluon/tools.py", line 3867, in f
> return action(*a, **b)
>   File 
> "/home/mauricewaka/web2py/applications/Hestque_Wellness/controllers/default.py"
>  
> ,
>  line 329, in index1
> table.import_from_csv_file(file)
>   File "/home/mauricewaka/web2py/gluon/packages/dal/pydal/objects.py", 
> line 980, in import_from_csv_file
> for lineno, line in enumerate(reader):
> _csv.Error: iterator should return strings, not bytes (did you open the 
> file in text mode?)
>
> How can I solve this
>
> --
> 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 

Re: [web2py] Accessing MySQL data without define tables

2019-02-12 Thread Jon Subscripted
Hi,
BTW I was checking "sql.log" file just in case I had unintentionally messed
up redefining the fen field twice and saw that every execution of the
script in my previous email led to a CREATE TABLE (see below). There's more
than one (one per each test I performed with the script).

Is this normal? Should the table definition in the script outside
web2py-app lead to a CREATE TABLE?

I also realized that the original CREATE TABLE statement created by web2py
(at the very top of the "sql.log" file, right after auth tables are
created) does have a different length VARCHAR( `fen` VARCHAR(512),).

Can this kind of length difference lead to MySQL to create a duplicated
field?

Thanks in advance.
Regards, Jon.

timestamp: 2019-02-11T16:33:57.499000
CREATE TABLE problem(
id INT AUTO_INCREMENT NOT NULL,
question_hint VARCHAR(255),
fen VARCHAR(255),
solutionSAN LONGTEXT,
solutionUCI LONGTEXT,
solordered CHAR(1),
pcomment VARCHAR(255),
previousFEN VARCHAR(255),
previousSAN VARCHAR(255),
previousUCI VARCHAR(255),
game_control VARCHAR(255),
ply_control INT,
PRIMARY KEY(id)
) ENGINE=InnoDB CHARACTER SET utf8;

On Tue, Feb 12, 2019 at 10:49 AM Jon Subscripted 
wrote:

> Thanks Ben,
> I did what you suggested and somehow I think I moved on.
>
> Still I got a weird error: InternalError: (1060, u"Duplicate column name
> 'fen__tmp'")
>
> import sys
>
> sys.path.append(r'C:\Users\Jon\Downloads\web2py_src\web2py\gluon')
>
> from gluon import DAL,Field
> from gluon import *
>
> dbpath =
> r'C:\Users\Jon\Downloads\web2py_src\web2py\applications\xakemate_scratch\databases'
> problemsuri = 'mysql://root:web2py@localhost/xakemate'
> posFEN = 'rnb2rk1/pp4pp/1qpbp3/3p4/4P3/3P1NP1/PPPN1RBP/R1BQ3K b - - 0 13'
>
>
> db = DAL(problemsuri)#,folder=dbpath)#,auto_import=True)
>
> db.define_table(
> "problem",
> Field("question_hint",type="string"),
>
> Field("fen",type="string"),#,requires=(IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'problem.fen'))),
> Field("solutionSAN",type="list:string",requires=IS_NOT_EMPTY()),
> Field("solutionUCI",type="list:string",requires=IS_NOT_EMPTY()),
> Field("solordered",type="boolean",default=True),
> Field("pcomment",type="string"),
> Field("previousSAN",type="string",default=''),
> Field("previousUCI",type="string",default=''),
> Field("previousFEN",type="string",default=''),
> Field("game_control",type="string",default=''),
> Field("ply_control",type="integer",default=0)
> )
>
> query = (db.problem.fen == posFEN)
> problem = db(query).select(orderby=db.problem.id).first()
>
> No handlers could be found for logger "web2py"
> WARNING:root:Unable to import plural rules: No module named plural_rules
>
> Traceback (most recent call last):
>   File "C:\Python27\withoutdefine.py", line 27, in 
> Field("ply_control",type="integer",default=0)
>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 7085, in
> define_table
> table = self.lazy_define_table(tablename,*fields,**args)
>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 7117, in
> lazy_define_table
> polymodel=polymodel)
>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 948, in
> create_table
> fake_migrate=fake_migrate)
>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 1054, in
> migrate_table
> self.execute(sub_query)
>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 1693, in execute
> return self.log_execute(*a, **b)
>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 1687, in
> log_execute
> ret = self.cursor.execute(*a, **b)
>   File "C:\Python27\lib\site-packages\pymysql\cursors.py", line 170, in
> execute
> result = self._query(query)
>   File "C:\Python27\lib\site-packages\pymysql\cursors.py", line 328, in
> _query
> conn.query(q)
>   File "C:\Python27\lib\site-packages\pymysql\connections.py", line 517,
> in query
> self._affected_rows = self._read_query_result(unbuffered=unbuffered)
>   File "C:\Python27\lib\site-packages\pymysql\connections.py", line 732,
> in _read_query_result
> result.read()
>   File "C:\Python27\lib\site-packages\pymysql\connections.py", line 1075,
> in read
> first_packet = self.connection._read_packet()
>   File "C:\Python27\lib\site-packages\pymysql\connections.py", line 684,
> in _read_packet
> packet.check_error()
>   File "C:\Python27\lib\site-packages\pymysql\protocol.py", line 220, in
> check_error
> err.raise_mysql_exception(self._data)
>   File "C:\Python27\lib\site-packages\pymysql\err.py", line 109, in
> raise_mysql_exception
> raise errorclass(errno, errval)
> InternalError: (1060, u"Duplicate column name 'fen__tmp'")
>
> I'm not aware of defining the 'fen' field twice, so I do not understande
> where did this come from.
> What does this mean?
> Regards, Jon.
>
>
> On Mon, Feb 11, 2019 at 6:08 PM Ben Duncan  wrote:
>
>> No , all you need is the db.define for the table you are going to access,
>> unless there is foreign 

Re: [web2py] Accessing MySQL data without define tables

2019-02-12 Thread Jon Subscripted
Thanks Ben,
I did what you suggested and somehow I think I moved on.

Still I got a weird error: InternalError: (1060, u"Duplicate column name
'fen__tmp'")

import sys

sys.path.append(r'C:\Users\Jon\Downloads\web2py_src\web2py\gluon')

from gluon import DAL,Field
from gluon import *

dbpath =
r'C:\Users\Jon\Downloads\web2py_src\web2py\applications\xakemate_scratch\databases'
problemsuri = 'mysql://root:web2py@localhost/xakemate'
posFEN = 'rnb2rk1/pp4pp/1qpbp3/3p4/4P3/3P1NP1/PPPN1RBP/R1BQ3K b - - 0 13'


db = DAL(problemsuri)#,folder=dbpath)#,auto_import=True)

db.define_table(
"problem",
Field("question_hint",type="string"),

Field("fen",type="string"),#,requires=(IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'problem.fen'))),
Field("solutionSAN",type="list:string",requires=IS_NOT_EMPTY()),
Field("solutionUCI",type="list:string",requires=IS_NOT_EMPTY()),
Field("solordered",type="boolean",default=True),
Field("pcomment",type="string"),
Field("previousSAN",type="string",default=''),
Field("previousUCI",type="string",default=''),
Field("previousFEN",type="string",default=''),
Field("game_control",type="string",default=''),
Field("ply_control",type="integer",default=0)
)

query = (db.problem.fen == posFEN)
problem = db(query).select(orderby=db.problem.id).first()

No handlers could be found for logger "web2py"
WARNING:root:Unable to import plural rules: No module named plural_rules

Traceback (most recent call last):
  File "C:\Python27\withoutdefine.py", line 27, in 
Field("ply_control",type="integer",default=0)
  File "C:\Python27\lib\site-packages\gluon\dal.py", line 7085, in
define_table
table = self.lazy_define_table(tablename,*fields,**args)
  File "C:\Python27\lib\site-packages\gluon\dal.py", line 7117, in
lazy_define_table
polymodel=polymodel)
  File "C:\Python27\lib\site-packages\gluon\dal.py", line 948, in
create_table
fake_migrate=fake_migrate)
  File "C:\Python27\lib\site-packages\gluon\dal.py", line 1054, in
migrate_table
self.execute(sub_query)
  File "C:\Python27\lib\site-packages\gluon\dal.py", line 1693, in execute
return self.log_execute(*a, **b)
  File "C:\Python27\lib\site-packages\gluon\dal.py", line 1687, in
log_execute
ret = self.cursor.execute(*a, **b)
  File "C:\Python27\lib\site-packages\pymysql\cursors.py", line 170, in
execute
result = self._query(query)
  File "C:\Python27\lib\site-packages\pymysql\cursors.py", line 328, in
_query
conn.query(q)
  File "C:\Python27\lib\site-packages\pymysql\connections.py", line 517, in
query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "C:\Python27\lib\site-packages\pymysql\connections.py", line 732, in
_read_query_result
result.read()
  File "C:\Python27\lib\site-packages\pymysql\connections.py", line 1075,
in read
first_packet = self.connection._read_packet()
  File "C:\Python27\lib\site-packages\pymysql\connections.py", line 684, in
_read_packet
packet.check_error()
  File "C:\Python27\lib\site-packages\pymysql\protocol.py", line 220, in
check_error
err.raise_mysql_exception(self._data)
  File "C:\Python27\lib\site-packages\pymysql\err.py", line 109, in
raise_mysql_exception
raise errorclass(errno, errval)
InternalError: (1060, u"Duplicate column name 'fen__tmp'")

I'm not aware of defining the 'fen' field twice, so I do not understande
where did this come from.
What does this mean?
Regards, Jon.


On Mon, Feb 11, 2019 at 6:08 PM Ben Duncan  wrote:

> No , all you need is the db.define for the table you are going to access,
> unless there is foreign keyes involved.
> Then include the PARENT table if these are child tables.
>
> *Ben Duncan*
> DBA / Chief Software Architect
> Mississippi State Supreme Court
> Electronic Filing Division
>
>
> On Mon, Feb 11, 2019 at 9:27 AM Jon Subscripted <
> jonsubscripti...@gmail.com> wrote:
>
>> Thanks Ben,
>> Should I include just the define_table for that very table (there are
>> more, but will not be accessed)?
>> Regards, Jon.
>>
>> On Mon, Feb 11, 2019 at 4:26 PM Ben Duncan  wrote:
>>
>>> If this script is being run OUTSIDE the web2py environment then you will
>>> need to include the define inside the python program itself.
>>>
>>> *Ben Duncan*
>>> DBA / Chief Software Architect
>>> Mississippi State Supreme Court
>>> Electronic Filing Division
>>>
>>>
>>> On Mon, Feb 11, 2019 at 9:01 AM Jon Subscripted <
>>> jonsubscripti...@gmail.com> wrote:
>>>
 Thanks Ben,
 Honestly I do not know if I understood what you suggest, sorry... it's
 actually my fault as I'm still trying to learn web2py (reading the manual,
 etc.).

 My web2py-app is actually working, but I still have lost of data to
 load in the DB. Most of the data to populate de DB is created outside the
 app itself (this may change in the future, but unfortunatelly it is like
 that now).

 As this data creation is done outside my web2py-app I wanted the
 scripts creating this data to