[web2py] Re: Migrate from sqlite to mysql

2019-02-08 Thread 黄祥

>
> - what version of mysql do I have to install to my PC where I have 2.17 
> version of web2py? Where can I find?
>
 
in windows env there are mysql and mariadb
*ref:*
https://downloads.mariadb.org
https://dev.mysql.com/downloads/mysql/

- is it necessary to install drivers or it is still included in my web2py 
> installed by windows installation method?
>

web2py already ship the mysql driver  

- what is the procedure to migrate the db of my application?
>

better to export and import in csv file

*step*:
- create database mysql
- when web2py using sqlite use export_to_csv_file()
- change db uri in private/appconfig.ini from sqlite to mysql 
- load web2py app, ensure migrate is true, so that will create the tables 
defined in web2py
- when web2py using mysql use import_from_csv_file() 

*ref:*
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Exporting-and-importing-data
 

another way around is web2py have a scripts/cpdb.py
*ref:*
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Copy-data-from-one-db-into-another

- after migrating, how to install the application using pyrhonanywhere 
> site? (I'm just using the app made with SQLite)
>

*local*
- export your database using mysqldump
- pack your app from web2py admin

*pythonanywhere*
- login to pythonanywhere, use tab console to import your mysql database
- then in web2py admin just Upload and install packed application

best regards,
stifan

-- 
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: Is there any way to preprocess a view before its rendered?

2019-02-08 Thread Alfonso Serra
This would be a solution:

At gluon/templates.py line 790, poll for "*response.parseview*" which is a 
custom function that will get the template text and return a modified one:


else:
text = filename.read()

response = context.get("response")
if response and response.parseview:
text = response.parseview(text)

text = to_native(text)
# Use the file contents to get a parsed template and return it.
return str(TemplateParser(text, context=context, path=path, lexers=
lexers, delimiters=delimiters)


Create the custom function returning text:
def js_template_fix(text):
return text.replace(r"\{{", "")

And at a controller:
def mycont():
response.parseview = fix_js_templates
return locals()

Not sure if it will work when the views are compiled, but for now this is 
good enough.
Thanks again.

-- 
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: Folder sessions

2019-02-08 Thread Dave S


On Wednesday, February 6, 2019 at 4:01:51 AM UTC-8, Константин Комков wrote:
>
> If I use first method my services was stoped and cannot be run, enother 
> method open in text editor file web2py.py. The better for me use nssm 
> becouse I can delete folder session manually(online 2 - 10 students). Stud 
> is my application name. Maybe that picture help, becouse I tried also:
>
> [image: 2.png]
>
>> c:\XXX\XXX\web2py.py -S stud -M -R c:\XXX\XXX\scripts\sessions2trash.py 
>> -A -o -x 3600 -f -v
>> pythonw.exe c:\XXX\XXX\web2py.py -S stud -M -R scripts\sessions2trash.py 
>> -A -o -x 3600 -f -v
>> pythonw.exe c:\XXX\XXX\web2py.py -S stud -M -R c:\XXX\XXX\scripts\
>> sessions2trash.py -A -o -x 3600 -f -v
>> python.exe c:\XXX\XXX\web2py.py -S stud -M -R scripts\sessions2trash.py -
>> A -o -x 3600 -f -v
>
>

For what it's worth, here's what I use on linux system, invoking it from a 
bash shell.

python web2py.py -S myapp1 -M -R scripts/sessions2trash.py -A -o -x 3600 -f 
-v



(I use this on the low-volume application.  For the trafficky application, 
I've moved a copy of sess2trash.py into it's modules folders, and follow 
the hints to call it from a scheduler routine.)

(I should look at my windows laptop at home, and see how many sessions I've 
acumulated there, but it's only local access and the sessions last long 
enough that I don't expect a problem.  I do have an issue with Chrome and 
its cache thrash, though, soaking up cycles from the Rocket server.)

/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.


[web2py] Re: Is there any way to preprocess a view before its rendered?

2019-02-08 Thread Alfonso Serra

Those are all good alternatives. ill investigate the js option but cant 
process a view with js delimiters as \{{ as they will be interepreted by 
python.

response.render is not documented but found an example at 
http://web2py.com/books/default/chapter/29/08/emails-and-sms?search=response.render#Using-the-template-system-to-generate-messages
 
easy enough to understand.

Ill read how response.render works and perhaps implement the callback 
functionality, so the view is not read twice per request. Ill post the 
solution once i have it.

I cant thank enough all the help you are offering on this forum, always 
providing quality answers.

King Regards.



-- 
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] Migrate from sqlite to mysql

2019-02-08 Thread Andrea Fae'
Hello everybody
I have some questions about an appllication I want to migrate from SQLite 
db to MySql in windows:
- what version of mysql do I have to install to my PC where I have 2.17 
version of web2py? Where can I find?
- is it necessary to install drivers or it is still included in my web2py 
installed by windows installation method?
- what is the procedure to migrate the db of my application?
- after migrating, how to install the application using pyrhonanywhere 
site? (I'm just using the app made with SQLite)
thank you for youe answers, even if you don't answer to all questions...

-- 
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: Is there any way to preprocess a view before its rendered?

2019-02-08 Thread Anthony
It's just a file, so read it in, do whatever you want with it, and then 
call response.render() with the results. A simpler approach is to see if 
you can use alternative delimiters with your JS library. If the library 
doesn't allow that, you can use alternative delimiters in the original 
code, render the view with response.render(), and then replace all the 
alternative JS delimiters in that output before returning it to the browser.

Anthony

On Friday, February 8, 2019 at 8:10:09 AM UTC-5, Alfonso Serra wrote:
>
>
> Hi.
>
> The question would be if theres any way to run a function taking a 
> composed unprocessed view as argument to return a modified one, before its 
> executed and rendered.
>
> The problem im trying to solve is because handlebars, jquery or knockout 
> js are using the same delimiters as web2py.
>
> Im aware of response.deilimiter = ("") but would like to preserve 
> web2py defaults that im used to.
>
> Example:
> A jquery template looks like:
> 
> 
    > \{{each tags}} >
  • > >
    > Edit > Delete >
    >
  • > \{{/each}} >
> > > by providing the view to a custom prepocessor i could replace > automatically the js brackets starting by "\{{" for the python counterpart > like: > {{=XML("{{")}}each tags{{=XML("}}")}} > > ... > {{=XML("{{")}}each{{=XML("}}")}} > Im my opinion, this would be a useful feature for the already wonderful > web2py templating engine. > > So yes, is there currently a way to achieve this? > > Thank you very much. > King Regards. > -- 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-08 Thread Ben Duncan
Did you set up the db_define table for the database in models.

For example, the accounting package I am working on for our Supreme Court
has and external postgres database.
>From the DDL, I've created, for example, the "ship to code" file (we reuse
for something else)
-
db.define_table('ar_ship_code',
Field('company_number', type='reference company.company_number',
ondelete='CASCADE'),
Field('code', type='string', length=10),
Field('short_desc', type='string', length=20),
Field('description', type='string', length=255),
Field('notes', type='text'),
primarykey=['company_number','code'],
migrate=False)
---

For each table you want to access, you will need a "db.define_table" entry
in the model directory.

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


On Fri, Feb 8, 2019 at 7:17 AM Jon Subscripted 
wrote:

> Hi everyone,
> I'm trying to access the data stored in my app db from a different piece
> of software (apart from my web2py app). But I get an error AttributeError.
>
> Based on the manual:
>
>
> http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Using-DAL-without-define-tables
>
> I used the code below (from IDLE):
>
> import sys
>
> sys.path.append(r'C:\Users\Jon\Downloads\web2py_src\web2py\gluon')
>
> from gluon import DAL
>
> dbpath =
> r'C:\Users\Jon\Downloads\web2py_src\web2py\applications\xakemate_scratch\databases'
> problemsuri = 'mysql://root:web2py@localhost/xakemate'
> pos = 'test_position'
>
> db = DAL(problemsuri,folder=dbpath,auto_import=True)
> query = (db.problem.fen == pos)
> problem = db(query).select(orderby=db.problem.id).first()
>
> I get the following error:
>
> Traceback (most recent call last):
>   File "", line 1, in 
> query = (dbproblems.problem.fen == posFEN)
>   File "C:\Python27\lib\site-packages\gluon\dal.py", line 7150, in
> __getattr__
> return ogetattr(self, key)
> AttributeError: 'DAL' object has no attribute 'problem'
>
> From what I understood the tables should be auto-imported and thus known
> to my code. Why is it not finding the table?
>
> In addition to that I've got a couple of questions:
>
> 1st Should I import PYDAL (from pydal import DAL)  or GLUON.DAL (as I did)?
>
> 2nd Even when using the db different from SQLite should we point to
> "applications/myapp/databases"?
>
> Thanks in advance, Jon.
>
>
> 
>  Libre
> de virus. www.avast.com
> 
> <#m_-5898545075541849496_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> --
> 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.


[web2py] Accessing MySQL data without define tables

2019-02-08 Thread Jon Subscripted
Hi everyone,
I'm trying to access the data stored in my app db from a different piece of
software (apart from my web2py app). But I get an error AttributeError.

Based on the manual:

http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Using-DAL-without-define-tables

I used the code below (from IDLE):

import sys

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

from gluon import DAL

dbpath =
r'C:\Users\Jon\Downloads\web2py_src\web2py\applications\xakemate_scratch\databases'
problemsuri = 'mysql://root:web2py@localhost/xakemate'
pos = 'test_position'

db = DAL(problemsuri,folder=dbpath,auto_import=True)
query = (db.problem.fen == pos)
problem = db(query).select(orderby=db.problem.id).first()

I get the following error:

Traceback (most recent call last):
  File "", line 1, in 
query = (dbproblems.problem.fen == posFEN)
  File "C:\Python27\lib\site-packages\gluon\dal.py", line 7150, in
__getattr__
return ogetattr(self, key)
AttributeError: 'DAL' object has no attribute 'problem'

>From what I understood the tables should be auto-imported and thus known to
my code. Why is it not finding the table?

In addition to that I've got a couple of questions:

1st Should I import PYDAL (from pydal import DAL)  or GLUON.DAL (as I did)?

2nd Even when using the db different from SQLite should we point to
"applications/myapp/databases"?

Thanks in advance, Jon.


Libre
de virus. www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

-- 
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] Is there any way to preprocess a view before its rendered?

2019-02-08 Thread Alfonso Serra

Hi.

The question would be if theres any way to run a function taking a composed 
unprocessed view as argument to return a modified one, before its executed 
and rendered.

The problem im trying to solve is because handlebars, jquery or knockout js 
are using the same delimiters as web2py.

Im aware of response.deilimiter = ("") but would like to preserve 
web2py defaults that im used to.

Example:
A jquery template looks like:




by providing the view to a custom prepocessor i could replace automatically 
the js brackets starting by "\{{" for the python counterpart like:
{{=XML("{{")}}each tags{{=XML("}}")}}

...
{{=XML("{{")}}each{{=XML("}}")}}
Im my opinion, this would be a useful feature for the already wonderful 
web2py templating engine.

So yes, is there currently a way to achieve this?

Thank you very much.
King Regards.

-- 
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.