Re: [web2py] Installation of an editor plugin in web2py app

2014-12-15 Thread Ramashish Gaurav
Thanks all the way Andrew. This was the perfect solution to my problem, for 
which I wasted a day. One more thing, if you wish to, please give me some 
info about XSS attack, how can we ignorantly get caught in it and measures 
taken to prevent XSS attacks.  

On Tuesday, December 16, 2014 1:20:20 AM UTC+5:30, Andrew wrote:
>
> Hey there if I understand correctly you want to not display html but the 
> formatted output. If so then use this in your view and add any html you 
> would like to allow.
>
> {{=XML(row.textfromeditor, sanitize=True, permitted_tags=['a', 'b', 
> 'blockquote', 'br', 'i', 'li',
>'ol', 'ul', 'p', 'cite', 
> 'code', 'pre', 'img'],
> allowed_attributes={'a':['href', 'title'],
>'img':['src', 'alt'], 
> 'blockquote':['type']})}}
>
>
>
> or do this which I highly suggest not doing {{=XML(row.textfromeditor, 
> sanitize=False)}}
>
> *cheers
>
>
> On Mon, Dec 15, 2014 at 6:50 AM, Ramashish Gaurav  > wrote:
>>
>> Dear Andrew,
>>
>> Many thanks for your response and elaborate explanation of installation 
>> of ck-editor. However I used another light weight editor nicEdit since the 
>> installation was pretty easy as directed at http://nicedit.com/ . 
>> However I am in a problem, not related to installation of editors, but in 
>> showing of html doc after being saved from the textarea.
>>
>> The content from the textarea in HTML used with nicEdit, is in html 
>> format. After getting the html coded text from textarea and saving it in 
>> database, I need to redisplay it on demand. I tried to use textarea with 
>> read only mode to display the html text in formatted form, searched for 
>> hours on internet but with no luck. Textarea always showed the raw html 
>> code instead of formatted one. Also I read that it can be done via an 
>> editor only, not textarea. So used nicEdit again, but don't know to use it 
>> in read only mode. stackoverflow had a post related to the similar problem 
>> of using nicEdit with disabled edit option, but it did not come to my 
>> rescue. I implemented the code posted there in answer, but was not able to 
>> set nicEdit in read only mode. Here is the link.
>>
>> http://stackoverflow.com/questions/4282446/how-to-set-nicedit-uneditable
>>
>> If you do know to display the html coded text in formatted way via 
>> nicEdit or any other way round, I'd appreciate your help.
>>
>> Here is the code I have implemented:
>>
>> {{extend 'layout.html'}}
>> 
>>
>> http://js.nicedit.com/nicEdit-latest.js"; 
>> type="text/javascript">
>> 
>> > type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);
>> http://js.nicedit.com/nicEdit-latest.js";>
>> //> bkLib.onDomLoaded(funtion(){
>>   var myNicEditor = 
>> new nicEditor();
>>   
>> myNicEditor.addInstance("nice"); 
>>   
>> nicEditors.findEditor("nice").disable();
>>});
>>   
>>   //]]> 
>>
>> 
>>
>> 
>> {{for row in rows:}}
>> {{=row.textfromeditor}}
>> {{pass}}
>>
>> 
>>
>>
>> On Monday, December 15, 2014 6:45:52 AM UTC+5:30, Andrew wrote:
>>>
>>> Your error at this point isn't from ckeditor but you are using a 
>>> reserved sql keyword in your database table/field. I suggest removing this 
>>> line *check_reserved=['all']* or change the name of one of the 
>>> fields/tables in question.
>>>
>>> As a side reference here is a brief bit of info for implementing 
>>> ckeditor. 
>>>
>>> I haven't used ckeditor in a long time but if the code remains the same 
>>> then you can do this.
>>>
>>> in db.py add:
>>>
>>> def advanced_editor(field, value):
>>> return TEXTAREA(_id = str(field).replace('.','_'), _name=field.name, 
>>> _class='text ckeditor', value=value, _cols=80, _rows=10)
>>>
>>> For the text field you use this as an example:
>>> Field('body', 'text', widget=advanced_editor))
>>>
>>> In your template file example layout.html add the path to ckeditor:
>>> 
>>>
>>> Then choose to sanitize or not the input. Depending if other users will 
>>> submit your form then I would choose to sanitize info:
>>>
>>> Example sanitized: 
>>> {{=XML(query.body,sanitize=True, 
>>> permitted_tags=['a', 'b', 'blockquote', 'br', 'i', 'li',
>>>'ol', 'ul', 'p', 'cite', 
>>> 'code', 'pre', 'img'],
>>> allowed_attributes={'a':['href', 'title'],
>>>'img':['src', 'alt'], 
>>> 'blockquote':['type']})}}
>>>
>>> Example unsanitized: {{=XML(query.body,sanitize=False)}}
>>>
>>> you can choose what values you will allow to be displayed for that form 
>>> code in th

[web2py] Re: removing items from cache not working

2014-12-15 Thread Anthony
How about:

cache.ram.clear(regex=r'admin\.setting.*')

Anthony

On Monday, December 15, 2014 6:22:38 PM UTC-5, Alex wrote:
>
> I've got a function which returns a dict with some values. the function 
> has this decorator:
>
> @cache('admin.setting.limits', 3600, cache.ram)
>
> def get_limits():
> ..
>
>
> This works fine and the values are used from cache. When I change those 
> settings I want to clear the cache so I'm doing this:
>
> cache.ram.clear(regex='admin\.setting.*')
>
> When I call my function again the cached values are still used. Am I doing 
> something wrong here? Any ideas?
>
>
> regards,
>
> Alex
>

-- 
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: removing items from cache not working

2014-12-15 Thread Alex


the regex should be fine (I tested it with a regex online tool). Doesn't 
make a difference if I use your regex.

Thanks for your help, I can fix the problem by clearing the exact values. 
But I'd like to understand what's wrong with clearing the cache by regex.

On Tuesday, December 16, 2014 1:32:01 AM UTC+1, Derek wrote:
>
> Your regex is wrong then.
>
> try this?
>
> admin\.setting\.[A-z]*
>
>
> On Monday, December 15, 2014 5:22:40 PM UTC-7, Alex wrote:
>>
>> tested with clearing values with exact key and this seems to work. Do you 
>> know why using the regex doesn't work?
>>
>>
>> Alex
>>
>

-- 
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: removing items from cache not working

2014-12-15 Thread Derek
Your regex is wrong then.

try this?

admin\.setting\.[A-z]*


On Monday, December 15, 2014 5:22:40 PM UTC-7, Alex wrote:
>
> tested with clearing values with exact key and this seems to work. Do you 
> know why using the regex doesn't work?
>
>
> Alex
>

-- 
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: Hyphen in application name

2014-12-15 Thread Derek
well, according to the documentation it should work, so perhaps you 
encountered a bug. 

Just a question, where did you put your routes.py? if in the application, 
then you can only route controllers and functions.

On Monday, December 15, 2014 3:42:53 AM UTC-7, tim.n...@conted.ox.ac.uk 
wrote:
>
> Does anyone know how to get map_hyphen to work with an application name?
>
> I have a routes.py setup as follows:
>
> routers = dict(
>BASE  = dict(
>default_application = "home",
>default_controller = "default",
>default_function = "index",
>map_hyphen=True, 
> ),
> )
>
> In my application (tutor_events), controller and function hyphen mapping 
> work fine, so the following paths work:
> /tutor_events/default/edit-details/424
> /tutor_events/tutor-fee/add
>
> And all URLs are being generated with hyphens
>
> But if I try to go to /tutor-events/..., I get an error: invalid function 
> (default/tutor_events)
> So web2py is trying to send me on to /home/default/tutor_events
>

-- 
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: removing items from cache not working

2014-12-15 Thread Alex


tested with clearing values with exact key and this seems to work. Do you 
know why using the regex doesn't work?


Alex

-- 
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: removing items from cache not working

2014-12-15 Thread Alex
because I have multiple values cached in different functions and all can be 
edited on the same page. I'll test to delete it with the exact key. 
Anything wrong with the regex?

On Tuesday, December 16, 2014 12:58:38 AM UTC+1, Derek wrote:
>
> Why are you not just clearing the exact key?
>
> cache.ram('admin.setting.limits',None)
>
> On Monday, December 15, 2014 4:22:38 PM UTC-7, Alex wrote:
>>
>> I've got a function which returns a dict with some values. the function 
>> has this decorator:
>>
>> @cache('admin.setting.limits', 3600, cache.ram)
>>
>> def get_limits():
>> ..
>>
>>
>> This works fine and the values are used from cache. When I change those 
>> settings I want to clear the cache so I'm doing this:
>>
>> cache.ram.clear(regex='admin\.setting.*')
>>
>> When I call my function again the cached values are still used. Am I 
>> doing something wrong here? Any ideas?
>>
>>
>> regards,
>>
>> Alex
>>
>

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


Re: [web2py] Re: Domain model and web2py DAL

2014-12-15 Thread Derek
I suppose it depends on what you mean by this " application logic 
completely independent from persistent data storage"
So you certainly can have that completely independent, though you wouldn't 
persist anything. Is the idea that you'd update a memory representation of 
objects only, and somehow your data will be automatically persisted? If so, 
you can certainly program it that way as well. 

Often times we'll get people here asking about something they read in a 
book somewhere about how this would be better and why doesn't Web2py 
support this something. Chances are, web2py does support this something, 
but not everyone is in agreement that this something is better. Time and 
experience are the greatest teachers.

As for you, I'd suggest that if  you can provide us with concrete examples 
of where a 'data mapper' is what you need, and why you choose this, perhaps 
we can review the capabilities of web2py with you.

On Sunday, December 14, 2014 12:54:42 PM UTC-7, Alan Evangelista wrote:
>
> Simple is a relative term, I should not have associated it with web2py 
> DAL. What I meant is that I want to make my application logic completely 
> independent from persistent data storage. The only method I know to 
> implement this is using the data mapper design pattern (
> http://en.wikipedia.org/wiki/Data_mapper_pattern). It seems to me this is 
> impossible using only web2py DAL, I'd have to implement an ORM on top of 
> web2py DAL. Is that correct? If not, please provide details on how I would 
> achieve this.
>
> Thanks in advance!
>

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


[web2py] Re: removing items from cache not working

2014-12-15 Thread Derek
Why are you not just clearing the exact key?

cache.ram('admin.setting.limits',None)

On Monday, December 15, 2014 4:22:38 PM UTC-7, Alex wrote:
>
> I've got a function which returns a dict with some values. the function 
> has this decorator:
>
> @cache('admin.setting.limits', 3600, cache.ram)
>
> def get_limits():
> ..
>
>
> This works fine and the values are used from cache. When I change those 
> settings I want to clear the cache so I'm doing this:
>
> cache.ram.clear(regex='admin\.setting.*')
>
> When I call my function again the cached values are still used. Am I doing 
> something wrong here? Any ideas?
>
>
> regards,
>
> Alex
>

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


Re: [web2py] Re: Component with argument example

2014-12-15 Thread clara
Anthony,

I think I found the problem. In page 405 of the book's 5th edition it says:

"*Because of the way grid works one can only have one grid per*
*controller function, unless they are embedded as components via*
*LOAD. To make the default search grid work in more than one*
*LOADed grid, please use a different formname for each one."*

I changed the component and added a unique formname to it as follows:

@auth.requires_login()
def pet_component():
itemid = request.args[0]
q = db.t_pet.f_owner == itemid
db.t_pet.f_owner.default = itemid
db.t_pet.f_owner.writable = False
form = SQLFORM.grid(q,args=request.args[:1],csv=False*,formname = 
"form"+str(itemid)*)
return locals()

And this solved the problem!  Now when I add a record to any of the grids 
and save it, the grid reloads filtering by owner and and the new record is 
shown .

Thanks for the great support!

Clara




El lunes, 15 de diciembre de 2014 15:06:56 UTC-3, clara escribió:
>
> Hello Anthony,
>
> Thanks for your patience :)
>
> Here is the code:
>
> *MODEL*
>
> db.define_table('t_owner',
> Field('f_name', type='string', label=T('Name')), 
> Field('f_lastname', type='string', label=T('Lastname')),auth.signature,
> format='%(f_name)s',
> migrate=settings.migrate)
>
> db.define_table('t_pet',
> Field('f_name', type='string', label=T('Name')),
> Field('f_animal', type='string', label=T('Animal')),
> Field('f_breed', type='string', label=T('Breed')),
> Field('f_owner', type='reference t_owner', label=T('Owner')),
> auth.signature,
> format='%(f_name)s',
> migrate=settings.migrate)
>
> *COMPONENT ACTION*
> @auth.requires_login()
> def pet_component():
> itemid = request.args[0]
> q = db.t_pet.f_owner == itemid
> db.t_pet.f_owner.default = itemid
> db.t_pet.f_owner.writable = False
> form = SQLFORM.grid(q,args=request.args[:1],csv=False)
> return locals()
>
> *pet_component.load : *
> 
> {{=form}}
> 
>
> *ACTION THAT USES THE COMPONENT:*
> @auth.requires_login()
> def all_manage():
> owner_forms =[]
> ids = []
> qowner = db.t_owner.id>0
> owners = db(qowner).select()
> for i,el in enumerate(owners):
> owner_forms.append(SQLFORM.grid(db.t_owner.id==el.id, 
> fields=[db.t_owner.f_name,db.t_owner.f_lastname],sortable=False,details=False,create=False,
>  
> searchable=False,csv=False,deletable=False,editable=False))
> ids.append(el.id) 
> return locals()
>
> *all_manage.html view:*
> {{extend 'layout.html'}}
>
> All Manage
> {{for i,el in enumerate(owner_forms):}}
> {{=el}}
> {{ids[i]}}
> {{=LOAD('default','pet_component.load',args=ids[i], ajax=True)}}
> {{pass}}
>
> Let me know if you find something. Thanks a lot.
>
> Clara
>
>
>
>
> On Mon, Dec 15, 2014 at 2:50 PM, Anthony  wrote:
>>
>> Probably need to see the code.
>>
>> On Monday, December 15, 2014 12:36:16 PM UTC-5, clara wrote:
>>>
>>> Hello Anthony,
>>>
>>> It did work!!! Thanks ! 
>>>
>>> Now, something does not work well when adding records into the grid 
>>> component: I restrict the "owner" so that the record should be appended to 
>>> the same grid. Now I enter the record, it gets recorded successfully but 
>>> the grid (in which I added the record) updates to the largest ID (it looks 
>>> like the last grid in the view). If I refresh the view, everything is in 
>>> order. Do I need to do something else? Could this be a bug?
>>>
>>> I can send the code in if needed. Thanks again for the great support.
>>>
>>> Clara
>>>
>>>
>>>
>>> El lunes, 15 de diciembre de 2014 12:19:36 UTC-3, Anthony escribió:

 The way you're doing it (with the adjustment I suggested) should work. 
 Are you still having problems?

 Anthony

 On Monday, December 15, 2014 9:25:27 AM UTC-5, clara wrote:
>
> Hello Anthony,
>
> Thanks for your reply. I am trying to pass *itemid* to the component. 
> How do I do that?
>
> Basically imagine a model like>
> db.define_table('person',
> Field('firstname'),
> Field('lastname'), format='%(firstname)s %(lastname)s'
> )
> db.define_table('dog',
> Field('name'),
> Field('owner',db.person))
>
> and what I want to generate is a view where there is every person 
> listed and each person has a grid below with the dogs it owns. I figured 
> components would be the best approach, but I don't know how to pass a 
> parameter (the owner ID, for the example model) to the component. 
>
> Thanks,
>
> Clara
>
>
> El domingo, 14 de diciembre de 2014 23:43:24 UTC-3, Anthony escribió:
>>
>> The grid makes use of URL args, so if the base URL of the grid action 
>> also includes args, you must tell the grid to preserve those extra-grid 
>> args via its "args" argument:
>>
>> form = SQLFORM.grid(db.address.client == itemid, args=request.args[:1
>> ])
>>
>> Anthony
>>
>> On Sunday, December 14, 2014 2:54:06 PM UTC-5, clara 

[web2py] removing items from cache not working

2014-12-15 Thread Alex


I've got a function which returns a dict with some values. the function has 
this decorator:

@cache('admin.setting.limits', 3600, cache.ram)

def get_limits():
..


This works fine and the values are used from cache. When I change those 
settings I want to clear the cache so I'm doing this:

cache.ram.clear(regex='admin\.setting.*')

When I call my function again the cached values are still used. Am I doing 
something wrong here? Any ideas?


regards,

Alex

-- 
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: Domain model and web2py DAL

2014-12-15 Thread Leonel Câmara
Well the DAL already implements the data mapper pattern. The memory 
representation are the tables defined in the models, the persistent 
representation can be anything really, you could make your own adapter. 

As for the "Domain Model Pattern " an easy approximation is using methods 
and virtual fields, if that's not "domain model" enough for you, you can 
use Bruno's model-less approach.

http://www.web2pyslices.com/slice/show/1479/model-less-apps-using-data-models-and-modules-in-web2py
 

Make sure you're not *over-engineering*.

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


Re: [web2py] Re: Cheap trick to achieve intellisense/autocompletion

2014-12-15 Thread Alex
I'm using PyCharm Community Edition. I'm planning to upgrade to the 
Professional Edition (which has web2py support) once they got some annoying 
bugs fixed. At the moment I don't know how good the web2py support is, i.e. 
if it makes your db autocomplete script obsolete or not.


On Monday, December 15, 2014 9:56:30 PM UTC+1, Andrew Buchan wrote:
>
> Excellent, glad someone is using it. Thanks for the heads up on the typo, 
> it's not the version I'm actually using which is why I'll have missed it. 
> Fixed now.
> What IDE are you using btw?
>
> On Mon, Dec 15, 2014 at 8:41 PM, Alex > 
> wrote:
>>
>> thanks! seems to work fine so far. You've got a syntax error in line 38: 
>> ', is missing at the end.
>>
>>
>> Alex
>> -- 
>> 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 a topic in the 
>> Google Groups "web2py-users" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/web2py/aQBsDK_TjB0/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> web2py+un...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

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


[web2py] Re: Thread safety and importing db, response, session

2014-12-15 Thread Anthony
Yes, that should do it.

Anthony

On Monday, December 15, 2014 3:35:01 PM UTC-5, Mark Graves wrote:
>
> Thanks Anthony,
>
> I saw your web2py con talk at depaul and really appreciated your 
> understanding of the inner workings.
>
> Would best practice be to just import current then define db = current.db?
>
> That works correctly as long as it is not a top level variable correct?
>
> -Mark
>
> On Monday, December 15, 2014 9:23:42 AM UTC-6, Anthony wrote:
>>
>> You can also just import current in the module and then refer to it 
>> directly within your function (i.e., no need to pass current as an argument 
>> to the function).
>>
>> Anthony
>>
>> On Sunday, December 14, 2014 11:07:48 PM UTC-5, Mark Graves wrote:
>>>
>>> Right,  I knew it looked too easy.
>>>
>>> Thanks, Anthony!
>>>
>>> Would it be viable to say in models (or controllers):
>>>
>>> from gluon import current
>>> current.db = db
>>>
>>> Then in modules:
>>>
>>> def my_function(current):
>>>  db = current.db
>>>  session = current.session
>>>  request = current.request
>>>  response = current.response
>>>
>>> Then perhaps futher mimic locals with a decorator by returning them to 
>>> the function and/or changing the signature? (Or would that run into the 
>>> same threading problem?
>>>
>>> Trying to avoid repeating myself...
>>>
>>>
>>>
>>>
>>>
>>> On Sunday, December 14, 2014 8:32:55 PM UTC-6, Anthony wrote:

 No, the book warns to avoid that approach: 
 http://www.web2py.com/books/default/chapter/29/04/the-core#Accessing-the-API-from-Python-modules

 You cannot assign the thread local object to a top-level variable in 
 the module, as it will only be assigned once upon first import.

 Anthony

 On Sunday, December 14, 2014 7:32:29 PM UTC-5, Mark Graves wrote:
>
> Hey everyone,
>
> I could use a sanity check here from the community.
>
> In a controller I get a record, then, I want to pass do some database 
> calls from a module.
>
> It seems that the least code I could write would be in models:
>
> from gluon import current
> current.db = db
>
> Then in the module at the top
>
> from gluon import current
> db = current.db
>
> The method I was using was passing the objects in directly to the 
> function defined in the module, but that was overly repetitive.  No 
> classes, just functions.
>
> Can anyone see where I would run into problems? Is this thread safe?
>
> Would it be better to instantiate a class with the handler similar to 
> what I've seen elsewhere regarding model-less apps?
>
> Thanks in advance!
>
> -Mark
>
>
>

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


Re: [web2py] Re: Cheap trick to achieve intellisense/autocompletion

2014-12-15 Thread Andrew Buchan
Excellent, glad someone is using it. Thanks for the heads up on the typo,
it's not the version I'm actually using which is why I'll have missed it.
Fixed now.
What IDE are you using btw?

On Mon, Dec 15, 2014 at 8:41 PM, Alex  wrote:
>
> thanks! seems to work fine so far. You've got a syntax error in line 38:
> ', is missing at the end.
>
>
> Alex
>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/aQBsDK_TjB0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


[web2py] Re: Cheap trick to achieve intellisense/autocompletion

2014-12-15 Thread Alex


thanks! seems to work fine so far. You've got a syntax error in line 38: ', 
is missing at the end.


Alex

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


Re: [web2py] Re: bootstrap 3 - if you care help test trunk now

2014-12-15 Thread Cynthia Butler
@Jim, 
Thank you very much! Just what I needed to learn what I was doing wrong.
( I was deleting the web2py .css and .js files)


On Monday, December 15, 2014 6:48:51 AM UTC-7, Jim S wrote:
>
> Attached is my layout.html...
>
>

-- 
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: Thread safety and importing db, response, session

2014-12-15 Thread Mark Graves
Thanks Anthony,

I saw your web2py con talk at depaul and really appreciated your 
understanding of the inner workings.

Would best practice be to just import current then define db = current.db?

That works correctly as long as it is not a top level variable correct?

-Mark

On Monday, December 15, 2014 9:23:42 AM UTC-6, Anthony wrote:
>
> You can also just import current in the module and then refer to it 
> directly within your function (i.e., no need to pass current as an argument 
> to the function).
>
> Anthony
>
> On Sunday, December 14, 2014 11:07:48 PM UTC-5, Mark Graves wrote:
>>
>> Right,  I knew it looked too easy.
>>
>> Thanks, Anthony!
>>
>> Would it be viable to say in models (or controllers):
>>
>> from gluon import current
>> current.db = db
>>
>> Then in modules:
>>
>> def my_function(current):
>>  db = current.db
>>  session = current.session
>>  request = current.request
>>  response = current.response
>>
>> Then perhaps futher mimic locals with a decorator by returning them to 
>> the function and/or changing the signature? (Or would that run into the 
>> same threading problem?
>>
>> Trying to avoid repeating myself...
>>
>>
>>
>>
>>
>> On Sunday, December 14, 2014 8:32:55 PM UTC-6, Anthony wrote:
>>>
>>> No, the book warns to avoid that approach: 
>>> http://www.web2py.com/books/default/chapter/29/04/the-core#Accessing-the-API-from-Python-modules
>>>
>>> You cannot assign the thread local object to a top-level variable in the 
>>> module, as it will only be assigned once upon first import.
>>>
>>> Anthony
>>>
>>> On Sunday, December 14, 2014 7:32:29 PM UTC-5, Mark Graves wrote:

 Hey everyone,

 I could use a sanity check here from the community.

 In a controller I get a record, then, I want to pass do some database 
 calls from a module.

 It seems that the least code I could write would be in models:

 from gluon import current
 current.db = db

 Then in the module at the top

 from gluon import current
 db = current.db

 The method I was using was passing the objects in directly to the 
 function defined in the module, but that was overly repetitive.  No 
 classes, just functions.

 Can anyone see where I would run into problems? Is this thread safe?

 Would it be better to instantiate a class with the handler similar to 
 what I've seen elsewhere regarding model-less apps?

 Thanks in advance!

 -Mark




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


Re: [web2py] Installation of an editor plugin in web2py app

2014-12-15 Thread Maboroshi
Hey there if I understand correctly you want to not display html but the
formatted output. If so then use this in your view and add any html you
would like to allow.

{{=XML(row.textfromeditor, sanitize=True, permitted_tags=['a', 'b',
'blockquote', 'br', 'i', 'li',
   'ol', 'ul', 'p', 'cite', 'code',
'pre', 'img'],
allowed_attributes={'a':['href', 'title'],
   'img':['src', 'alt'],
'blockquote':['type']})}}



or do this which I highly suggest not doing {{=XML(row.textfromeditor,
sanitize=False)}}

*cheers


On Mon, Dec 15, 2014 at 6:50 AM, Ramashish Gaurav 
wrote:
>
> Dear Andrew,
>
> Many thanks for your response and elaborate explanation of installation of
> ck-editor. However I used another light weight editor nicEdit since the
> installation was pretty easy as directed at http://nicedit.com/ . However
> I am in a problem, not related to installation of editors, but in showing
> of html doc after being saved from the textarea.
>
> The content from the textarea in HTML used with nicEdit, is in html
> format. After getting the html coded text from textarea and saving it in
> database, I need to redisplay it on demand. I tried to use textarea with
> read only mode to display the html text in formatted form, searched for
> hours on internet but with no luck. Textarea always showed the raw html
> code instead of formatted one. Also I read that it can be done via an
> editor only, not textarea. So used nicEdit again, but don't know to use it
> in read only mode. stackoverflow had a post related to the similar problem
> of using nicEdit with disabled edit option, but it did not come to my
> rescue. I implemented the code posted there in answer, but was not able to
> set nicEdit in read only mode. Here is the link.
>
> http://stackoverflow.com/questions/4282446/how-to-set-nicedit-uneditable
>
> If you do know to display the html coded text in formatted way via nicEdit
> or any other way round, I'd appreciate your help.
>
> Here is the code I have implemented:
>
> {{extend 'layout.html'}}
> 
>
> http://js.nicedit.com/nicEdit-latest.js";
> type="text/javascript">
> 
>  type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);
> http://js.nicedit.com/nicEdit-latest.js";>
> // bkLib.onDomLoaded(funtion(){
>   var myNicEditor =
> new nicEditor();
>
> myNicEditor.addInstance("nice");
>
> nicEditors.findEditor("nice").disable();
>});
>
>   //]]> 
>
> 
>
> 
> {{for row in rows:}}
> {{=row.textfromeditor}}
> {{pass}}
>
> 
>
>
> On Monday, December 15, 2014 6:45:52 AM UTC+5:30, Andrew wrote:
>>
>> Your error at this point isn't from ckeditor but you are using a reserved
>> sql keyword in your database table/field. I suggest removing this line
>> *check_reserved=['all']* or change the name of one of the fields/tables
>> in question.
>>
>> As a side reference here is a brief bit of info for implementing
>> ckeditor.
>>
>> I haven't used ckeditor in a long time but if the code remains the same
>> then you can do this.
>>
>> in db.py add:
>>
>> def advanced_editor(field, value):
>> return TEXTAREA(_id = str(field).replace('.','_'), _name=field.name,
>> _class='text ckeditor', value=value, _cols=80, _rows=10)
>>
>> For the text field you use this as an example:
>> Field('body', 'text', widget=advanced_editor))
>>
>> In your template file example layout.html add the path to ckeditor:
>> 
>>
>> Then choose to sanitize or not the input. Depending if other users will
>> submit your form then I would choose to sanitize info:
>>
>> Example sanitized:
>> {{=XML(query.body,sanitize=True,
>> permitted_tags=['a', 'b', 'blockquote', 'br', 'i', 'li',
>>'ol', 'ul', 'p', 'cite',
>> 'code', 'pre', 'img'],
>> allowed_attributes={'a':['href', 'title'],
>>'img':['src', 'alt'],
>> 'blockquote':['type']})}}
>>
>> Example unsanitized: {{=XML(query.body,sanitize=False)}}
>>
>> you can choose what values you will allow to be displayed for that form
>> code in the ckeditor config. I don't remember if there is anything you need
>> to do in the controller files but looking at code I don't believe so.
>>
>> *cheers!
>>
>> On Wed, Dec 10, 2014 at 10:50 PM, Ramashish Gaurav 
>> wrote:
>>
>>>
>>> Hi all !
>>>
>>> First of all, I am a newbie in web2py.
>>> I am working on a project and need to install an editor plugin in my
>>> web2py app named "editor". After hours of search I got ck_editor4 plugin
>>>  ,
>>> installed it and then made some changes in models and views of my
>>> application. Changes were made in :
>>>
>>> 1:   editor/models/db1.py
>>> Contents are :
>>>
>>> # -*- codin

Re: [web2py] Re: Web2py Debug Error

2014-12-15 Thread Mariano Reingart
Hi Shaun:

There seems to be an issue with the latest changes in DAL (__all__ was
removed from gluon.dal).

To fix it, in /web2py/applications/admin/controllers/debug.py you should
remove the last condition from line 75/76:

  and \
name not in gluon.dal.__dict__:

Anyway, this is just a cosmetic patch (as it filters the names to show in
the locals  variables pane), once fixed, it should not affect normal
behavior of the debugger.
As the __all__ variable exposes the exported module names  (originally DAL,
Field), it could be replaced it with __dict__, but that could be dangerous
as DAL now exports many other names that could collide with common valid
ones (base, connection, etc).

I made a patch / PR fixing this issue in next versions:

https://github.com/web2py/web2py/pull/559

Let me know if you find any other issue with the debugger, I didn't have
time to work lately, but I'm planing to revamp somethings in the next
months.

Best regards,


Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com

On Mon, Dec 15, 2014 at 5:35 AM, Shaun Smith  wrote:
>
> Hi
>
> The Debug feature however still does not work on my *debian* system:
>
> Setting a breakpoint at line 13 of '*default.py*' of the attached '
> *web2py.app.app2(1).w2p*' package and refreshing the application seems to
> hang.
> Opening the 'Debug' feature gives:
> Internal error, Ticket issued:
> admin/127.0.0.1.2014-12-15.10-24-04.ca400024-1983-4af8-a9e9-952ac27c58e9
> 
> .
>
> Clicking on the ticket gives
> Error ticket for "admin", and
>  'module' object has no attribute
> '__all__'
>
> as per the attached 'debug_ticket.html'.
> Please advise how I could resolve this issue.
>
> Kind Regards
> Shaun
>
> On Friday, December 12, 2014 11:06:04 AM UTC+2, Shaun Smith wrote:
>
>> Hi
>>
>> I am a new user to web2py and am trying to use the debug feature. I have
>> attached the 'app1' application package ('web2py.app.app1w2p). When I run
>> it it runs as expected.
>>
>> However the action of setting a breakpoint in line 11 of "*default.py*"
>> gives the response
>> "[14968:14968:1212/105253:ERROR:CONSOLE(248)] "Uncaught TypeError:
>> undefined is not a function", source: https://apis.google.com/_/scs/
>> abc-static/_/js/k=gapi.gapi.en.mDMl48C7FR8.O/m=iframes,
>> googleapis_client/rt=j/d=1/rs=AItRSTOveVmyqj7FQViAq5Q-ZAhF4tZ22g (248)"
>> in my *Debian* terminal and my application seems to hang.
>>
>> When I click on the *Debug* option I get the response '*Internal error*',
>> Ticket issued: admin/127.0.0.1.2014-12-12.10-
>> 56-26.75180abc-a962-4c49-a76b-1e4a59892fe8
>> .
>> Clicking on this ticket link gives
>> *Error ticket for "admin"*,  'module'
>> object has no attribute '__all__', (accompanying ticket information file
>> 'ticket_admin.html').
>>
>> Can anyone perhaps advise how I can resolve this problem?
>>
>> Kind Regards
>> Shaun
>>
>>
>>
>>  --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [web2py] Re: Component with argument example

2014-12-15 Thread Clara Ferrando
Hello Anthony,

Thanks for your patience :)

Here is the code:

*MODEL*

db.define_table('t_owner',
Field('f_name', type='string', label=T('Name')),
Field('f_lastname', type='string', label=T('Lastname')),auth.signature,
format='%(f_name)s',
migrate=settings.migrate)

db.define_table('t_pet',
Field('f_name', type='string', label=T('Name')),
Field('f_animal', type='string', label=T('Animal')),
Field('f_breed', type='string', label=T('Breed')),
Field('f_owner', type='reference t_owner', label=T('Owner')),
auth.signature,
format='%(f_name)s',
migrate=settings.migrate)

*COMPONENT ACTION*
@auth.requires_login()
def pet_component():
itemid = request.args[0]
q = db.t_pet.f_owner == itemid
db.t_pet.f_owner.default = itemid
db.t_pet.f_owner.writable = False
form = SQLFORM.grid(q,args=request.args[:1],csv=False)
return locals()

*pet_component.load : *

{{=form}}


*ACTION THAT USES THE COMPONENT:*
@auth.requires_login()
def all_manage():
owner_forms =[]
ids = []
qowner = db.t_owner.id>0
owners = db(qowner).select()
for i,el in enumerate(owners):
owner_forms.append(SQLFORM.grid(db.t_owner.id==el.id,
fields=[db.t_owner.f_name,db.t_owner.f_lastname],sortable=False,details=False,create=False,
searchable=False,csv=False,deletable=False,editable=False))
ids.append(el.id)
return locals()

*all_manage.html view:*
{{extend 'layout.html'}}

All Manage
{{for i,el in enumerate(owner_forms):}}
{{=el}}
{{ids[i]}}
{{=LOAD('default','pet_component.load',args=ids[i], ajax=True)}}
{{pass}}

Let me know if you find something. Thanks a lot.

Clara




On Mon, Dec 15, 2014 at 2:50 PM, Anthony  wrote:
>
> Probably need to see the code.
>
> On Monday, December 15, 2014 12:36:16 PM UTC-5, clara wrote:
>>
>> Hello Anthony,
>>
>> It did work!!! Thanks !
>>
>> Now, something does not work well when adding records into the grid
>> component: I restrict the "owner" so that the record should be appended to
>> the same grid. Now I enter the record, it gets recorded successfully but
>> the grid (in which I added the record) updates to the largest ID (it looks
>> like the last grid in the view). If I refresh the view, everything is in
>> order. Do I need to do something else? Could this be a bug?
>>
>> I can send the code in if needed. Thanks again for the great support.
>>
>> Clara
>>
>>
>>
>> El lunes, 15 de diciembre de 2014 12:19:36 UTC-3, Anthony escribió:
>>>
>>> The way you're doing it (with the adjustment I suggested) should work.
>>> Are you still having problems?
>>>
>>> Anthony
>>>
>>> On Monday, December 15, 2014 9:25:27 AM UTC-5, clara wrote:

 Hello Anthony,

 Thanks for your reply. I am trying to pass *itemid* to the component.
 How do I do that?

 Basically imagine a model like>
 db.define_table('person',
 Field('firstname'),
 Field('lastname'), format='%(firstname)s %(lastname)s')
 db.define_table('dog',
 Field('name'),
 Field('owner',db.person))

 and what I want to generate is a view where there is every person
 listed and each person has a grid below with the dogs it owns. I figured
 components would be the best approach, but I don't know how to pass a
 parameter (the owner ID, for the example model) to the component.

 Thanks,

 Clara


 El domingo, 14 de diciembre de 2014 23:43:24 UTC-3, Anthony escribió:
>
> The grid makes use of URL args, so if the base URL of the grid action
> also includes args, you must tell the grid to preserve those extra-grid
> args via its "args" argument:
>
> form = SQLFORM.grid(db.address.client == itemid, args=request.args[:1
> ])
>
> Anthony
>
> On Sunday, December 14, 2014 2:54:06 PM UTC-5, clara wrote:
>>
>> Hello,
>>
>> I would like to see an example of a component with an argument. I
>> tried it with no luck, If I define the component without arguments it 
>> works
>> fine but if I add an argument loading the page that has the component 
>> leads
>> to some kind of infinite recursion. Any help on this would be 
>> appreciated.
>> To be more explicit:
>>
>> in the controller:
>> @auth.requires_login()
>> def component_action():
>> itemid = request.args(0)
>> form = SQLFORM.grid(db.address.client==itemid)
>> return dict(form=form)
>>
>> in views:
>> I create a "component_action.load":
>>
>> 
>> {{=form}}
>> 
>>
>> I use the component in another action adding to the action's HTML:
>> {{=LOAD('default','component_action.load',args=2, ajax=True)}}
>>
>> Is there anything awefully wrong in this?
>>
>> I will appreciate your help. Thanks!
>>
>> Clara
>>
>>
>>  --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - h

[web2py] Re: Component with argument example

2014-12-15 Thread Anthony
Probably need to see the code.

On Monday, December 15, 2014 12:36:16 PM UTC-5, clara wrote:
>
> Hello Anthony,
>
> It did work!!! Thanks ! 
>
> Now, something does not work well when adding records into the grid 
> component: I restrict the "owner" so that the record should be appended to 
> the same grid. Now I enter the record, it gets recorded successfully but 
> the grid (in which I added the record) updates to the largest ID (it looks 
> like the last grid in the view). If I refresh the view, everything is in 
> order. Do I need to do something else? Could this be a bug?
>
> I can send the code in if needed. Thanks again for the great support.
>
> Clara
>
>
>
> El lunes, 15 de diciembre de 2014 12:19:36 UTC-3, Anthony escribió:
>>
>> The way you're doing it (with the adjustment I suggested) should work. 
>> Are you still having problems?
>>
>> Anthony
>>
>> On Monday, December 15, 2014 9:25:27 AM UTC-5, clara wrote:
>>>
>>> Hello Anthony,
>>>
>>> Thanks for your reply. I am trying to pass *itemid* to the component. 
>>> How do I do that?
>>>
>>> Basically imagine a model like>
>>> db.define_table('person',
>>> Field('firstname'),
>>> Field('lastname'), format='%(firstname)s %(lastname)s')
>>> db.define_table('dog',
>>> Field('name'),
>>> Field('owner',db.person))
>>>
>>> and what I want to generate is a view where there is every person listed 
>>> and each person has a grid below with the dogs it owns. I figured 
>>> components would be the best approach, but I don't know how to pass a 
>>> parameter (the owner ID, for the example model) to the component. 
>>>
>>> Thanks,
>>>
>>> Clara
>>>
>>>
>>> El domingo, 14 de diciembre de 2014 23:43:24 UTC-3, Anthony escribió:

 The grid makes use of URL args, so if the base URL of the grid action 
 also includes args, you must tell the grid to preserve those extra-grid 
 args via its "args" argument:

 form = SQLFORM.grid(db.address.client == itemid, args=request.args[:1])

 Anthony

 On Sunday, December 14, 2014 2:54:06 PM UTC-5, clara wrote:
>
> Hello,
>
> I would like to see an example of a component with an argument. I 
> tried it with no luck, If I define the component without arguments it 
> works 
> fine but if I add an argument loading the page that has the component 
> leads 
> to some kind of infinite recursion. Any help on this would be 
> appreciated. 
> To be more explicit:
>
> in the controller: 
> @auth.requires_login()
> def component_action():
> itemid = request.args(0)
> form = SQLFORM.grid(db.address.client==itemid)
> return dict(form=form)
>
> in views:
> I create a "component_action.load":
>
> 
> {{=form}}
> 
>
> I use the component in another action adding to the action's HTML:
> {{=LOAD('default','component_action.load',args=2, ajax=True)}}
>
> Is there anything awefully wrong in this?
>
> I will appreciate your help. Thanks!
>
> Clara
>
>
>

-- 
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: Component with argument example

2014-12-15 Thread clara
Hello Anthony,

It did work!!! Thanks ! 

Now, something does not work well when adding records into the grid 
component: I restrict the "owner" so that the record should be appended to 
the same grid. Now I enter the record, it gets recorded successfully but 
the grid (in which I added the record) updates to the largest ID (it looks 
like the last grid in the view). If I refresh the view, everything is in 
order. Do I need to do something else? Could this be a bug?

I can send the code in if needed. Thanks again for the great support.

Clara



El lunes, 15 de diciembre de 2014 12:19:36 UTC-3, Anthony escribió:
>
> The way you're doing it (with the adjustment I suggested) should work. Are 
> you still having problems?
>
> Anthony
>
> On Monday, December 15, 2014 9:25:27 AM UTC-5, clara wrote:
>>
>> Hello Anthony,
>>
>> Thanks for your reply. I am trying to pass *itemid* to the component. 
>> How do I do that?
>>
>> Basically imagine a model like>
>> db.define_table('person',
>> Field('firstname'),
>> Field('lastname'), format='%(firstname)s %(lastname)s')
>> db.define_table('dog',
>> Field('name'),
>> Field('owner',db.person))
>>
>> and what I want to generate is a view where there is every person listed 
>> and each person has a grid below with the dogs it owns. I figured 
>> components would be the best approach, but I don't know how to pass a 
>> parameter (the owner ID, for the example model) to the component. 
>>
>> Thanks,
>>
>> Clara
>>
>>
>> El domingo, 14 de diciembre de 2014 23:43:24 UTC-3, Anthony escribió:
>>>
>>> The grid makes use of URL args, so if the base URL of the grid action 
>>> also includes args, you must tell the grid to preserve those extra-grid 
>>> args via its "args" argument:
>>>
>>> form = SQLFORM.grid(db.address.client == itemid, args=request.args[:1])
>>>
>>> Anthony
>>>
>>> On Sunday, December 14, 2014 2:54:06 PM UTC-5, clara wrote:

 Hello,

 I would like to see an example of a component with an argument. I tried 
 it with no luck, If I define the component without arguments it works fine 
 but if I add an argument loading the page that has the component leads to 
 some kind of infinite recursion. Any help on this would be appreciated. To 
 be more explicit:

 in the controller: 
 @auth.requires_login()
 def component_action():
 itemid = request.args(0)
 form = SQLFORM.grid(db.address.client==itemid)
 return dict(form=form)

 in views:
 I create a "component_action.load":

 
 {{=form}}
 

 I use the component in another action adding to the action's HTML:
 {{=LOAD('default','component_action.load',args=2, ajax=True)}}

 Is there anything awefully wrong in this?

 I will appreciate your help. Thanks!

 Clara




-- 
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: ERR_CACHE_MISS while working with SQLFORM.factory()

2014-12-15 Thread Ramashish Gaurav
Thanks a lot for clarifying my doubts. You were indeed helpful.

On Monday, December 15, 2014 9:02:45 PM UTC+5:30, Anthony wrote:
>
> Given your code, I would expect the browser warning after successful 
> submission whether or not it was preceded by an earlier form validation 
> error.
>
> Also, note that when you hit the back button, it is not a GET request -- 
> rather, it is a repeat of the previous request (which in this case was a 
> POST request, which is what causes the warning -- you are asking the 
> browser to repeat an earlier POST request).
>
> Anthony
>
> On Monday, December 15, 2014 9:18:11 AM UTC-5, Ramashish Gaurav wrote:
>>
>> Dear Anthony,
>>
>> Thanks for your response.
>>
>> I am planning to implement your advice to redirect to the same form 
>> submission page, with a link for redirecting to other page after form 
>> submission. In case of an issue, I'll let you know. 
>>
>> However one thing is still unclear to me. Yeh, you indeed figured out a 
>> solution to prevent ERR_CACHE_MISS, but why does it occurs only after 
>> submission of a wrong entry followed by submission of correct entry, and 
>> not in the case of submitting a correct entry right at the first attempt of 
>> form submission?
>>
>> I do understand that clicking browsers back button is a GET request which 
>> in my case tries to retrieve a form made for POST request, thus creating an 
>> error.
>>
>> On Sunday, December 14, 2014 10:32:51 PM UTC+5:30, Anthony wrote:
>>>
>>> Ideally, hitting the back button in the browser after a form submission 
>>> is not a common workflow in your app. If it is, you probably need to come 
>>> up with an alternative.
>>>
>>> Using a GET request is not a good idea if POST is the appropriate HTTP 
>>> verb (e.g., if submitting the form results in changes on the server, you 
>>> don't want to use a GET request, which might be repeated without warning 
>>> when hitting the back button). An alternative is to simply do a redirect 
>>> back to the same page right after successful form submission (possibly 
>>> followed by another redirect to the "other" page if necessary). The 
>>> redirect back to the same page will cause the page to load a blank form via 
>>> GET before the ultimate redirect, so if the back button is hit, it will 
>>> reload the GET request rather than the previous POST request.
>>>
>>> Anthony
>>>
>>> On Sunday, December 14, 2014 7:49:26 AM UTC-5, Ramashish Gaurav wrote:

 Thanks for the response.

 So can we remove this warning while still using SQLFORM.factory() ? . 
 Actually in this mailing list, I read one post regarding the same error, 
 where a form was generated via HTML and "method" was set as "get" instead 
 of "post", to remove the same warning. You may wanna go through this post:


 https://groups.google.com/forum/?hl=en#!searchin/web2py/ERR_CACHE_MISS/web2py/iqpamJNOvn4/h12NBjBXCvQJ

 Perhaps I have to change the way of form generation and submission. 
 Please take a look into it.

 On Sunday, December 14, 2014 6:07:30 PM UTC+5:30, Niphlod wrote:
>
> it's standard behaviour for modern browsers. You can't go back to 
> something that was generated by a POST (the form submission) without a 
> warning, because it's like having the form submitted twice (POST isn't 
> idempotent).
>


-- 
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] SQLFORM.factory with upload field - the operation is insecure

2014-12-15 Thread Jim S
I've got an issue that is really puzzling me.

I have a form, SQLFORM.factory with one field, an upload field.

When I click on submit to submit the form (adding a new record), I get a 
javascript error that flashes by quickly in Firebug.  All I can get from it 
is that the text says 'the operation is insecure'.

Here is the controller code:

@auth.requires_permission('select', db.helpdesk)
def attachments():
ticket_id = request.vars['ticketId']
ticket = db.ticket(ticket_id)


updateQuery = db.ticket_attachment.ticket==ticket_id


form = SQLFORM.factory(Field('attachment_file', 'upload', required=True,
 uploadfolder='%s/tickets' % (connect_util.
getFileLocation('uploads'))),
   table_name='ticket_attachment', submit_button=
'Add', formstyle=my_formstyle, ui=grid_ui,
   formname='attachment_form', _id='attachment_form'
)


if form.process(formname='attachment_form').accepted:
attachment = form.vars.attachment_file
db.ticket_attachment.insert(ticket=ticket_id, attachment=attachment)


ticket_notification(ticket_id, 'new tag added',
'Tag %s added.' % (helpdesk_tag.tag),
log_activity=True)
else:
print 'err'


Here is the view


function delete_attachment(ticket_attachment_id) {
$.ajax({url: 
"{{=URL('ticket','delete_ticket_attachment',user_signature=True)}}",
data: {ticket_attachment_id:ticket_attachment_id }})
.fail(function() {
alert('There was a problem removing the attachment from this 
ticket.  Please contact support.');
})
.success(function(msg) {
location.reload();
});
}



{{=form.custom.begin}}

{{=form.custom.widget.attachment_file}}
{{=form.custom.submit}}

{{=form.custom.end}}

{{for attachment in ticket_attachments:}}


{{=attachment.attachment}}

{{if can_delete:}}



{{pass}}

{{pass}}




Any ideas on what may be causing this or how to capture the javascript 
error?

-Jim



-- 
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: ERR_CACHE_MISS while working with SQLFORM.factory()

2014-12-15 Thread Anthony
Given your code, I would expect the browser warning after successful 
submission whether or not it was preceded by an earlier form validation 
error.

Also, note that when you hit the back button, it is not a GET request -- 
rather, it is a repeat of the previous request (which in this case was a 
POST request, which is what causes the warning -- you are asking the 
browser to repeat an earlier POST request).

Anthony

On Monday, December 15, 2014 9:18:11 AM UTC-5, Ramashish Gaurav wrote:
>
> Dear Anthony,
>
> Thanks for your response.
>
> I am planning to implement your advice to redirect to the same form 
> submission page, with a link for redirecting to other page after form 
> submission. In case of an issue, I'll let you know. 
>
> However one thing is still unclear to me. Yeh, you indeed figured out a 
> solution to prevent ERR_CACHE_MISS, but why does it occurs only after 
> submission of a wrong entry followed by submission of correct entry, and 
> not in the case of submitting a correct entry right at the first attempt of 
> form submission?
>
> I do understand that clicking browsers back button is a GET request which 
> in my case tries to retrieve a form made for POST request, thus creating an 
> error.
>
> On Sunday, December 14, 2014 10:32:51 PM UTC+5:30, Anthony wrote:
>>
>> Ideally, hitting the back button in the browser after a form submission 
>> is not a common workflow in your app. If it is, you probably need to come 
>> up with an alternative.
>>
>> Using a GET request is not a good idea if POST is the appropriate HTTP 
>> verb (e.g., if submitting the form results in changes on the server, you 
>> don't want to use a GET request, which might be repeated without warning 
>> when hitting the back button). An alternative is to simply do a redirect 
>> back to the same page right after successful form submission (possibly 
>> followed by another redirect to the "other" page if necessary). The 
>> redirect back to the same page will cause the page to load a blank form via 
>> GET before the ultimate redirect, so if the back button is hit, it will 
>> reload the GET request rather than the previous POST request.
>>
>> Anthony
>>
>> On Sunday, December 14, 2014 7:49:26 AM UTC-5, Ramashish Gaurav wrote:
>>>
>>> Thanks for the response.
>>>
>>> So can we remove this warning while still using SQLFORM.factory() ? . 
>>> Actually in this mailing list, I read one post regarding the same error, 
>>> where a form was generated via HTML and "method" was set as "get" instead 
>>> of "post", to remove the same warning. You may wanna go through this post:
>>>
>>>
>>> https://groups.google.com/forum/?hl=en#!searchin/web2py/ERR_CACHE_MISS/web2py/iqpamJNOvn4/h12NBjBXCvQJ
>>>
>>> Perhaps I have to change the way of form generation and submission. 
>>> Please take a look into it.
>>>
>>> On Sunday, December 14, 2014 6:07:30 PM UTC+5:30, Niphlod wrote:

 it's standard behaviour for modern browsers. You can't go back to 
 something that was generated by a POST (the form submission) without a 
 warning, because it's like having the form submitted twice (POST isn't 
 idempotent).

>>>

-- 
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: Thread safety and importing db, response, session

2014-12-15 Thread Anthony
You can also just import current in the module and then refer to it 
directly within your function (i.e., no need to pass current as an argument 
to the function).

Anthony

On Sunday, December 14, 2014 11:07:48 PM UTC-5, Mark Graves wrote:
>
> Right,  I knew it looked too easy.
>
> Thanks, Anthony!
>
> Would it be viable to say in models (or controllers):
>
> from gluon import current
> current.db = db
>
> Then in modules:
>
> def my_function(current):
>  db = current.db
>  session = current.session
>  request = current.request
>  response = current.response
>
> Then perhaps futher mimic locals with a decorator by returning them to the 
> function and/or changing the signature? (Or would that run into the same 
> threading problem?
>
> Trying to avoid repeating myself...
>
>
>
>
>
> On Sunday, December 14, 2014 8:32:55 PM UTC-6, Anthony wrote:
>>
>> No, the book warns to avoid that approach: 
>> http://www.web2py.com/books/default/chapter/29/04/the-core#Accessing-the-API-from-Python-modules
>>
>> You cannot assign the thread local object to a top-level variable in the 
>> module, as it will only be assigned once upon first import.
>>
>> Anthony
>>
>> On Sunday, December 14, 2014 7:32:29 PM UTC-5, Mark Graves wrote:
>>>
>>> Hey everyone,
>>>
>>> I could use a sanity check here from the community.
>>>
>>> In a controller I get a record, then, I want to pass do some database 
>>> calls from a module.
>>>
>>> It seems that the least code I could write would be in models:
>>>
>>> from gluon import current
>>> current.db = db
>>>
>>> Then in the module at the top
>>>
>>> from gluon import current
>>> db = current.db
>>>
>>> The method I was using was passing the objects in directly to the 
>>> function defined in the module, but that was overly repetitive.  No 
>>> classes, just functions.
>>>
>>> Can anyone see where I would run into problems? Is this thread safe?
>>>
>>> Would it be better to instantiate a class with the handler similar to 
>>> what I've seen elsewhere regarding model-less apps?
>>>
>>> Thanks in advance!
>>>
>>> -Mark
>>>
>>>
>>>

-- 
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] Maximum size session variable

2014-12-15 Thread Richard D
Hi,

We have strange behaviour (e.g. message: 'memory error') while using large 
(>1MB) session variables.
Is there a limit to session variables?

Thank you 
Richard

-- 
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: Component with argument example

2014-12-15 Thread Anthony
The way you're doing it (with the adjustment I suggested) should work. Are 
you still having problems?

Anthony

On Monday, December 15, 2014 9:25:27 AM UTC-5, clara wrote:
>
> Hello Anthony,
>
> Thanks for your reply. I am trying to pass *itemid* to the component. How 
> do I do that?
>
> Basically imagine a model like>
> db.define_table('person',
> Field('firstname'),
> Field('lastname'), format='%(firstname)s %(lastname)s')
> db.define_table('dog',
> Field('name'),
> Field('owner',db.person))
>
> and what I want to generate is a view where there is every person listed 
> and each person has a grid below with the dogs it owns. I figured 
> components would be the best approach, but I don't know how to pass a 
> parameter (the owner ID, for the example model) to the component. 
>
> Thanks,
>
> Clara
>
>
> El domingo, 14 de diciembre de 2014 23:43:24 UTC-3, Anthony escribió:
>>
>> The grid makes use of URL args, so if the base URL of the grid action 
>> also includes args, you must tell the grid to preserve those extra-grid 
>> args via its "args" argument:
>>
>> form = SQLFORM.grid(db.address.client == itemid, args=request.args[:1])
>>
>> Anthony
>>
>> On Sunday, December 14, 2014 2:54:06 PM UTC-5, clara wrote:
>>>
>>> Hello,
>>>
>>> I would like to see an example of a component with an argument. I tried 
>>> it with no luck, If I define the component without arguments it works fine 
>>> but if I add an argument loading the page that has the component leads to 
>>> some kind of infinite recursion. Any help on this would be appreciated. To 
>>> be more explicit:
>>>
>>> in the controller: 
>>> @auth.requires_login()
>>> def component_action():
>>> itemid = request.args(0)
>>> form = SQLFORM.grid(db.address.client==itemid)
>>> return dict(form=form)
>>>
>>> in views:
>>> I create a "component_action.load":
>>>
>>> 
>>> {{=form}}
>>> 
>>>
>>> I use the component in another action adding to the action's HTML:
>>> {{=LOAD('default','component_action.load',args=2, ajax=True)}}
>>>
>>> Is there anything awefully wrong in this?
>>>
>>> I will appreciate your help. Thanks!
>>>
>>> Clara
>>>
>>>
>>>

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


Re: [web2py] Installation of an editor plugin in web2py app

2014-12-15 Thread Ramashish Gaurav
Dear Andrew,

Many thanks for your response and elaborate explanation of installation of 
ck-editor. However I used another light weight editor nicEdit since the 
installation was pretty easy as directed at http://nicedit.com/ . However I 
am in a problem, not related to installation of editors, but in showing of 
html doc after being saved from the textarea.

The content from the textarea in HTML used with nicEdit, is in html format. 
After getting the html coded text from textarea and saving it in database, 
I need to redisplay it on demand. I tried to use textarea with read only 
mode to display the html text in formatted form, searched for hours on 
internet but with no luck. Textarea always showed the raw html code instead 
of formatted one. Also I read that it can be done via an editor only, not 
textarea. So used nicEdit again, but don't know to use it in read only 
mode. stackoverflow had a post related to the similar problem of using 
nicEdit with disabled edit option, but it did not come to my rescue. I 
implemented the code posted there in answer, but was not able to set 
nicEdit in read only mode. Here is the link.

http://stackoverflow.com/questions/4282446/how-to-set-nicedit-uneditable

If you do know to display the html coded text in formatted way via nicEdit 
or any other way round, I'd appreciate your help.

Here is the code I have implemented:

{{extend 'layout.html'}}


http://js.nicedit.com/nicEdit-latest.js"; 
type="text/javascript">

bkLib.onDomLoaded(nicEditors.allTextAreas);
http://js.nicedit.com/nicEdit-latest.js";>
// 




{{for row in rows:}}
{{=row.textfromeditor}}
{{pass}}




On Monday, December 15, 2014 6:45:52 AM UTC+5:30, Andrew wrote:
>
> Your error at this point isn't from ckeditor but you are using a reserved 
> sql keyword in your database table/field. I suggest removing this line 
> *check_reserved=['all']* or change the name of one of the fields/tables 
> in question.
>
> As a side reference here is a brief bit of info for implementing ckeditor. 
>
> I haven't used ckeditor in a long time but if the code remains the same 
> then you can do this.
>
> in db.py add:
>
> def advanced_editor(field, value):
> return TEXTAREA(_id = str(field).replace('.','_'), _name=field.name, 
> _class='text ckeditor', value=value, _cols=80, _rows=10)
>
> For the text field you use this as an example:
> Field('body', 'text', widget=advanced_editor))
>
> In your template file example layout.html add the path to ckeditor:
>  src="{{=URL(request.application,'static','ckeditor/ckeditor.js')}}">
>
> Then choose to sanitize or not the input. Depending if other users will 
> submit your form then I would choose to sanitize info:
>
> Example sanitized: 
> {{=XML(query.body,sanitize=True, permitted_tags=['a', 
> 'b', 'blockquote', 'br', 'i', 'li',
>'ol', 'ul', 'p', 'cite', 
> 'code', 'pre', 'img'],
> allowed_attributes={'a':['href', 'title'],
>'img':['src', 'alt'], 
> 'blockquote':['type']})}}
>
> Example unsanitized: {{=XML(query.body,sanitize=False)}}
>
> you can choose what values you will allow to be displayed for that form 
> code in the ckeditor config. I don't remember if there is anything you need 
> to do in the controller files but looking at code I don't believe so.
>
> *cheers!
>
> On Wed, Dec 10, 2014 at 10:50 PM, Ramashish Gaurav  > wrote:
>>
>>
>> Hi all !
>>
>> First of all, I am a newbie in web2py. 
>> I am working on a project and need to install an editor plugin in my 
>> web2py app named "editor". After hours of search I got ck_editor4 plugin 
>>  , 
>> installed it and then made some changes in models and views of my 
>> application. Changes were made in :
>>
>> 1:   editor/models/db1.py 
>> Contents are :
>>
>> # -*- coding: utf-8 -*-
>> from plugin_ckeditor import CKEditor
>> ckeditor = CKEditor(db)
>> ckeditor.define_tables()
>>
>> db.define_table('content', Field('title', length=255), 
>> Field('public', 'boolean', default=True), 
>> Field('text', 'text', widget=ckeditor.widget) )
>>
>> 2:   editor/views/default/index.html
>> Contents are:
>>
>> {{=ckeditor.edit_in_place('.editable', URL())}}
>>
>> After opening the index page in browser a ticket was raised which says 
>> this:
>>
>> Traceback (most recent call last):
>>   File "gluon/restricted.py", line 224, in restricted
>>   File "

[web2py] Re: Component with argument example

2014-12-15 Thread clara
Hello Anthony,

Thanks for your reply. I am trying to pass *itemid* to the component. How 
do I do that?

Basically imagine a model like>
db.define_table('person',
Field('firstname'),
Field('lastname'), format='%(firstname)s %(lastname)s')
db.define_table('dog',
Field('name'),
Field('owner',db.person))

and what I want to generate is a view where there is every person listed 
and each person has a grid below with the dogs it owns. I figured 
components would be the best approach, but I don't know how to pass a 
parameter (the owner ID, for the example model) to the component. 

Thanks,

Clara


El domingo, 14 de diciembre de 2014 23:43:24 UTC-3, Anthony escribió:
>
> The grid makes use of URL args, so if the base URL of the grid action also 
> includes args, you must tell the grid to preserve those extra-grid args via 
> its "args" argument:
>
> form = SQLFORM.grid(db.address.client == itemid, args=request.args[:1])
>
> Anthony
>
> On Sunday, December 14, 2014 2:54:06 PM UTC-5, clara wrote:
>>
>> Hello,
>>
>> I would like to see an example of a component with an argument. I tried 
>> it with no luck, If I define the component without arguments it works fine 
>> but if I add an argument loading the page that has the component leads to 
>> some kind of infinite recursion. Any help on this would be appreciated. To 
>> be more explicit:
>>
>> in the controller: 
>> @auth.requires_login()
>> def component_action():
>> itemid = request.args(0)
>> form = SQLFORM.grid(db.address.client==itemid)
>> return dict(form=form)
>>
>> in views:
>> I create a "component_action.load":
>>
>> 
>> {{=form}}
>> 
>>
>> I use the component in another action adding to the action's HTML:
>> {{=LOAD('default','component_action.load',args=2, ajax=True)}}
>>
>> Is there anything awefully wrong in this?
>>
>> I will appreciate your help. Thanks!
>>
>> Clara
>>
>>
>>

-- 
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: ERR_CACHE_MISS while working with SQLFORM.factory()

2014-12-15 Thread Ramashish Gaurav
Dear Anthony,

Thanks for your response.

I am planning to implement your advice to redirect to the same form 
submission page, with a link for redirecting to other page after form 
submission. In case of an issue, I'll let you know. 

However one thing is still unclear to me. Yeh, you indeed figured out a 
solution to prevent ERR_CACHE_MISS, but why does it occurs only after 
submission of a wrong entry followed by submission of correct entry, and 
not in the case of submitting a correct entry right at the first attempt of 
form submission?

I do understand that clicking browsers back button is a GET request which 
in my case tries to retrieve a form made for POST request, thus creating an 
error.

On Sunday, December 14, 2014 10:32:51 PM UTC+5:30, Anthony wrote:
>
> Ideally, hitting the back button in the browser after a form submission is 
> not a common workflow in your app. If it is, you probably need to come up 
> with an alternative.
>
> Using a GET request is not a good idea if POST is the appropriate HTTP 
> verb (e.g., if submitting the form results in changes on the server, you 
> don't want to use a GET request, which might be repeated without warning 
> when hitting the back button). An alternative is to simply do a redirect 
> back to the same page right after successful form submission (possibly 
> followed by another redirect to the "other" page if necessary). The 
> redirect back to the same page will cause the page to load a blank form via 
> GET before the ultimate redirect, so if the back button is hit, it will 
> reload the GET request rather than the previous POST request.
>
> Anthony
>
> On Sunday, December 14, 2014 7:49:26 AM UTC-5, Ramashish Gaurav wrote:
>>
>> Thanks for the response.
>>
>> So can we remove this warning while still using SQLFORM.factory() ? . 
>> Actually in this mailing list, I read one post regarding the same error, 
>> where a form was generated via HTML and "method" was set as "get" instead 
>> of "post", to remove the same warning. You may wanna go through this post:
>>
>>
>> https://groups.google.com/forum/?hl=en#!searchin/web2py/ERR_CACHE_MISS/web2py/iqpamJNOvn4/h12NBjBXCvQJ
>>
>> Perhaps I have to change the way of form generation and submission. 
>> Please take a look into it.
>>
>> On Sunday, December 14, 2014 6:07:30 PM UTC+5:30, Niphlod wrote:
>>>
>>> it's standard behaviour for modern browsers. You can't go back to 
>>> something that was generated by a POST (the form submission) without a 
>>> warning, because it's like having the form submitted twice (POST isn't 
>>> idempotent).
>>>
>>

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


Re: [web2py] Re: bootstrap 3 - if you care help test trunk now

2014-12-15 Thread Jim Steil
Attached is my layout.html...

On Sun, Dec 14, 2014 at 5:35 AM,  wrote:

>
> 
>
>
> I also had overlay icons, in the auth navbar, as shown. To solve it I had
> to edit gluon/tools.py:1536
>
> def bootstrap3():  # Default web2py scaffolding
> def rename(icon): return icon.replace('icon','glyphicon')
> self.bar = UL(LI(Anr(I(_class=rename('icon '+items[0]['icon'
> ])),
>  ' ' + items[0]['name'],
>  _href=items[0]['href'])),_class=
> 'dropdown-menu')
>
> instead of
>
> def bootstrap3():  # Default web2py scaffolding
> def rename(icon): return icon+' '+icon.replace('icon',
> 'glyphicon')
> self.bar = UL(LI(Anr(I(_class=rename('icon '+items[0]['icon'
> ])),
>  ' ' + items[0]['name'],
>  _href=items[0]['href'])),_class=
> 'dropdown-menu')
>
> There sure are other ways...
>
>
>
>
>  --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/HWZ_4gyUSPo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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







 





{{=response.flash or ''}}



Toggle navigation




QLF CONNECT 




{{=MENU(response.menu, _class='nav navbar-nav navbar-left')}}


{{='auth' in globals() and auth.navbar(mode="dropdown") or ''}}









{{=A(SPAN(response.title[:1].upper(),_style='font-size: 22pt;')+SPAN(response.title[1:].upper(),_style='font-size:18pt;'), _href=URL(response.title.lower(),'index'), _class='sectionHeader')}}
{{=response.subtitle or ''}}



{{include}}









{{if response.google_analytics_id:}}
 {{pass}}





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


[web2py] How to deal with legacy data types at Mysql

2014-12-15 Thread mcamel
I mean, you have to access a preexisting database with boolean stored as 
tinyints, datetime stored as unixtime and so on. You cannot change that.

Focusing on booleans, how to make a simple form work?

At Mysql Test Instance:

CREATE TABLE table1 (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `chk1` tinyint(1) unsigned NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`)
);

INSERT INTO table1 SET chk1=1;

Model:

db = DAL('mysql:', migrate_enabled=False)

db.define_table('table1',
Field('chk1', 'boolean'),
)

Controller:

def checkbox():
form = SQLFORM(db.table1, record=db.table1[1])
form.process().accepted

return dict(form=form)

This gives no error but it doesn't work neither with reads nor with writes. 
Form always generate "chk1=0" when you try to update the record, even if 
you mark the checkbox. DAL expects a varchar field at database with 'T' or 
'F' value, so you'll have this unexpected behaviour.

One solution would be creating a Mysql view (if you have rights to do so) 
that converts tinyint to the expected varchar, but this would work only for 
SELECTs but no with UPDATEs (you cannot update a derived column at mysql):

CREATE VIEW view1
AS SELECT id, IF(chk1=1,'T','F') as chk1 FROM table1;

Then you rewrite model and controller with 'view1' instead of 'table1', and 
you'll see right results with "reads" but error with "writes".

So if you need the form to update the record you can do the conversion at 
web2py level, using 'filter_in' and 'filter_out'. Rewrite model:

db.define_table('table1',
Field('chk1',
  'string', 
  widget = SQLFORM.widgets.boolean.widget,
  filter_in  = lambda x: 1 if x == 'on' else 0,
  filter_out = lambda x: 'on' if x == 1 else None,
)
)

Now it works also for writes.

BUT, it's not trivial at all and probably unstable. I've made lots of 
combinations until i get this working code. Note, for example, that 'T' is 
internally converted to/from 'on' and 'F' to/from None. Besides, you have 
to define field as 'string'. I'm pretty sure this has "colateral effects". 
At least unexpected behaviour with some funcionalities of the framework.

SQLCustomType should work fine with this, but it's marked as experimental 
and it has a related bug with write forms (
https://code.google.com/p/web2py/issues/detail?id=1879).

SO, anyone has a better approach?.


Regards.

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


[web2py] Hyphen in application name

2014-12-15 Thread tim . nyborg
Does anyone know how to get map_hyphen to work with an application name?

I have a routes.py setup as follows:

routers = dict(
   BASE  = dict(
   default_application = "home",
   default_controller = "default",
   default_function = "index",
   map_hyphen=True, 
),
)

In my application (tutor_events), controller and function hyphen mapping 
work fine, so the following paths work:
/tutor_events/default/edit-details/424
/tutor_events/tutor-fee/add

And all URLs are being generated with hyphens

But if I try to go to /tutor-events/..., I get an error: invalid function 
(default/tutor_events)
So web2py is trying to send me on to /home/default/tutor_events

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