[web2py] Re: Inserting a new field to an old table - default value is not updated correctly

2016-07-27 Thread Ykä Marjanen
Thanks Massimo! Much easier way.

Ykä

On Wednesday, July 27, 2016 at 10:24:13 AM UTC+3, Massimo Di Pierro wrote:
>
> No need for a loop just do fro the shell:
>
> db(db.persons.new_field==None).update(new_field=0)
>
> Massimo
>
> On Tuesday, 26 July 2016 10:54:19 UTC-5, Ykä Marjanen wrote:
>>
>> How should I properly initialize old rows after inserting a new field if 
>> default only updates the new rows? In my case the old rows should also work 
>> with the new field and value.
>>
>> Should I do a for loop to manually update all 'old' rows to default value 
>> after defining the new field?
>>
>> Ykä
>>
>> On Tuesday, July 26, 2016 at 5:05:54 PM UTC+3, Niphlod wrote:
>>>
>>> yep. "default" is something that gets evaluated in python at insert 
>>> time. Given it takes also a callable, it can't be translated to a proper 
>>> default constraint on the backend. When you alter the table, you should do 
>>> so ALSO considering if it's full or empty, and/or that the new column would 
>>> be meaningful only from a certain "release" onwards.
>>>
>>> tl;dr: the naming is unfortunate, but "default" doesn't translate to 
>>> anything in the backend: all the machinery is done on the python layer.
>>>
>>> On Tuesday, July 26, 2016 at 10:13:19 AM UTC+2, Ykä Marjanen wrote:
>>>>
>>>> Hi,
>>>>
>>>> I have been using Web2py for couple years now, but have not been able 
>>>> to find a decent solution to this issue.
>>>>
>>>> When creating a new web app I am constantly updating new fields to a 
>>>> database table after I already have data there. When I add a new field, I 
>>>> want it to have a default value for it, but for some reason web2py always 
>>>> has the value at None for the new field even though I have defined it to 
>>>> be 
>>>> 0.
>>>>
>>>> For example:
>>>>
>>>> db.define_table(
>>>> 'persons',
>>>>Field('old_field','integer',default=0),
>>>>Field('new_field','integer',default=0)
>>>> )
>>>>
>>>> The new_field is now updated to the table correctly, but instead of 0 
>>>> it is None for the old records.
>>>>
>>>> This is annoying as I am assuming old tables to have the new_field also 
>>>> set as 0 and now I must write code to assume None and change it manually 
>>>> to 
>>>> 0.
>>>>
>>>> Am I missing something?
>>>>
>>>> Ykä
>>>>
>>>>

-- 
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: Inserting a new field to an old table - default value is not updated correctly

2016-07-26 Thread Ykä Marjanen
How should I properly initialize old rows after inserting a new field if 
default only updates the new rows? In my case the old rows should also work 
with the new field and value.

Should I do a for loop to manually update all 'old' rows to default value 
after defining the new field?

Ykä

On Tuesday, July 26, 2016 at 5:05:54 PM UTC+3, Niphlod wrote:
>
> yep. "default" is something that gets evaluated in python at insert time. 
> Given it takes also a callable, it can't be translated to a proper default 
> constraint on the backend. When you alter the table, you should do so ALSO 
> considering if it's full or empty, and/or that the new column would be 
> meaningful only from a certain "release" onwards.
>
> tl;dr: the naming is unfortunate, but "default" doesn't translate to 
> anything in the backend: all the machinery is done on the python layer.
>
> On Tuesday, July 26, 2016 at 10:13:19 AM UTC+2, Ykä Marjanen wrote:
>>
>> Hi,
>>
>> I have been using Web2py for couple years now, but have not been able to 
>> find a decent solution to this issue.
>>
>> When creating a new web app I am constantly updating new fields to a 
>> database table after I already have data there. When I add a new field, I 
>> want it to have a default value for it, but for some reason web2py always 
>> has the value at None for the new field even though I have defined it to be 
>> 0.
>>
>> For example:
>>
>> db.define_table(
>> 'persons',
>>Field('old_field','integer',default=0),
>>Field('new_field','integer',default=0)
>> )
>>
>> The new_field is now updated to the table correctly, but instead of 0 it 
>> is None for the old records.
>>
>> This is annoying as I am assuming old tables to have the new_field also 
>> set as 0 and now I must write code to assume None and change it manually to 
>> 0.
>>
>> Am I missing something?
>>
>> Ykä
>>
>>

-- 
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] Inserting a new field to an old table - default value is not updated correctly

2016-07-26 Thread Ykä Marjanen
Hi,

I have been using Web2py for couple years now, but have not been able to 
find a decent solution to this issue.

When creating a new web app I am constantly updating new fields to a 
database table after I already have data there. When I add a new field, I 
want it to have a default value for it, but for some reason web2py always 
has the value at None for the new field even though I have defined it to be 
0.

For example:

db.define_table(
'persons',
   Field('old_field','integer',default=0),
   Field('new_field','integer',default=0)
)

The new_field is now updated to the table correctly, but instead of 0 it is 
None for the old records.

This is annoying as I am assuming old tables to have the new_field also set 
as 0 and now I must write code to assume None and change it manually to 0.

Am I missing something?

Ykä

-- 
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: Important New Year News: PyCon 2014 Tutorial

2014-05-19 Thread Ykä Marjanen
Here's the link to the video from pyvideo.org:

http://pyvideo.org/video/2558/0-to-0000-with-web2py

I think it's a good introductory video for newbies to get some insights, 
but I think Massimo's videos are better for actually learning the framework 
:)

Ykä

On Saturday, January 4, 2014 6:03:52 AM UTC+2, Massimo Di Pierro wrote:
>
> There will be a web2py tutorial at PyCon 2014.
>
> https://us.pycon.org/2014/schedule/presentation/133/
>
> Congratulations to Clifford Williams for proposing the tutorial and 
> passing the selection process.
>
>

-- 
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] Web2py Separating Controller and View Layer

2014-02-18 Thread Ykä Marjanen
Juslin, I've done it manually like in your example. Yes it's long, but gives 
full control on every field. I also define number of rows for each text box and 
have a placeholder text. Also classes and other parameters (e.g. Default 
values) are easier too define in view than in controller, so that everything is 
in one place,

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


Re: [web2py] Absolute URL issue in PythonAnywhere when using scheduled script

2014-02-15 Thread Ykä Marjanen
Thanks Marin. I did check this, but my issue is that the same links are 
generated from both a website request and the internal script. The same 
module is used also in another domain. I wouldn't like to manually change 
the domain name for each application, as the scheme=True and host=True has 
worked so well.

On Saturday, February 15, 2014 5:53:57 PM UTC+2, Marin Pranjić wrote:
>
> As explained here:
>
> http://www.web2py.com/books/default/chapter/29/04/the-core#Absolute-urls
>
>
> You should use:
>
> URL(..., scheme='http', host='www.mysite.com')
>
>
> Marin
>
>
> On Sat, Feb 15, 2014 at 4:49 PM, Ykä Marjanen 
> 
> > wrote:
>
>> I got the scheduled background script working in PA. The script is 
>> started in web2py environment with -S app and -M -R parameters. The script 
>> generates emails, which include links (e.g. registration link with UUID).
>>
>> I use scheme=True and host=True to generate absolute URL. This works when 
>> I generate the emails directly from a website request. But when the 
>> scheduled script generates it in the background, the URL has local host 
>> (127.0.0.1) and not the real domain.
>>
>> I assume that because I generate the link in a background script, web2py 
>> instance lives in the local host and doesn't "see" the outside world (like 
>> when a website request happens).
>>
>> Should I just generate the domain manually, or do I have any better way 
>> to replace the localhost with the real domain?
>>  
>> -- 
>> 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/groups/opt_out.
>>
>
>

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


[web2py] Absolute URL issue in PythonAnywhere when using scheduled script

2014-02-15 Thread Ykä Marjanen
I got the scheduled background script working in PA. The script is started 
in web2py environment with -S app and -M -R parameters. The script 
generates emails, which include links (e.g. registration link with UUID).

I use scheme=True and host=True to generate absolute URL. This works when I 
generate the emails directly from a website request. But when the scheduled 
script generates it in the background, the URL has local host (127.0.0.1) 
and not the real domain.

I assume that because I generate the link in a background script, web2py 
instance lives in the local host and doesn't "see" the outside world (like 
when a website request happens).

Should I just generate the domain manually, or do I have any better way to 
replace the localhost with the real domain?

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


[web2py] Adventures and issues with implementing scheduled background task with web2py and pythonanywhere

2014-02-15 Thread Ykä Marjanen
I've been reading and trying to figure out the best way to implement 
scheduled background tasks in PythonAnywhere. I think I understand the 
basics and challenges, but I still think I'm missing something.

I haven't found a reasonable way to use web2py scheduler directly in 
PythonAnywhere. Is it possible? When using script with my own loop, I'm 
having either issues with timeout (might take several minutes before I 
check db again) or when manually refreshing DAL with auto_import=True, the 
db variables are not imported, only table names (I have few pickle filters).

I want to have a background task, which checks the database and sends 
emails if necessary. PythonAnywhere offers min 1 hour interval for scripts, 
and my script should be more responsive (varies from 30 seconds to 15 
minutes).

Currently I've made an hourly scheduled python script, which never ends 
(while loop), checks the database and then sleep variable time, if nothing 
is found. It updates a file so that when PythonAnywhere tries to start a 
new process again (hourly), it will not start another instance as the 
previous script is still ok. 

This works fine and I use the web2py environment to load all model 
information and so on (e.g. python web2py.py -S app -M -R 
applications\app\modules\script.py). But that command loads the models only 
once and if I sleep 15 minutes, the db connection is lost. I tried to 
search if web2py has something like db.reconnect() by could'nt found 
anything.

P.s. I do have to say that PythonAnywhere rocks for a small developer like 
my (as well as we2py).

Ykä

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


[web2py] Re: Can you help me test this project of mine?

2013-12-12 Thread Ykä Marjanen
Looks promising. I can test this next week. I will implement an email 
reminder service and compare it with using own scheduler in Pythonanywhere.

Ykä

On Thursday, December 12, 2013 5:05:40 AM UTC+2, Massimo Di Pierro wrote:
>
> Should be self-explanatory:
>
> http://callme.experts4solutions.com/
>
> Massimo
>
>

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


[web2py] Re: Online classes

2013-12-03 Thread Ykä Marjanen
Thanks Massimo! Even though I already have the basic knowledge of web2py 
this is a great way to recap.

Ykä

On Tuesday, December 3, 2013 8:34:18 AM UTC+2, Massimo Di Pierro wrote:
>
> Hello everybody,
>
> As you know I teach a certification program about web development with 
> Python and I use web2py. 
> I posted my most recent classes online:
>
> https://vimeo.com/75499986
> https://vimeo.com/76047107
> https://vimeo.com/76608898
> https://vimeo.com/77179700
> https://vimeo.com/77654974
>
> It is about of 13 hours of web2py lessons and coding.
> Please join me in thanking the students who enrolled in the program and 
> supported these classes.
>
> Massimo
>

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


[web2py] Re: Model and Controller with Web2Py, View with Excel ??

2013-11-28 Thread Ykä Marjanen
I don't think you can use a web based application without a server. 
However, the local server is already there without additional installation, 
so if you want an application that has a browser interface, then you don't 
need to do any extra.

You can use the webpy current architecture directly and just generate the 
excel file in a controller and pass it to view (or generate it in the 
view). I think you can even view/edit the xls file in the browser with a 
browser plugin, or then let it automatically open the results in excel.

I think you can use DAL in your local script without server and do the 
controller-part also in normal Python functions, but then you wouldn't have 
browser UI or web support.

Ykä

On Wednesday, November 27, 2013 6:22:25 PM UTC+2, Py Dev wrote:
>
> Hi,
>
> the combination web2py-DAL with python code (controller) and Excel to 
> manipulate and chart table data would be wonderful.
>
> That would mean rapid prototyping with a lot of databases and the option 
> to go to web later.
>
> So, is it possible to use „only“ the model and controller level from 
> web2py and use Mircosoft Excel as view with for example pyxll or datanitro?
>
> (see http://www.pyxll.com  and https://datanitro.com )
>
> Is it possible to use web2py-DAL locally without a webserver?
>
> Would it be possible to use a debugger with this combination?
>
> Cheers!
>
> pd
>

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


[web2py] Re: auth.messages.verify_email html template

2013-10-27 Thread Ykä Marjanen
I have replaced the standard verification with my own. The standard 
authentication is pretty simple as it creates a unique key, which it stores in 
the database and sends as a link to the registrant. When the link is clicked it 
will match the registration details with the unique id and stores (accepts the 
user) them.

This way you can customize the template and use email API (json), which is much 
more powerful than smtp method (I use mailgun).

Ykä

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


[web2py] How Do You Choose Frameworks That Will Survive?

2013-10-25 Thread Ykä Marjanen
First choose a language as it has a longetivity beyond a framework (i.e. 
Python). Then choose a framework which meets your needs and start using it. I 
dont think long analysis will do any good as it is not that difficult to learn 
and adapt to another framework (especially python).

I've done most of the website logic in a class which has API to web2py, for 
easy switch to another framework.

Althought I have to say that I find no reason to look any other frameworks. 
However frameworks come and go and you have to adapt and switch sooner or 
later, so just start using one.

Ykä

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


Re: [web2py] Bootstrap 2.2.2 / 2.3.2

2013-10-22 Thread Ykä Marjanen
I'm with Niphlod on moving this to developers forum.

As a newbie on front end framework and implementing it to web2py, here are 
some issues/topics I went through:

1) How layout.html works and can be changed
2) What are the additional web2py ajax and js functions and which ones I 
need and which ones I can replace
3) How to customize forms and add new classes to them (this has several 
ways to do it)

I think I have now some idea of these and have been able to implement 
bootstrap 3 pretty well. However, it was pain to find the necessary 
information from the manual, this forum, google and so on. The information 
is in the manual, but for me it was not easy to find.

So maybe we should have one section in the manual for "implementing a front 
end framework to web2py", which would cover all aspects. And maybe improve 
some parts of the code to make it easier to customize (I'm not sure if this 
is even needed).

Ykä

On Tuesday, October 22, 2013 12:19:04 AM UTC+3, Niphlod wrote:
>
> PR sent for 2.3.2 .
>
> PS: maybe we should move the discussion to web2py-developers on the plans 
> to easy up working with new css frameworks and web2py
>
> On Monday, October 21, 2013 10:55:34 PM UTC+2, Paolo Caruccio wrote:
>>
>> twbs versions after the 2.2.2 up to 2.3.2 did not introduce significant 
>> changes. Version 3.0, instead, is a revolution. We can say that is a 
>> different framework. Consequently, although it is easy to create a layout 
>> based on twbs 3.0, it is complicated to adjust some components that are 
>> pre-built in web2py such as forms and grids to name the main ones.
>> In a previous 
>> discussionNiphlod
>>  and Anthony had suggested to create a file in gluon/contrib.
>> Personally, I started to write some code in a module but it's at an early 
>> stage. I do not know if anyone else is working on this.
>>
>> Edit: I forgot the most important thing +1 to 2.3.2
>>
>>
>> Il giorno lunedì 21 ottobre 2013 21:58:06 UTC+2, Niphlod ha scritto:
>>>
>>> Need to change all widgets to pass to bootstrap3. I remember someone 
>>> working on itbut of course it's keeping for himself :-P
>>>
>>> Before doing that (pass to 3), we should figure out:
>>> - something to set all methods for formstyle to be homogeneous among all 
>>> the app
>>> - a contrib "way" to make module for formstyles and widgets
>>>
>>> Passing from 2.2.2 to 2.3.2 is harmless, at least for my apps.
>>>
>>> On Monday, October 21, 2013 9:29:38 PM UTC+2, Massimo Di Pierro wrote:

 If somebody sends me a git pull request, I will apply it but shouldn't 
 we jump to bootstrap 3?



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


Re: [web2py] Bootstrap 2.2.2 / 2.3.2

2013-10-21 Thread Ykä Marjanen
I would vote for bootstrap 3 as it is simpler to implement and use.

With the current guidance and the layout template it is pretty easy to 
customize to any framework already. So I would only focus on improving the 
documentation, especially for customizing the forms and errors.

Then people can choose any front end framework.

Ykä

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


[web2py] Re: Issue with switching to mysql from sqlite in Pythonanywhere (table not created)

2013-10-14 Thread Ykä Marjanen
Thanks Niphlod,

I've been happily using SQLite for testing and smaller projects, so 
switching to MySQL was a new thing (I'd like to use PostgreSQL in the 
future). I was expecting it to work by just switching the initialization 
line, as it was working fine with SQLite. But I learned new stuff, again.

Ykä

On Sunday, October 13, 2013 9:42:50 PM UTC+3, Niphlod wrote:
>
> mysql has a very known problem of not handling unique keys longer than 255 
> chars. 
> As specified in the book and as a best practice, ALWAYS specify a length 
> for 'string' fields. In the case of mysql, if those fields are unique, the 
> maximum length is 255.
>
> On the other issue (creating the referencing table before the referenced 
> one): seems impossible to let users digest this fact (seems pretty obvious 
> to me), but you CAN'T (in ANY serious backend) specify a relationship 
> towards something that doesn't exist.
> SQLite has no referential integrity turned on by default, so it skips the 
> issue entirely. Remember, SQLite is a wonderful db but is tiny and has its 
> own limitations.
>
>
> On Sunday, October 13, 2013 6:36:16 PM UTC+2, Ykä Marjanen wrote:
>>
>> I got everything working, when I moved the table order so that all tables 
>> that are referenced later are at the beginning.
>>
>> Additionally I had to declare the "unique" value after creating the 
>> table, so:
>>
>> Not working:
>> db.define_table('tablename',Field('name',unique=True)
>>
>> Working:
>> db.define_table('tablename',Field('name')
>> db.tablename.name.unique = True
>>
>> Is this correct behavior?
>>
>> Ykä
>>
>> On Sunday, October 13, 2013 4:54:30 PM UTC+3, Niphlod wrote:
>>>
>>> there is no path2 field in the models you posted. are you sure that this 
>>> is the correct traceback ?
>>> BTW, try to issue the create statement to the db to see what is the 
>>> error, eventually trimming out the column that are references to external 
>>> tables.
>>>
>>> On Sunday, October 13, 2013 3:00:57 PM UTC+2, Ykä Marjanen wrote:
>>>>
>>>> And the resulting ticket:
>>>>
>>>> Error ticket for "innopinion_01" Ticket ID 
>>>>
>>>> 91.155.41.52.2013-10-13.12-54-52.7a8f0165-58f8-4ca8-960a-7fdcdc40d788
>>>>  (1005, "Can't create table 
>>>> 'ykamarjanen$dbname.campaign' (errno: 150)") Version  web2py™ Version 
>>>> 2.6.4-stable+timestamp.2013.09.22.01.43.37  Traceback 
>>>>
>>>> 1.
>>>> 2.
>>>> 3.
>>>> 4.
>>>> 5.
>>>> 6.
>>>> 7.
>>>> 8.
>>>> 9.
>>>> 10.
>>>> 11.
>>>> 12.
>>>> 13.
>>>> 14.
>>>> 15.
>>>> 16.
>>>> 17.
>>>> 18.
>>>> 19.
>>>> 20.
>>>> 21.
>>>> 22.
>>>> 23.
>>>>
>>>> Traceback (most recent call last):
>>>>   File "/home/ykamarjanen/web2py/gluon/restricted.py", line 217, in 
>>>> restricted
>>>> exec ccode in environment
>>>>   File "/home/ykamarjanen/web2py/applications/innopinion_01/models/db.py" 
>>>> <https://ykamarjanen.pythonanywhere.com/admin/edit/innopinion_01/models/db.py>,
>>>>  line 114, in 
>>>> Field('path2','text', filter_in=(lambda x: pickle.dumps(x)), 
>>>> filter_out=(lambda s: s and pickle.loads(s)),default=None, readable=False, 
>>>> writable=False))
>>>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 7895, in define_table
>>>> table = self.lazy_define_table(tablename,*fields,**args)
>>>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 7932, in 
>>>> lazy_define_table
>>>> polymodel=polymodel)
>>>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 1002, in create_table
>>>> self.create_sequence_and_triggers(query,table)
>>>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 1816, in 
>>>> create_sequence_and_triggers
>>>> self.execute(query)
>>>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 1833, in execute
>>>> return self.log_execute(*a, **b)
>>>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 1827, in log_execute
>>>> ret = self.cursor.execu

[web2py] Re: Issue with switching to mysql from sqlite in Pythonanywhere (table not created)

2013-10-13 Thread Ykä Marjanen
I got everything working, when I moved the table order so that all tables 
that are referenced later are at the beginning.

Additionally I had to declare the "unique" value after creating the table, 
so:

Not working:
db.define_table('tablename',Field('name',unique=True)

Working:
db.define_table('tablename',Field('name')
db.tablename.name.unique = True

Is this correct behavior?

Ykä

On Sunday, October 13, 2013 4:54:30 PM UTC+3, Niphlod wrote:
>
> there is no path2 field in the models you posted. are you sure that this 
> is the correct traceback ?
> BTW, try to issue the create statement to the db to see what is the error, 
> eventually trimming out the column that are references to external tables.
>
> On Sunday, October 13, 2013 3:00:57 PM UTC+2, Ykä Marjanen wrote:
>>
>> And the resulting ticket:
>>
>> Error ticket for "innopinion_01" Ticket ID 
>>
>> 91.155.41.52.2013-10-13.12-54-52.7a8f0165-58f8-4ca8-960a-7fdcdc40d788
>>  (1005, "Can't create table 
>> 'ykamarjanen$dbname.campaign' (errno: 150)") Version  web2py™ Version 
>> 2.6.4-stable+timestamp.2013.09.22.01.43.37  Traceback 
>>
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>> 10.
>> 11.
>> 12.
>> 13.
>> 14.
>> 15.
>> 16.
>> 17.
>> 18.
>> 19.
>> 20.
>> 21.
>> 22.
>> 23.
>>
>> Traceback (most recent call last):
>>   File "/home/ykamarjanen/web2py/gluon/restricted.py", line 217, in 
>> restricted
>> exec ccode in environment
>>   File "/home/ykamarjanen/web2py/applications/innopinion_01/models/db.py" 
>> <https://ykamarjanen.pythonanywhere.com/admin/edit/innopinion_01/models/db.py>,
>>  line 114, in 
>> Field('path2','text', filter_in=(lambda x: pickle.dumps(x)), 
>> filter_out=(lambda s: s and pickle.loads(s)),default=None, readable=False, 
>> writable=False))
>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 7895, in define_table
>> table = self.lazy_define_table(tablename,*fields,**args)
>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 7932, in 
>> lazy_define_table
>> polymodel=polymodel)
>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 1002, in create_table
>> self.create_sequence_and_triggers(query,table)
>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 1816, in 
>> create_sequence_and_triggers
>> self.execute(query)
>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 1833, in execute
>> return self.log_execute(*a, **b)
>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 1827, in log_execute
>> ret = self.cursor.execute(command, *a[1:], **b)
>>   File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 
>> 201, in execute
>> self.errorhandler(self, exc, value)
>>   File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 
>> 36, in defaulterrorhandler
>> raise errorclass, errorvalue
>> OperationalError: (1005, "Can't create table 'ykamarjanen$dbname.campaign' 
>> (errno: 150)")
>>
>>
>>
>> On Sunday, October 13, 2013 3:59:08 PM UTC+3, Ykä Marjanen wrote:
>>>
>>> Niphlod,
>>>
>>> this is the log. The test table, that I created, passes fine, but the 
>>> "campaign" table doesn't say "success". Is it about the FOREIGN KEY?
>>>
>>> <<<<< sql.log
>>> timestamp: 2013-10-13T12:23:25.789598
>>> CREATE TABLE tests(
>>> id INTEGER PRIMARY KEY AUTOINCREMENT,
>>> auth_table INTEGER REFERENCES auth_user (id) ON DELETE CASCADE,
>>> path2 TEXT
>>> );
>>> success!
>>> timestamp: 2013-10-13T12:29:03.020292
>>> CREATE TABLE campaign(
>>> id INT AUTO_INCREMENT NOT NULL,
>>> uuid VARCHAR(64),
>>> name VARCHAR(512),
>>> pagename VARCHAR(512),
>>> description LONGTEXT,
>>> created_by_auth INT, INDEX created_by_auth__idx (created_by_auth), 
>>> FOREIGN KEY (created_by_auth) REFERENCES auth_user (id) ON DELETE CASCADE,
>>> created_by_participant INT, INDEX created_by_participant__idx 
>>> (created_by_participant), FOREIGN KEY (created_by_participant) REFERENCES 
>>> participant (id) ON DELETE CASCADE,
>>> cctype VARCHAR(512),
>>> privacy VARCHAR(512)

[web2py] Re: Issue with switching to mysql from sqlite in Pythonanywhere (table not created)

2013-10-13 Thread Ykä Marjanen
I checked every line of the table creation, and have found the following 
issues:

1) When using a reference to another table ('reference participant'), that 
table has to be created before the referenced table. This was not a problem 
with sqlite.
2) When using unique=True (e.g. Field('email',unique=True)) it will 
complain about "Specified key was too long, max key..."

Am I missing something or is this correct behavior?

On Sunday, October 13, 2013 4:54:30 PM UTC+3, Niphlod wrote:
>
> there is no path2 field in the models you posted. are you sure that this 
> is the correct traceback ?
> BTW, try to issue the create statement to the db to see what is the error, 
> eventually trimming out the column that are references to external tables.
>
> On Sunday, October 13, 2013 3:00:57 PM UTC+2, Ykä Marjanen wrote:
>>
>> And the resulting ticket:
>>
>> Error ticket for "innopinion_01" Ticket ID 
>>
>> 91.155.41.52.2013-10-13.12-54-52.7a8f0165-58f8-4ca8-960a-7fdcdc40d788
>>  (1005, "Can't create table 
>> 'ykamarjanen$dbname.campaign' (errno: 150)") Version  web2py™ Version 
>> 2.6.4-stable+timestamp.2013.09.22.01.43.37  Traceback 
>>
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>> 10.
>> 11.
>> 12.
>> 13.
>> 14.
>> 15.
>> 16.
>> 17.
>> 18.
>> 19.
>> 20.
>> 21.
>> 22.
>> 23.
>>
>> Traceback (most recent call last):
>>   File "/home/ykamarjanen/web2py/gluon/restricted.py", line 217, in 
>> restricted
>> exec ccode in environment
>>   File "/home/ykamarjanen/web2py/applications/innopinion_01/models/db.py" 
>> <https://ykamarjanen.pythonanywhere.com/admin/edit/innopinion_01/models/db.py>,
>>  line 114, in 
>> Field('path2','text', filter_in=(lambda x: pickle.dumps(x)), 
>> filter_out=(lambda s: s and pickle.loads(s)),default=None, readable=False, 
>> writable=False))
>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 7895, in define_table
>> table = self.lazy_define_table(tablename,*fields,**args)
>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 7932, in 
>> lazy_define_table
>> polymodel=polymodel)
>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 1002, in create_table
>> self.create_sequence_and_triggers(query,table)
>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 1816, in 
>> create_sequence_and_triggers
>> self.execute(query)
>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 1833, in execute
>> return self.log_execute(*a, **b)
>>   File "/home/ykamarjanen/web2py/gluon/dal.py", line 1827, in log_execute
>> ret = self.cursor.execute(command, *a[1:], **b)
>>   File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 
>> 201, in execute
>> self.errorhandler(self, exc, value)
>>   File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 
>> 36, in defaulterrorhandler
>> raise errorclass, errorvalue
>> OperationalError: (1005, "Can't create table 'ykamarjanen$dbname.campaign' 
>> (errno: 150)")
>>
>>
>>
>> On Sunday, October 13, 2013 3:59:08 PM UTC+3, Ykä Marjanen wrote:
>>>
>>> Niphlod,
>>>
>>> this is the log. The test table, that I created, passes fine, but the 
>>> "campaign" table doesn't say "success". Is it about the FOREIGN KEY?
>>>
>>> <<<<< sql.log
>>> timestamp: 2013-10-13T12:23:25.789598
>>> CREATE TABLE tests(
>>> id INTEGER PRIMARY KEY AUTOINCREMENT,
>>> auth_table INTEGER REFERENCES auth_user (id) ON DELETE CASCADE,
>>> path2 TEXT
>>> );
>>> success!
>>> timestamp: 2013-10-13T12:29:03.020292
>>> CREATE TABLE campaign(
>>> id INT AUTO_INCREMENT NOT NULL,
>>> uuid VARCHAR(64),
>>> name VARCHAR(512),
>>> pagename VARCHAR(512),
>>> description LONGTEXT,
>>> created_by_auth INT, INDEX created_by_auth__idx (created_by_auth), 
>>> FOREIGN KEY (created_by_auth) REFERENCES auth_user (id) ON DELETE CASCADE,
>>> created_by_participant INT, INDEX created_by_participant__idx 
>>> (created_by_participant), FOREIGN KEY (created_by_participant) REFERENCES 
>>> participant (id) ON DELETE CASCADE,
>>> cctype VARCHAR(512),
>>>  

[web2py] Re: Issue with switching to mysql from sqlite in Pythonanywhere (table not created)

2013-10-13 Thread Ykä Marjanen
And the resulting ticket:

Error ticket for "innopinion_01" Ticket ID 

91.155.41.52.2013-10-13.12-54-52.7a8f0165-58f8-4ca8-960a-7fdcdc40d788
 (1005, "Can't create table 
'ykamarjanen$dbname.campaign' (errno: 150)") Version  web2py™ Version 
2.6.4-stable+timestamp.2013.09.22.01.43.37  Traceback 

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.

Traceback (most recent call last):
  File "/home/ykamarjanen/web2py/gluon/restricted.py", line 217, in restricted
exec ccode in environment
  File "/home/ykamarjanen/web2py/applications/innopinion_01/models/db.py" 
<https://ykamarjanen.pythonanywhere.com/admin/edit/innopinion_01/models/db.py>, 
line 114, in 
Field('path2','text', filter_in=(lambda x: pickle.dumps(x)), 
filter_out=(lambda s: s and pickle.loads(s)),default=None, readable=False, 
writable=False))
  File "/home/ykamarjanen/web2py/gluon/dal.py", line 7895, in define_table
table = self.lazy_define_table(tablename,*fields,**args)
  File "/home/ykamarjanen/web2py/gluon/dal.py", line 7932, in lazy_define_table
polymodel=polymodel)
  File "/home/ykamarjanen/web2py/gluon/dal.py", line 1002, in create_table
self.create_sequence_and_triggers(query,table)
  File "/home/ykamarjanen/web2py/gluon/dal.py", line 1816, in 
create_sequence_and_triggers
self.execute(query)
  File "/home/ykamarjanen/web2py/gluon/dal.py", line 1833, in execute
return self.log_execute(*a, **b)
  File "/home/ykamarjanen/web2py/gluon/dal.py", line 1827, in log_execute
ret = self.cursor.execute(command, *a[1:], **b)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 201, 
in execute
self.errorhandler(self, exc, value)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 
36, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1005, "Can't create table 'ykamarjanen$dbname.campaign' 
(errno: 150)")



On Sunday, October 13, 2013 3:59:08 PM UTC+3, Ykä Marjanen wrote:
>
> Niphlod,
>
> this is the log. The test table, that I created, passes fine, but the 
> "campaign" table doesn't say "success". Is it about the FOREIGN KEY?
>
> <<<<< sql.log
> timestamp: 2013-10-13T12:23:25.789598
> CREATE TABLE tests(
> id INTEGER PRIMARY KEY AUTOINCREMENT,
> auth_table INTEGER REFERENCES auth_user (id) ON DELETE CASCADE,
> path2 TEXT
> );
> success!
> timestamp: 2013-10-13T12:29:03.020292
> CREATE TABLE campaign(
> id INT AUTO_INCREMENT NOT NULL,
> uuid VARCHAR(64),
> name VARCHAR(512),
> pagename VARCHAR(512),
> description LONGTEXT,
> created_by_auth INT, INDEX created_by_auth__idx (created_by_auth), 
> FOREIGN KEY (created_by_auth) REFERENCES auth_user (id) ON DELETE CASCADE,
> created_by_participant INT, INDEX created_by_participant__idx 
> (created_by_participant), FOREIGN KEY (created_by_participant) REFERENCES 
> participant (id) ON DELETE CASCADE,
> cctype VARCHAR(512),
> privacy VARCHAR(512),
> registration VARCHAR(512),
> idea_submit VARCHAR(512),
> campaign_logo VARCHAR(512),
> campaign_start DATE,
> campaign_end DATE,
> creation_date DATETIME,
> twitter_feed CHAR(1),
> weekly_newsletter VARCHAR(512),
> weekly_contributor_status CHAR(1),
> weekly_contributor_nro INT,
> weekly_contributor_prize_description LONGTEXT,
> overall_contributor_status CHAR(1),
> overall_contributor_nro INT,
> overall_contributor_prize_description LONGTEXT,
> registered_participant_status CHAR(1),
> registered_participant_tasks INT,
> registered_participant_description LONGTEXT,
> free_prize_description LONGTEXT,
> status VARCHAR(512),
> nro_of_participants INT,
> nro_of_ideas INT,
> nro_of_ratings INT,
> nro_of_comments INT,
> additional_settings LONGTEXT,
> credits_settings LONGTEXT,
> rating_settings LONGTEXT,
> process_settings LONGTEXT,
> cpath LONGTEXT,
> PRIMARY KEY(id)
> ) ENGINE=InnoDB CHARACTER SET utf8;
>
> Ykä
>
> On Sunday, October 13, 2013 3:47:36 PM UTC+3, Niphlod wrote:
>>
>> inspect databases/sql.log, there are the statements used to create the 
>> table there
>>
>> On Sunday, October 13, 2013 2:42:03 PM UTC+2, Ykä Marjanen wrote:
>>>
>>> Hi guys,
>>>
>>> I thought of using pythonanywhere for the next level of development, so 
>>> deployed my code there. I had been using sqlite as a test environment, and 
>>> wanted to move to the mysql database that pythonanywher

[web2py] Re: Issue with switching to mysql from sqlite in Pythonanywhere (table not created)

2013-10-13 Thread Ykä Marjanen
Niphlod,

this is the log. The test table, that I created, passes fine, but the 
"campaign" table doesn't say "success". Is it about the FOREIGN KEY?

<<<<< sql.log
timestamp: 2013-10-13T12:23:25.789598
CREATE TABLE tests(
id INTEGER PRIMARY KEY AUTOINCREMENT,
auth_table INTEGER REFERENCES auth_user (id) ON DELETE CASCADE,
path2 TEXT
);
success!
timestamp: 2013-10-13T12:29:03.020292
CREATE TABLE campaign(
id INT AUTO_INCREMENT NOT NULL,
uuid VARCHAR(64),
name VARCHAR(512),
pagename VARCHAR(512),
description LONGTEXT,
created_by_auth INT, INDEX created_by_auth__idx (created_by_auth), 
FOREIGN KEY (created_by_auth) REFERENCES auth_user (id) ON DELETE CASCADE,
created_by_participant INT, INDEX created_by_participant__idx 
(created_by_participant), FOREIGN KEY (created_by_participant) REFERENCES 
participant (id) ON DELETE CASCADE,
cctype VARCHAR(512),
privacy VARCHAR(512),
registration VARCHAR(512),
idea_submit VARCHAR(512),
campaign_logo VARCHAR(512),
campaign_start DATE,
campaign_end DATE,
creation_date DATETIME,
twitter_feed CHAR(1),
weekly_newsletter VARCHAR(512),
weekly_contributor_status CHAR(1),
weekly_contributor_nro INT,
weekly_contributor_prize_description LONGTEXT,
overall_contributor_status CHAR(1),
overall_contributor_nro INT,
overall_contributor_prize_description LONGTEXT,
registered_participant_status CHAR(1),
registered_participant_tasks INT,
registered_participant_description LONGTEXT,
free_prize_description LONGTEXT,
status VARCHAR(512),
nro_of_participants INT,
nro_of_ideas INT,
nro_of_ratings INT,
nro_of_comments INT,
additional_settings LONGTEXT,
credits_settings LONGTEXT,
rating_settings LONGTEXT,
process_settings LONGTEXT,
cpath LONGTEXT,
PRIMARY KEY(id)
) ENGINE=InnoDB CHARACTER SET utf8;

Ykä

On Sunday, October 13, 2013 3:47:36 PM UTC+3, Niphlod wrote:
>
> inspect databases/sql.log, there are the statements used to create the 
> table there
>
> On Sunday, October 13, 2013 2:42:03 PM UTC+2, Ykä Marjanen wrote:
>>
>> Hi guys,
>>
>> I thought of using pythonanywhere for the next level of development, so 
>> deployed my code there. I had been using sqlite as a test environment, and 
>> wanted to move to the mysql database that pythonanywhere provides.
>>
>> I created a new mysql database and then switched the DAL connection to:
>> db = 
>> DAL('mysql://ykamarjanen:PASS@mysql.server/ykamarjanen$DBNAME',pool_size=1,check_reserved=['all'])
>>
>> After running the web2py I got an error about the database (1005, can't 
>> create table, errno:150). I tried different variations, but could figure 
>> out what is wrong with my table. 
>>
>> Here's my table, that is not created (it has some reserved names, which I 
>> changed):
>>
>> db.define_table('campaign',
>> Field('uuid', length=64, default=lambda:str(uuid4())),
>> Field('name'),
>> Field('pagename'),
>> Field('description','text', requires=IS_LENGTH(minsize=20, 
>> maxsize=500)),
>> Field('created_by_auth','reference auth_user', default=auth.user_id, 
>> readable=False, writable=False),
>> Field('created_by_participant','reference participant', 
>> readable=False, writable=False),
>> Field('campaign_type', readable=False, writable=False),
>> Field('privacy',requires=IS_IN_SET(['open','closed'],zero=T('Choose 
>> privacy')),default='open'),
>> 
>> Field('registration',requires=IS_IN_SET(['open','invitation'],zero=T('Choose 
>> registration')),default='open'),
>> 
>> Field('idea_submit',requires=IS_IN_SET(['anonymous','registered'],zero=T('Choose
>>  
>> how ideas can be sent')),default='anonymous'),
>> Field('campaign_logo',requires=IS_EMPTY_OR(IS_URL())),
>> Field('campaign_start','date',requires=IS_DATE(),default=request.now),
>> Field('campaign_end','date',requires=IS_DATE()),
>> Field('creation_date','datetime',default=request.now),
>> Field('twitter_feed','boolean',default=False),
>> 
>> Field('weekly_newsletter',requires=IS_IN_SET(['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],zero=T('Pick
>>  
&g

[web2py] Issue with switching to mysql from sqlite in Pythonanywhere (table not created)

2013-10-13 Thread Ykä Marjanen
Hi guys,

I thought of using pythonanywhere for the next level of development, so 
deployed my code there. I had been using sqlite as a test environment, and 
wanted to move to the mysql database that pythonanywhere provides.

I created a new mysql database and then switched the DAL connection to:
db = 
DAL('mysql://ykamarjanen:PASS@mysql.server/ykamarjanen$DBNAME',pool_size=1,check_reserved=['all'])

After running the web2py I got an error about the database (1005, can't 
create table, errno:150). I tried different variations, but could figure 
out what is wrong with my table. 

Here's my table, that is not created (it has some reserved names, which I 
changed):

db.define_table('campaign',
Field('uuid', length=64, default=lambda:str(uuid4())),
Field('name'),
Field('pagename'),
Field('description','text', requires=IS_LENGTH(minsize=20, 
maxsize=500)),
Field('created_by_auth','reference auth_user', default=auth.user_id, 
readable=False, writable=False),
Field('created_by_participant','reference participant', readable=False, 
writable=False),
Field('campaign_type', readable=False, writable=False),
Field('privacy',requires=IS_IN_SET(['open','closed'],zero=T('Choose 
privacy')),default='open'),

Field('registration',requires=IS_IN_SET(['open','invitation'],zero=T('Choose 
registration')),default='open'),

Field('idea_submit',requires=IS_IN_SET(['anonymous','registered'],zero=T('Choose
 
how ideas can be sent')),default='anonymous'),
Field('campaign_logo',requires=IS_EMPTY_OR(IS_URL())),
Field('campaign_start','date',requires=IS_DATE(),default=request.now),
Field('campaign_end','date',requires=IS_DATE()),
Field('creation_date','datetime',default=request.now),
Field('twitter_feed','boolean',default=False),

Field('weekly_newsletter',requires=IS_IN_SET(['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],zero=T('Pick
 
a day for newsletter')),default='Monday'),
Field('weekly_contributor_status','boolean',default=True),

Field('weekly_contributor_nro','integer',requires=IS_IN_SET(range(0,20),zero=T('Select
 
the number of participants included in the raffle'))),
Field('weekly_contributor_prize_description','text'),
Field('overall_contributor_status','boolean',default=True),

Field('overall_contributor_nro','integer',requires=IS_IN_SET(range(0,20),zero=T('Select
 
the number of participants included in the raffle'))),
Field('overall_contributor_prize_description','text'),
Field('registered_participant_status','boolean',default=True),

Field('registered_participant_tasks','integer',requires=IS_IN_SET(range(0,20),zero=T('Select
 
the number of minimum tasks for the prize raffle'))),
Field('registered_participant_description','text'),
Field('free_prize_description','text'),
Field('status', 
requires=IS_IN_SET(['waiting','running','halted','ended']), readable=False, 
writable=False), #waiting, running, halted, ended
Field('nro_of_participants','integer',default=0, readable=False, 
writable=False),
Field('nro_of_ideas','integer',default=0, readable=False, 
writable=False),
Field('nro_of_ratings','integer',default=0, readable=False, 
writable=False),
Field('nro_of_comments','integer',default=0, readable=False, 
writable=False),
Field('additional_settings','text', filter_in=(lambda x: 
pickle.dumps(x)), filter_out=(lambda s: s and 
pickle.loads(s)),default=None, readable=False, writable=False),
Field('credits_settings','text', filter_in=(lambda x: pickle.dumps(x)), 
filter_out=(lambda s: s and pickle.loads(s)),default=None, readable=False, 
writable=False),
Field('rating_settings','text', filter_in=(lambda x: pickle.dumps(x)), 
filter_out=(lambda s: s and pickle.loads(s)),default=None, readable=False, 
writable=False),
Field('process_settings','text', filter_in=(lambda x: pickle.dumps(x)), 
filter_out=(lambda s: s and pickle.loads(s)),default=None, readable=False, 
writable=False),
Field('path','text', filter_in=(lambda x: pickle.dumps(x)), 
filter_out=(lambda s: s and pickle.loads(s)),default=None, readable=False, 
writable=False))

Ykä

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


[web2py] Re: Custom Style of a textarea.

2013-10-07 Thread Ykä Marjanen
Glad to help back, as I've gotten so much help from here.

If you like to have a more generic code to add your classes to the form 
objects, you can use the code below. It will add a new class to all 
elements while keeping the web2py classes. I think you could even add this 
to the layout with "try"-statement, so anytime you use any form, it would 
include new classes.


{{for element in form.elements():}}
{{if element['_class']:}}
{{element['_class'] = str(element['_class']) + " form-control"}}
{{else:}}
{{element['_class'] = 'form-control'}}
{{pass}}
{{pass}}

Ykä

On Sunday, October 6, 2013 10:31:19 PM UTC+3, Francisco García wrote:
>
> Hello Ykä and Paolo,
>
> Your answers are very useful for me. The problem is solved.
> All I needed was this sentence:
>
> form.custom.widget.FIELD['_class'] = 'text myclass'}
>
> Thank you for your fast answer.
> Regards.
>
>
> El sábado, 5 de octubre de 2013 09:24:59 UTC+2, Ykä Marjanen escribió:
>>
>> Hi Francisco,
>>
>> happy to help you, as I've gone a 4 day intensive bootstrap 3 integration 
>> to web2py and learned a lot about customizing the views and forms. This 
>> might not be the best (or only) solution, but has worked well for me:
>>
>> - Web2py form includes classes based on their type, which I recommend to 
>> keep, if you want any added web2py functionality.
>> - You need to use custom form style (form.custom.begin) and then 
>> manipulate each widget separately (or all of them in a for loop)
>>
>> Here's my form code in a view (controller is not modified). In this form 
>> I have added "form-control" class of bootstrap 3 and kept the original 
>> class as well. For textarea you can do 
>> "form.custom.widget.textfield['_rows'] = 3" if you want to make a smaller 
>> textarea.
>>
>> <<<
>> 
>> 
>> {{form.custom.widget.campaign['_class'] = 
>> 'generic-widget form-control'}}
>> {{form.custom.widget.topic['_class'] = 'string 
>> form-control'}}
>> {{form.custom.widget.topic['_placeholder'] = 'Idea 
>> topic'}}
>> {{form.custom.widget.description['_class'] = 'text 
>> form-control'}}
>> {{form.custom.widget.description['_placeholder'] = 
>> 'Idea description'}}
>> 
>> Select a 
>> campaign
>> {{=form.custom.widget.campaign}}
>> 
>> 
>> Input idea topic 
>> and description
>> {{=form.custom.widget.topic}}
>> 
>> 
>> {{=form.custom.widget.description}}
>> 
>> Submit 
>> your idea
>> 
>> {{=form.custom.end}}
>>
>> <<<<
>>
>> Ykä
>>
>> On Friday, October 4, 2013 8:14:33 PM UTC+3, Francisco García wrote:
>>>
>>> Hello all,
>>>
>>> I am loading a form from a database table, with CRUD or SQLFORM (It is 
>>> the same for me).
>>> This form contains text fields and textarea fields between others.
>>>
>>> Now, I need to change in the views the class of all textareas,  from 
>>> class="text"  to class="myclass"
>>> How can I do this from controllers or views?   (I can't edit any css 
>>> file).
>>>
>>> I am trying with form.custom.widget  but I can't change it.
>>> I'm not sure if it is something simple, or it is impossible to do this 
>>> way.
>>>
>>>
>>> Thank you in advance.
>>> Regards,
>>> Francisco
>>>
>>

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


[web2py] Re: Custom Style of a textarea.

2013-10-05 Thread Ykä Marjanen
Hi Francisco,

happy to help you, as I've gone a 4 day intensive bootstrap 3 integration 
to web2py and learned a lot about customizing the views and forms. This 
might not be the best (or only) solution, but has worked well for me:

- Web2py form includes classes based on their type, which I recommend to 
keep, if you want any added web2py functionality.
- You need to use custom form style (form.custom.begin) and then manipulate 
each widget separately (or all of them in a for loop)

Here's my form code in a view (controller is not modified). In this form I 
have added "form-control" class of bootstrap 3 and kept the original class 
as well. For textarea you can do "form.custom.widget.textfield['_rows'] = 
3" if you want to make a smaller textarea.

<<<


{{form.custom.widget.campaign['_class'] = 
'generic-widget form-control'}}
{{form.custom.widget.topic['_class'] = 'string 
form-control'}}
{{form.custom.widget.topic['_placeholder'] = 'Idea 
topic'}}
{{form.custom.widget.description['_class'] = 'text 
form-control'}}
{{form.custom.widget.description['_placeholder'] = 
'Idea description'}}

Select a campaign
{{=form.custom.widget.campaign}}


Input idea topic and 
description
{{=form.custom.widget.topic}}


{{=form.custom.widget.description}}

Submit 
your idea

{{=form.custom.end}}



Ykä

On Friday, October 4, 2013 8:14:33 PM UTC+3, Francisco García wrote:
>
> Hello all,
>
> I am loading a form from a database table, with CRUD or SQLFORM (It is the 
> same for me).
> This form contains text fields and textarea fields between others.
>
> Now, I need to change in the views the class of all textareas,  from class
> ="text"  to class="myclass"
> How can I do this from controllers or views?   (I can't edit any css file).
>
> I am trying with form.custom.widget  but I can't change it.
> I'm not sure if it is something simple, or it is impossible to do this way.
>
>
> Thank you in advance.
> Regards,
> Francisco
>

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


Re: [web2py] Crowdsourcing platform in Web2Py?

2013-09-09 Thread Ykä Marjanen
Hi,

check out Massimo's appliances from Git. There are lots of good example 
sources for web2py projects:

https://github.com/mdipierro/web2py-appliances

Ykä

On Monday, September 9, 2013 11:40:58 AM UTC+3, D.P. wrote:
>
> Sorry about the long time to answer. I will would be please to take a look 
> and help you testing it.
>
> Regards,
> D.
>
> On Thursday, July 4, 2013 4:35:23 PM UTC+2, Relsi Hur Maron wrote:
>>
>> What features you need?
>>
>> I'm developing a project of crowdsourcing here, is commercial but I'll 
>> release a part of the application opensource, with the following features
>> :
>>
>> - add/listing of jobs
>> - add/listing workers and portfolios
>> - signup employee and company
>> - submission of Proposals
>> - internal messages
>>
>> is a very alpha release, but if it fit for you, I can send the app to my 
>> repository on github and you get it.
>>
>>
>>
>> 2013/7/4 D.P. 
>>
>>> Hello,
>>>
>>> it is my first post in this group, and it is a pleasure to be in, as I 
>>> really think that web2py is a great tool.
>>>
>>> I am trying to see if there is any opensource crowdsoucing platform made 
>>> in web2py? Does any know any of any code example?
>>>
>>> Regards,
>>>
>>> D.
>>>
>>> -- 
>>>  
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "web2py-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to web2py+un...@googlegroups.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>

-- 

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


[web2py] Re: Is it mandatory to add new html page for every new function ?

2013-09-07 Thread Ykä Marjanen
You can redirect to any page you wish from a function. This way you don't 
have to create a page for the function and can decide what is the page you 
want to call.

example:

def no_page():
redirect(URL('index'))

This is beneficial, if you want to have a function which handles the link 
data and then decides what page (view) to call.

Ykä

On Friday, September 6, 2013 6:16:46 PM UTC+3, kranthi aeronaut wrote:
>
> hii all , i am new to web2py , it seems that in web2py for every function 
> we declare in default.py page , we should also create a new html page with 
> same name of function , is this mandatory or is there any other way to 
> implement the logic ??
>

-- 

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


[web2py] how to sms web app

2013-09-06 Thread Ykä Marjanen
Hi,

You need sms API service like textmagic. Then you create a basic application 
that reads text messages and displays them. The display part is well documented 
in web2py book.

Ykä

-- 

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


[web2py] Re: Webhosts for Web2py

2013-08-29 Thread Ykä Marjanen
Regarding pythonanywhere.com, what's the best way to run own background 
tasks? In the website they state 1-hour scheduled task, but I need to run 
multiple tasks almost real-time (e.g. sending registration emails and 
such). I've designed my website so that most tasks are queued and done in 
the background.

Ykä

On Thursday, August 29, 2013 9:33:36 AM UTC+3, Loïc wrote:
>
> My apps are hosted at pythonanywhere.com
> People there are very helpfull and responsive.
> I recommend it...
>
>
> Le mercredi 28 août 2013 16:41:25 UTC+2, Massimo Di Pierro a écrit :
>>
>> Answers below.
>>
>> On Tuesday, 27 August 2013 16:11:22 UTC-5, Vivek Jha wrote:
>>>
>>> I am new in web development and I have started with web2py and have 
>>> almost copleted reading the web2py book.
>>>
>>> Now few practical issues are coming up about which I don't have any 
>>> experience and that is chosing the right economical webhost.
>>>
>>> I think following suits my pocket:
>>> 1. Bluehost
>>> 2. Hostgator (mainly becuase they have presence in India as well)
>>> 3. Justhost. 
>>>
>>
>>> Do any of guys have any experience with these web hosts. As most of the 
>>> webhosts are still not able to see the world beyond PHP and wordpress they 
>>> have not mentioned python support specifically though they may be 
>>> supporting Python based applications internally.
>>>
>>> Questions:
>>> 1. Do the above webhosts will be able to support Web2Py with FastCGI.
>>>
>>
>> I just looked them up and they all they they do. They have instructions 
>> for Django. The same instructions apply to web2py except that 1) you do not 
>> need to install Django 2) you need to download and unzip web2py 3) you need 
>> to configure apache to point to the provided fcgihandler.py.
>>  
>>
>>> 2. Is having shell access a must for running web2py.
>>>
>>
>> You don't but it is convenient for maintenance. All the hosts you listed 
>> have a shell.
>>  
>>
>>> 3. Will it be possible to run Web2Py on the main domain and Wordpress on 
>>> subdomain or vice versa with them.
>>>
>>
>> That's an apache configuration issue. Yes you can. web2py does not care. 
>> If there is a path prefix you have to use routes.py to tell web2py to 
>> ignore the prefix.
>>  
>>
>>> 4. Whom to ask about WSGI setup? Is this a webshost specific question or 
>>> Web2Py specific.
>>>
>>
>> That's a host specific issue. It is unlikely shared hosts will support it.
>>  
>>
>>> If you think I have not asked the right questions, then please assume me 
>>> as a beginner in the hosting world and let me if there are any catches 
>>> about which I should be careful of.
>>>
>>
>> As a rule of thumb, if they have instructions for any other python 
>> framework you can do it with web2py too. We can help you convert the 
>> instructions. All python frameworks use the same standard mechanisms to 
>> talk to web servers. web2py is actually easier than others because you do 
>> not need root privileges to install it nor you need virtualenv. We also 
>> support all adapters: wsgi, fcgi, scgi, cgi, mod_python (discouraged), 
>> isapi (windows only). The real issue is, if they don't allow wsgi, than 
>> probably you need to run web2py using fcgi. This means you need to run your 
>> own long running process. What tools do they offer to do that (start, 
>> monitor, restart). Moreover if you later need a third party module that 
>> requires sudo access, will they install it for you? If they are mostly a 
>> Ruby or PHP shop, they will not help you much.  I have worked with 
>> pythonanywhere.com and they were very helpful and responsive.
>>
>

-- 

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


[web2py] Re: inbuilt login form

2013-08-21 Thread Ykä Marjanen
Hi kn,

it would help to provide a code (model, controller, view) and a description 
of what you want it to do.

Ykä

On Wednesday, August 21, 2013 7:05:19 PM UTC+3, kn wrote:
>
> hi, am new to web2py and i have been struggling to use it, could anyone 
> help me on how to make it work as in what needs to be done. i have a 
> template which is working fine so far but the thing is once i click on the 
> login button, i expect the inbuilt login form to appear of which it is not. 
> i have edited the default.py and the db.py file. any help will be 
> appreciated.
>
> best regards
>

-- 

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


[web2py] Re: Not a web2py issues but ...

2013-08-21 Thread Ykä Marjanen
Happy to help Massimo (sending you an email). I've done my PhD using Python 
and Scipy/Numpy and in my company we develop motion algorithms using 
Python. Now starting to learn Pandas.

Ykä

On Monday, August 19, 2013 4:51:56 PM UTC+3, Massimo Di Pierro wrote:
>
> ... I am writing a book about Numerical Algorithms in Python. It is almost 
> done. If you are interested in the subject and are interested in the area, 
> please email me. I will be happy them to share them in exchange of some 
> feedback.
>
> Massimo
>

-- 

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


[web2py] Re: An architectural strategy for a website - I'd like comments

2013-08-17 Thread Ykä Marjanen
Thanks guys!

So for next level strategy I will:

1) Determine and cache all queries and calculations that are non user 
spefic (e.g. ranking of all participants)
- This can be done either with cached select(), or using 
cache.ram/memcache/redis directly
- These could be done in a model level to make sure that they are updated 
regularly or use a cron/scheduler to do that in a background

2) Make session specific calculations and queries lazy and cache those that 
are required to be done multiple times in a session
- This can be done with @cache_property and/or storing results in a session 
variable (e.g. participant ranking in different competitions)

3) Use iterator/generator with those methods/functions that require only 
end result and most likely only once
- These could be also stored in a session for reuse if necessary

And of course it's a good idea to analyze code and decide the indexing of 
the database tables based on what is used heaviest.

I think it's easier to get the right strategy now when the code is simple, 
than later. Although I find Python flexible to change architecture also 
later.

Ykä

On Saturday, August 17, 2013 12:59:13 AM UTC+3, Massimo Di Pierro wrote:
>
>
>
> On Friday, 16 August 2013 06:58:49 UTC-5, Ykä Marjanen wrote:
>>
>> I read about cached select a bit more. So basically I could cache 
>> especially  the queries that are non user dependent (e.g. when calculating 
>> all participant rankings) and the query would be cached to all session. 
>> Right?
>>
>
> yes
>  
>
>>
>> I'm yet a bit early in the process to worry about too much optimization, 
>> but it's good to get a right understanding from the beginning, as I will 
>> soon have zillions of users :)
>>
>> Ykä
>>
>> On Friday, August 16, 2013 12:39:20 PM UTC+3, Niphlod wrote:
>>>
>>> That's a good way to eat up memory in the python process. I would have 
>>> saved a lot of headaches and just used select() with cache, possibly 
>>> exploiting memcache or redis to do the hard job. Don't take this the wrong 
>>> way, the cached_property is a neat trick, it's just not that suitable for 
>>> storing your zillions participant when you'll grow big.
>>>
>>> On Friday, August 16, 2013 10:25:32 AM UTC+2, Ykä Marjanen wrote:
>>>>
>>>> Hi,
>>>>
>>>> After learning Python and web2py deeper, I've restructured my web2py 
>>>> application so that all functions and data are now in classes with lazy 
>>>> methods in my own module. The lazy property class turns any method into a 
>>>> "cached attribute", thus I can make a db query that returns rows and if it 
>>>> is called again it uses the previous result.
>>>>
>>>> What this has allowed me to do, is to clean practically all code in my 
>>>> controller as the logic and variables are in a class. Now I just pass the 
>>>> class to the view and the view prints the "attributes" directly without 
>>>> separate call and saving to dict. I've read that some don't like any logic 
>>>> in the view, but that's unavoidable as in the view you need to print stuff 
>>>> depending who the user is and is he logged in or not.
>>>>
>>>> I'd like your opinions and comments on my strategy. Here are few 
>>>> simplified examples from my code:
>>>>
>>>> Module:
>>>>
>>>> class MyClass(object):
>>>> def __init__(self):
>>>> self.db = current.db
>>>>
>>>> @cached_property
>>>> def all_participants(self):
>>>> return self.db(self.db.participant.id>0).select()
>>>>
>>>> class MyClassParticipant(MyClass):
>>>>  "Inherits base class"
>>>> def __init__(self, auth_user_id=None):
>>>> self.auth_user_id = auth_user_id
>>>>
>>>> super(MyClassParticipant, self).__init__()
>>>>
>>>> @cached_property
>>>> def participant_stats(self):
>>>> return 
>>>> self.db(self.db.participant.auth_user_id==self.auth_user_id).select()
>>>>
>>>> Controller:
>>>>
>>>> def index():
>>>> if auth.user:
>>>> xclassinstance = 
>>>> module.MyClassParticipant(auth_user_id=auth.user_id)
>>>> else:
>>>> xclassinstance = module.MyClass()
>>>>
>>>> return dict(xclassinstance=xclassinstance)
>>>>
>>>> View:
>>>>
>>>> {{if auth.user:}}
>>>> Your ranking is {{=xclassinstance.participant_stats.ranking}}
>>>>
>>>> Rankings of all participants
>>>> 
>>>> {{for participant in xclassinstance.all_participants:}}
>>>> {{=participant.name}} ranking is {{=participant.ranking}}
>>>> 
>>>>
>>>> Ykä
>>>> 
>>>>
>>>>

-- 

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


[web2py] Re: An architectural strategy for a website - I'd like comments

2013-08-16 Thread Ykä Marjanen
I read about cached select a bit more. So basically I could cache 
especially  the queries that are non user dependent (e.g. when calculating 
all participant rankings) and the query would be cached to all session. 
Right?

I'm yet a bit early in the process to worry about too much optimization, 
but it's good to get a right understanding from the beginning, as I will 
soon have zillions of users :)

Ykä

On Friday, August 16, 2013 12:39:20 PM UTC+3, Niphlod wrote:
>
> That's a good way to eat up memory in the python process. I would have 
> saved a lot of headaches and just used select() with cache, possibly 
> exploiting memcache or redis to do the hard job. Don't take this the wrong 
> way, the cached_property is a neat trick, it's just not that suitable for 
> storing your zillions participant when you'll grow big.
>
> On Friday, August 16, 2013 10:25:32 AM UTC+2, Ykä Marjanen wrote:
>>
>> Hi,
>>
>> After learning Python and web2py deeper, I've restructured my web2py 
>> application so that all functions and data are now in classes with lazy 
>> methods in my own module. The lazy property class turns any method into a 
>> "cached attribute", thus I can make a db query that returns rows and if it 
>> is called again it uses the previous result.
>>
>> What this has allowed me to do, is to clean practically all code in my 
>> controller as the logic and variables are in a class. Now I just pass the 
>> class to the view and the view prints the "attributes" directly without 
>> separate call and saving to dict. I've read that some don't like any logic 
>> in the view, but that's unavoidable as in the view you need to print stuff 
>> depending who the user is and is he logged in or not.
>>
>> I'd like your opinions and comments on my strategy. Here are few 
>> simplified examples from my code:
>>
>> Module:
>>
>> class MyClass(object):
>> def __init__(self):
>> self.db = current.db
>>
>> @cached_property
>> def all_participants(self):
>> return self.db(self.db.participant.id>0).select()
>>
>> class MyClassParticipant(MyClass):
>>  "Inherits base class"
>> def __init__(self, auth_user_id=None):
>> self.auth_user_id = auth_user_id
>>
>> super(MyClassParticipant, self).__init__()
>>
>> @cached_property
>> def participant_stats(self):
>> return 
>> self.db(self.db.participant.auth_user_id==self.auth_user_id).select()
>>
>> Controller:
>>
>> def index():
>> if auth.user:
>> xclassinstance = 
>> module.MyClassParticipant(auth_user_id=auth.user_id)
>> else:
>> xclassinstance = module.MyClass()
>>
>> return dict(xclassinstance=xclassinstance)
>>
>> View:
>>
>> {{if auth.user:}}
>> Your ranking is {{=xclassinstance.participant_stats.ranking}}
>>
>> Rankings of all participants
>> 
>> {{for participant in xclassinstance.all_participants:}}
>> {{=participant.name}} ranking is {{=participant.ranking}}
>> 
>>
>> Ykä
>> 
>>
>>

-- 

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


[web2py] Re: An architectural strategy for a website - I'd like comments

2013-08-16 Thread Ykä Marjanen
The example was a bit simplified. In the real process I fetch data from the 
database, calculate scores and rankings and then return the result. So it's 
not just for database queries, but all calculations.

The reason I'm using cache_property is that many methods in the class use 
the same data, so if I call "classinstance.participant_ranking" and 
"classinstance.all_participant_rankings", they both use the same cached 
data in the class (you cannot calculate ranking of one participant without 
calculating it for all). Otherwise I would need to manually check if the 
query and calculation has been already made if I don't want to duplicate 
the calculation.

I've understood that caches (cache.ram, cache.disk, memcache and redis) are 
server level caches. So if my data changes per user, I cannot really use 
them(?)

Ykä

On Friday, August 16, 2013 12:39:20 PM UTC+3, Niphlod wrote:
>
> That's a good way to eat up memory in the python process. I would have 
> saved a lot of headaches and just used select() with cache, possibly 
> exploiting memcache or redis to do the hard job. Don't take this the wrong 
> way, the cached_property is a neat trick, it's just not that suitable for 
> storing your zillions participant when you'll grow big.
>
> On Friday, August 16, 2013 10:25:32 AM UTC+2, Ykä Marjanen wrote:
>>
>> Hi,
>>
>> After learning Python and web2py deeper, I've restructured my web2py 
>> application so that all functions and data are now in classes with lazy 
>> methods in my own module. The lazy property class turns any method into a 
>> "cached attribute", thus I can make a db query that returns rows and if it 
>> is called again it uses the previous result.
>>
>> What this has allowed me to do, is to clean practically all code in my 
>> controller as the logic and variables are in a class. Now I just pass the 
>> class to the view and the view prints the "attributes" directly without 
>> separate call and saving to dict. I've read that some don't like any logic 
>> in the view, but that's unavoidable as in the view you need to print stuff 
>> depending who the user is and is he logged in or not.
>>
>> I'd like your opinions and comments on my strategy. Here are few 
>> simplified examples from my code:
>>
>> Module:
>>
>> class MyClass(object):
>> def __init__(self):
>> self.db = current.db
>>
>> @cached_property
>> def all_participants(self):
>> return self.db(self.db.participant.id>0).select()
>>
>> class MyClassParticipant(MyClass):
>>  "Inherits base class"
>> def __init__(self, auth_user_id=None):
>> self.auth_user_id = auth_user_id
>>
>> super(MyClassParticipant, self).__init__()
>>
>> @cached_property
>> def participant_stats(self):
>> return 
>> self.db(self.db.participant.auth_user_id==self.auth_user_id).select()
>>
>> Controller:
>>
>> def index():
>> if auth.user:
>> xclassinstance = 
>> module.MyClassParticipant(auth_user_id=auth.user_id)
>> else:
>> xclassinstance = module.MyClass()
>>
>> return dict(xclassinstance=xclassinstance)
>>
>> View:
>>
>> {{if auth.user:}}
>> Your ranking is {{=xclassinstance.participant_stats.ranking}}
>>
>> Rankings of all participants
>> 
>> {{for participant in xclassinstance.all_participants:}}
>> {{=participant.name}} ranking is {{=participant.ranking}}
>> 
>>
>> Ykä
>> 
>>
>>

-- 

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


[web2py] An architectural strategy for a website - I'd like comments

2013-08-16 Thread Ykä Marjanen
Hi,

After learning Python and web2py deeper, I've restructured my web2py 
application so that all functions and data are now in classes with lazy 
methods in my own module. The lazy property class turns any method into a 
"cached attribute", thus I can make a db query that returns rows and if it 
is called again it uses the previous result.

What this has allowed me to do, is to clean practically all code in my 
controller as the logic and variables are in a class. Now I just pass the 
class to the view and the view prints the "attributes" directly without 
separate call and saving to dict. I've read that some don't like any logic 
in the view, but that's unavoidable as in the view you need to print stuff 
depending who the user is and is he logged in or not.

I'd like your opinions and comments on my strategy. Here are few simplified 
examples from my code:

Module:

class MyClass(object):
def __init__(self):
self.db = current.db

@cached_property
def all_participants(self):
return self.db(self.db.participant.id>0).select()

class MyClassParticipant(MyClass):
 "Inherits base class"
def __init__(self, auth_user_id=None):
self.auth_user_id = auth_user_id

super(MyClassParticipant, self).__init__()

@cached_property
def participant_stats(self):
return 
self.db(self.db.participant.auth_user_id==self.auth_user_id).select()

Controller:

def index():
if auth.user:
xclassinstance = 
module.MyClassParticipant(auth_user_id=auth.user_id)
else:
xclassinstance = module.MyClass()

return dict(xclassinstance=xclassinstance)

View:

{{if auth.user:}}
Your ranking is {{=xclassinstance.participant_stats.ranking}}

Rankings of all participants

{{for participant in xclassinstance.all_participants:}}
{{=participant.name}} ranking is {{=participant.ranking}}


Ykä


-- 

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


Re: [web2py] Re: Pass python list back to controller

2013-08-16 Thread Ykä Marjanen
In my case I generate unique links to participants that are sent via email. 
In this case I cannot use session to store them, as the user clicks the 
links without registering to a website and can take several days before 
registering.

I had an option to either pass all parameters in the link args, which would 
make a long link, or to generate a unique code and store the parameters in 
a table. I decided to do the latter for keeping the link short and for 
security reasons (parameters would imply how to change link parameters 
manually).

If the user does the tasks while signed in, I still generate the links the 
same way, even though I could do it using the session, because I want to 
avoid extra work :)

Ykä

On Thursday, August 15, 2013 10:19:13 PM UTC+3, Richard wrote:
>
> ids = [1, 2, 3]
> redirect(URL(c='test', f='side_by_side', args=(request.args(0)), 
> vars=dict(ids=ids)))
>
> ids = request.vars.ids
>
> Work as well...
>
> The url look like that :
>
> test/side_by_side/table?ids=1&ids=2&ids=3
>
> I have use session.ids before, but I need to pass a list of id by the url 
> in order to not have to write a big infrastructure to store each "report" 
> constructed by user... Having everything in the url let call the same 
> report again and again (constructed once by selecting the differents 
> records with a form that than redirect on the url of the report). Then the 
> only thing I have to manage is a bunch of links that user can keep in a 
> table of report or something. The user as only to copy url and send it by 
> email to colleague...
>
> :)
>
> Richard
>
>
> On Thu, Aug 8, 2013 at 5:24 PM, Kyle Flanagan 
> 
> > wrote:
>
>> This worked well. Thanks.
>>
>>
>> On Thursday, July 18, 2013 11:18:23 AM UTC-5, Ykä Marjanen wrote:
>>>
>>> Hi,
>>>
>>> If I understood correctly, you could use 'session' to save the list, so 
>>> you don't have to pass it back and forth to the controller.
>>>
>>> E.g. session.serials = [] and then session.serials.append(x)
>>>
>>> Ykä
>>>
>>> On Thursday, July 18, 2013 6:55:52 PM UTC+3, Kyle Flanagan wrote:
>>>>
>>>> What's the best way to pass a Python list back to the controller, i.e. 
>>>> keep the list object persistent between calls? The list could get quite 
>>>> large so I'm not sure if request.args or request.vars is appropriate for 
>>>> it 
>>>> (well the items in the list)? The code below is a mockup of what I'm 
>>>> trying 
>>>> to achieve. The list in question is 'serials.' 
>>>>
>>>> @auth.requires_login()
>>>> def send():
>>>> """
>>>> Method for 'sending'an IBC tote to a location.
>>>> """
>>>> try:
>>>> if serials:
>>>> pass
>>>> except:
>>>> serials = list()
>>>> 
>>>> if request.vars["location_id"]:
>>>> if request.vars["serial_number"]:
>>>> # update the location
>>>> serials.append(request.vars["**serial_number"])
>>>>
>>>> # start accepting input to update IBC's to this location
>>>> status = "Location: " + db.MyLocation[request.vars['**
>>>> location_id']].name
>>>> form = SQLFORM.factory(Field('Object_**serial_number', requires
>>>> =IS_IN_DB(db, 'Object.serial_number', '%(serial_number)s', orderby=db.
>>>> Object.serial_**number)))
>>>> if form.process().accepted:
>>>> response.flash = form.vars.Object_serial_number
>>>> redirect(URL('send', vars=dict(location_id=request.**vars[
>>>> "location_id"], serial_number=form.vars.Object**_serial_number)))
>>>> else:
>>>> # we need to pick a location
>>>> form = SQLFORM.factory(Field('send_**location', requires=
>>>> IS_IN_DB(db, 'MyLocation.id', '%(name)s', orderby=db.MyLocation.name)))
>>>> if form.process().accepted:
>>>> response.flash = form.vars.send_location
>>>> redirect(URL('send', vars=dict(location_id=form.var**s.
>>>> send_location)))
>>>> status = "No location"
>>>> 
>>>> return dict(grid=form, status=status, serials=serials, count=len(
>>>> serials))
>>>>
>>>> Basically, the user goes to the 'send' controller, picks a location, 
>>>> then enters serial numbers. I'd like to keep a list going so that the user 
>>>> can remove a serial number from the list if they added one in error and 
>>>> then submit them for updating all at once.
>>>>
>>>  -- 
>>  
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to web2py+un...@googlegroups.com .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 

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


[web2py] offtopic : beautiful code

2013-07-23 Thread Ykä Marjanen
I've watched this at least 10 times. Definately would recommend all web2py 
developers to watch and learn from this.

Ykä

-- 

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




[web2py] Re: Pass python list back to controller

2013-07-18 Thread Ykä Marjanen
Hi,

If I understood correctly, you could use 'session' to save the list, so you 
don't have to pass it back and forth to the controller.

E.g. session.serials = [] and then session.serials.append(x)

Ykä

On Thursday, July 18, 2013 6:55:52 PM UTC+3, Kyle Flanagan wrote:
>
> What's the best way to pass a Python list back to the controller, i.e. 
> keep the list object persistent between calls? The list could get quite 
> large so I'm not sure if request.args or request.vars is appropriate for it 
> (well the items in the list)? The code below is a mockup of what I'm trying 
> to achieve. The list in question is 'serials.' 
>
> @auth.requires_login()
> def send():
> """
> Method for 'sending'an IBC tote to a location.
> """
> try:
> if serials:
> pass
> except:
> serials = list()
> 
> if request.vars["location_id"]:
> if request.vars["serial_number"]:
> # update the location
> serials.append(request.vars["serial_number"])
>
> # start accepting input to update IBC's to this location
> status = "Location: " + db.MyLocation[request.vars['location_id'
> ]].name
> form = SQLFORM.factory(Field('Object_serial_number', requires=
> IS_IN_DB(db, 'Object.serial_number', '%(serial_number)s', orderby=db.
> Object.serial_number)))
> if form.process().accepted:
> response.flash = form.vars.Object_serial_number
> redirect(URL('send', vars=dict(location_id=request.vars[
> "location_id"], serial_number=form.vars.Object_serial_number)))
> else:
> # we need to pick a location
> form = SQLFORM.factory(Field('send_location', requires=IS_IN_DB(db
> , 'MyLocation.id', '%(name)s', orderby=db.MyLocation.name)))
> if form.process().accepted:
> response.flash = form.vars.send_location
> redirect(URL('send', vars=dict(location_id=form.vars.
> send_location)))
> status = "No location"
> 
> return dict(grid=form, status=status, serials=serials, count=len(
> serials))
>
> Basically, the user goes to the 'send' controller, picks a location, then 
> enters serial numbers. I'd like to keep a list going so that the user can 
> remove a serial number from the list if they added one in error and then 
> submit them for updating all at once.
>

-- 

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




[web2py] Re: Filling form in multiple phases with some data from database and some from a dictionary

2013-06-15 Thread Ykä Marjanen
Hi J,

Of course you were here too :)

I solved the issue by using SQLFORM.factory to generate the form for those 
pages where there was a dictionary variable. I've edited the code so that I 
think I got it working properly.

I save the form.vars of each page to session.page_nro and at the end (four 
phases) I add them all to a one dictionary to add it to database: 
db.campaign.insert(**db_data).

It seems to work okay.

On Thursday, June 13, 2013 11:55:08 AM UTC+3, Ykä Marjanen wrote:
>
> Hi,
>
> I've been programming Python for 10 years now, mainly algorithms. I found 
> out about Web2py 4 months ago, and have been intensively learning it since. 
> So thanks for all contributors!
>
> I'm developing a web interface where a user can create a new idea 
> campaign. Because the campaign has lots of parameters which can change per 
> campaign, I've decided to store most of the settings to the database as a 
> dictionary using Pickle. I want to cut the creation of the campaign into 
> phases to keep the visible form short.
>
> Based on the documentation (excellent book) I've decided to use Session to 
> store the value from each phase and only store the variables into the 
> database after the user has filled all forms. I use the same page to show 
> different forms to keep the files to a minimum.
>
> My problems are the following:
>
> 1) How to use SQLFORM.dictform with a dictionary so that it shows menu 
> options (and checklist) to some of the settings (e.g. 
> IS_IN_SET(['one','two'])). The dictionary is created during the process, so 
> the database doesn't have no values in it to fetch.
>
> 2) Am I doing to this properly (see code below)?
>
> Here's my code (I've simplified it to make it more understandable)
>
> Model:
>
> db.define_table('campaign',
> Field('name', unique=True),
> Field('pagename', unique=True),
> Field('description','text'),
> Field('created_by','reference auth_user', default=auth.user_id),
> Field('type', requires=IS_IN_SET(['open','private'])),
> Field('general_settings','text', filter_in=(lambda x: 
> pickle.dumps(x)), filter_out=(lambda s: s and 
> pickle.loads(s)),default=None))
>
> Controller:
>
> if request.args(0,cast=str) == 'prev':
> try:
> if session.step > 0:
> session.step -= 1
> else:
> redirect(URL('index'))
> except:
> session.step = 0
>
> #determine in which step
> if not session.step:
> session.step = 0
>
> if session.step == 0:
> form = SQLFORM(db.campaign, fields=['name','description'])
> form.add_button('Cancel',URL('index'))
> if form.validate():
> session.step1_variables = form.vars
> session.step = 1
>
> redirect(URL('new_campaign'))
>
> elif session.step == 1:
> form = SQLFORM(db.campaign, fields=['pagename'])
> form.add_button('Prev',URL('new_campaign',args='prev'))
> if form.validate():
> session.step2_variables = form.vars
> session.step = 2
>
> redirect(URL('new_campaign'))
>
> elif session.step == 2:
> settings_dict = dict(privacy="", registration="self")
> form = SQLFORM.dictform(settings_dict)
> form.add_button('Prev',URL('new_campaign',args='prev'))
> form.custom.widget.privacy['requires'] = 
> IS_IN_SET(['open','closed'])
> if form.validate():
> session.step3_variables = form.vars
> session.step = 3
>
> redirect(URL('new_campaign'))
>
> elif session.step == 3:
> form = FORM.confirm('Are you sure?')
> if form.accepted:
> session.step = 0
> #Store all variables to the database
> #Redirect to the new campaign page  
>
> else:
> redirect(URL('index'))
>
> return dict(form=form, step=session.step)
>
> View:
>
> {extend 'layout.html'}}
> {{if step == 0:}}
> {{=T('Create new campaign')}}
> {{=T('Welcome to XXX. Create a campaign using this simple wizard')}}
> {{elif step == 1:}}
> {{=T('Create new campaign')}}
> {{=T('Please add your pagename')}}   
> {{elif step == 2:}}
> {{=T('Create new campaign')}}
> {{=T('Make some settings')}}
> {{elif step == 3:}}
> {{=T('Create new campaign')}}
> {{=T('Here are all your settings. Click the button the accept them')}}
> {{pass}}
> {{=form}}
>

-- 

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




[web2py] Filling form in multiple phases with some data from database and some from a dictionary

2013-06-13 Thread Ykä Marjanen
Hi,

I've been programming Python for 10 years now, mainly algorithms. I found 
out about Web2py 4 months ago, and have been intensively learning it since. 
So thanks for all contributors!

I'm developing a web interface where a user can create a new idea campaign. 
Because the campaign has lots of parameters which can change per campaign, 
I've decided to store most of the settings to the database as a dictionary 
using Pickle. I want to cut the creation of the campaign into phases to 
keep the visible form short.

Based on the documentation (excellent book) I've decided to use Session to 
store the value from each phase and only store the variables into the 
database after the user has filled all forms. I use the same page to show 
different forms to keep the files to a minimum.

My problems are the following:

1) How to use SQLFORM.dictform with a dictionary so that it shows menu 
options (and checklist) to some of the settings (e.g. 
IS_IN_SET(['one','two'])). The dictionary is created during the process, so 
the database doesn't have no values in it to fetch.

2) Am I doing to this properly (see code below)?

Here's my code (I've simplified it to make it more understandable)

Model:

db.define_table('campaign',
Field('name', unique=True),
Field('pagename', unique=True),
Field('description','text'),
Field('created_by','reference auth_user', default=auth.user_id),
Field('type', requires=IS_IN_SET(['open','private'])),
Field('general_settings','text', filter_in=(lambda x: pickle.dumps(x)), 
filter_out=(lambda s: s and pickle.loads(s)),default=None))

Controller:

if request.args(0,cast=str) == 'prev':
try:
if session.step > 0:
session.step -= 1
else:
redirect(URL('index'))
except:
session.step = 0

#determine in which step
if not session.step:
session.step = 0

if session.step == 0:
form = SQLFORM(db.campaign, fields=['name','description'])
form.add_button('Cancel',URL('index'))
if form.validate():
session.step1_variables = form.vars
session.step = 1

redirect(URL('new_campaign'))

elif session.step == 1:
form = SQLFORM(db.campaign, fields=['pagename'])
form.add_button('Prev',URL('new_campaign',args='prev'))
if form.validate():
session.step2_variables = form.vars
session.step = 2

redirect(URL('new_campaign'))

elif session.step == 2:
settings_dict = dict(privacy="", registration="self")
form = SQLFORM.dictform(settings_dict)
form.add_button('Prev',URL('new_campaign',args='prev'))
form.custom.widget.privacy['requires'] = 
IS_IN_SET(['open','closed'])
if form.validate():
session.step3_variables = form.vars
session.step = 3

redirect(URL('new_campaign'))

elif session.step == 3:
form = FORM.confirm('Are you sure?')
if form.accepted:
session.step = 0
#Store all variables to the database
#Redirect to the new campaign page  

else:
redirect(URL('index'))

return dict(form=form, step=session.step)

View:

{extend 'layout.html'}}
{{if step == 0:}}
{{=T('Create new campaign')}}
{{=T('Welcome to XXX. Create a campaign using this simple wizard')}}
{{elif step == 1:}}
{{=T('Create new campaign')}}
{{=T('Please add your pagename')}}   
{{elif step == 2:}}
{{=T('Create new campaign')}}
{{=T('Make some settings')}}
{{elif step == 3:}}
{{=T('Create new campaign')}}
{{=T('Here are all your settings. Click the button the accept them')}}
{{pass}}
{{=form}}

-- 

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