Re: [web2py] Re: links in texts stoded in a database

2013-12-27 Thread Jonas Fredriksson
I tried ckeditor and I've got an editor in admin so I can insert links, so
far so good.
but the text is still rendered plain with html tags visible.

my function and db in db.py: (text field is the field I want to insert
links into)

def advanced_editor(field,text):
return TEXTAREA(_id = str(text).replace('.','_'), _name=field.text,
_class='text ckeditor', value=text , _cols=80)

db.define_table('blog',
Field('date','datetime',default=request.now),
Field('image','upload'),
Field('imageTitle','text',default="image text"),
Field('title','text',default='imager text here...'),
Field('text','text',default='blog text
here...',widget=advanced_editor),
Field('votes','integer',default=0),
Field('plus','integer',default=0),
Field('minus','integer',default=0))
#format = '%(title)s')


On Wed, Dec 25, 2013 at 2:53 AM, 黄祥  wrote:

> i think you can achieve it with put the rich text editor in your form input
> ref:
> https://groups.google.com/forum/#!topic/web2py/OoZ1EI8OOmw
>
> another way is with put the html code in your input text area form or
> either use markmin.
> the first is the easiest.
>
> best regards,
> stifan
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/yukzpnZe4GQ/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/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.


Re: [web2py] Re: links in texts stoded in a database

2013-12-29 Thread Jonas Fredriksson
just to clarify, my problem is that html tags in my input text area is just
rendered as tags, naturally because the field is classified as text and
nothing else. I need to render the html elements when displaying text.


On Fri, Dec 27, 2013 at 10:01 PM, Jonas Fredriksson wrote:

> I tried ckeditor and I've got an editor in admin so I can insert links, so
> far so good.
> but the text is still rendered plain with html tags visible.
>
> my function and db in db.py: (text field is the field I want to insert
> links into)
>
> def advanced_editor(field,text):
> return TEXTAREA(_id = str(text).replace('.','_'), _name=field.text,
> _class='text ckeditor', value=text , _cols=80)
>
> db.define_table('blog',
> Field('date','datetime',default=request.now),
> Field('image','upload'),
> Field('imageTitle','text',default="image text"),
> Field('title','text',default='imager text here...'),
> Field('text','text',default='blog text
> here...',widget=advanced_editor),
> Field('votes','integer',default=0),
> Field('plus','integer',default=0),
> Field('minus','integer',default=0))
> #format = '%(title)s')
>
>
> On Wed, Dec 25, 2013 at 2:53 AM, 黄祥  wrote:
>
>> i think you can achieve it with put the rich text editor in your form
>> input
>> ref:
>> https://groups.google.com/forum/#!topic/web2py/OoZ1EI8OOmw
>>
>> another way is with put the html code in your input text area form or
>> either use markmin.
>> the first is the easiest.
>>
>> best regards,
>> stifan
>>
>> --
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "web2py-users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/web2py/yukzpnZe4GQ/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/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.


Re: [web2py] Re: links in texts stoded in a database

2013-12-30 Thread Jonas Fredriksson
the XML function solved the problem:

{{for i, row in enumerate(rows):}}
{{=DIV(XML(T(row.table_field), sanitize = True) ) }}
{{pass}}

thanks.



On Mon, Dec 30, 2013 at 3:29 AM, 黄祥  wrote:

> another way around is define it on the represent for your table text field.
> e.g.
> table.table_field.represent = lambda v, r: XML(v, sanitize = True)
>
> the difference for previous code in this one you can use it for grid
> without define it again on your view.
>
> if you use string type field, yet it can be done with represent also
> e.g.
> table.website.represent = lambda website, field: \
> A(website, _title = T("View Website"), _target = "_blank", _href = "%s" %
> website)
>
> best regards,
> stifan
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/yukzpnZe4GQ/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/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.


Re: [web2py] calling custom javascript functions

2014-01-12 Thread Jonas Fredriksson
I just wanted to see if it's possible to call custom made js functions
using jQuery. I found that it is possible to call by using this function:

  $(document).ready(function() {
  $(function_call());
}

css tags can also be added.

but it is simpler to just use myfunction();

In the web2py book all examples covers jQery effects but I couldn't find
any information about calling custom made js functions.



On Sun, Jan 12, 2014 at 4:41 AM, Anthony  wrote:

> It's not quite clear what you want to do. You wouldn't use ajax to call a
> JavaScript function. If you want to call a JS function in the browser, just
> make sure it is loaded on the page and call it.
>
> Anthony
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/rinBxmv6diM/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/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.


Re: [web2py] calling custom javascript functions

2014-01-12 Thread Jonas Fredriksson
yes, and it works. thanks


On Sun, Jan 12, 2014 at 3:08 PM, Anthony  wrote:

> Did you try:
>
> $(document).ready(function() {
>   myfunction();
> });
>
> Anthony
>
> On Sunday, January 12, 2014 3:48:48 AM UTC-5, jonas wrote:
>
>> I just wanted to see if it's possible to call custom made js functions
>> using jQuery. I found that it is possible to call by using this function:
>>
>>   $(document).ready(function() {
>>   $(function_call());
>> }
>>
>> css tags can also be added.
>>
>> but it is simpler to just use myfunction();
>>
>> In the web2py book all examples covers jQery effects but I couldn't find
>> any information about calling custom made js functions.
>>
>>
>>
>> On Sun, Jan 12, 2014 at 4:41 AM, Anthony  wrote:
>>
>>> It's not quite clear what you want to do. You wouldn't use ajax to call
>>> a JavaScript function. If you want to call a JS function in the browser,
>>> just make sure it is loaded on the page and call it.
>>>
>>> Anthony
>>>
>>> --
>>> Resources:
>>> - http://web2py.com
>>> - http://web2py.com/book (Documentation)
>>> - http://github.com/web2py/web2py (Source code)
>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>> ---
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "web2py-users" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/
>>> topic/web2py/rinBxmv6diM/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/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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/rinBxmv6diM/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/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.


Re: [web2py] Re: controller not returning java script variable correctly

2014-01-15 Thread Jonas Fredriksson
ok, now I undestand what you mean:


def test():

print "called2"
data3=[3, 6, 2, 7, 5, 2, 0, 3, 8, 9, 2, 5, 9, 3, 6, 3, 6, 2, 7, 5, 2,
1, 3, 8, 9, 2, 5, 9, 2, 7]

return 'graph1(%s);' % data3


 ajax('{{=URL('test')}}',[],':eval');
 

graph1 is the actual function, the write function was just for testing.
This works but it means that I have to make a python function for every js
function call when passing values from python functions.



On Wed, Jan 15, 2014 at 5:38 PM, Anthony  wrote:

> Javascript is asynchronous -- the document.write() line will be executed
> before the ajax call has completed. Try putting the document.write() in the
> returned Javascript itself.
>
>
> On Wednesday, January 15, 2014 11:09:04 AM UTC-5, jonas wrote:
>>
>> Hi
>>
>> I have a controller that is supposed to return a list to a js function
>> (for testing purposes):
>>
>> def test():
>>
>> print "called2"
>>
>> data=[3, 6, 2, 7, 5, 2, 0, 3, 8, 9, 2, 5, 9, 3, 6, 3, 6, 2, 7, 5, 2,
>> 1, 3, 8, 9, 2, 5, 9, 2, 7]
>>
>>return 'var data=%s;' % data
>>
>> I am calling this with an ajax function:
>>
>> 
>>  ajax('{{=URL('test')}}',[],':eval');
>>  document.write(data);
>>  
>>
>> but is seems that the data is not present in the script.
>>
>> what went wrong?
>>
>  --
> 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/WQ3geDp_pEo/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/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.


Re: [web2py] Re: controller not returning java script variable correctly

2014-01-15 Thread Jonas Fredriksson
nice solution and it works.

thanks


On Wed, Jan 15, 2014 at 7:34 PM, Anthony  wrote:

> graph1 is the actual function, the write function was just for testing.
>> This works but it means that I have to make a python function for every js
>> function call when passing values from python functions.
>>
>
> You can do this:
>
> def test():
> data = ...
> return '%s(%s);' % (request.args(0), data)
>
> 
>  ajax('{{=URL('default', 'test', args='myjsfunction')}}', [], ':eval');
> 
>
> Just pass the name of the JS function in the URL.
>
> Anthony
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/WQ3geDp_pEo/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/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] difference between crud.select(db.hem,query) and db(query).select()?

2012-06-26 Thread Jonas Fredriksson
hi

When doing results=crud.select(db.hem,query) I got a list containing the 
result with html tags in the beginning and the end. But I am not able to 
access different fields like result.info and so on. When I am using 
 results=db(query).select() I can do results.info. Is there any way to get 
individual fields using crud.select(db.hem,query)?

-- 





Re: [web2py] page min height

2012-11-22 Thread Jonas Fredriksson
Hi. I tried the link and more or less copied the code but the sticky footer 
don't work. especially the push seems not to work. here is my code: 


  

  page header


  span4
  span8


  span10
  span2

  
  



  sticky footer?



On Thursday, November 1, 2012 1:31:11 PM UTC+1, villas wrote:
>
> Hi Richard,  I presume you already saw this?
>
> http://twitter.github.com/bootstrap/examples/sticky-footer.html
>

-- 





Re: [web2py] Re: forms redirect and verification doesn't work

2012-12-05 Thread Jonas Fredriksson
now it works, had to put everything in the right order:

crud.settings.create_next = URL('index')
post=db(db.blog.id==request.args(0)).select().first()
db.comments.post_id.default=post.id
form=crud.create(db.comments)

Thanks again

On Wed, Dec 5, 2012 at 12:55 PM, jonas  wrote:
> Thanks for the reply. I will the section in the book to get a clearer
> understanding of what is happening. Unfortunately both solutions posted here
> didn't work, no redirection or verification.
>
>
> On Monday, December 3, 2012 2:43:23 AM UTC+1, Anthony wrote:
>>
>> Read through the CRUD section of the book again:
>> http://web2py.com/books/default/chapter/29/07#CRUD.
>>
>> Crud automatically handles form processing, so you do not call
>> form.process() after calling crud.create() -- in that case, you are
>> processing the form twice. Instead, crud.create() handles the processing
>> itself. If you want it to redirect, do:
>>
>> crud.settings.create_next = URL('index')
>>
>>
>> as indicated in the book.
>>
>> Anthony
>>
>> On Sunday, December 2, 2012 4:15:51 PM UTC-5, jonas wrote:
>>>
>>> Hi.
>>>
>>> when using the code below redirect and verification doesn't work:
>>>
>>> def comment():
>>>
>>> """ create comment form """
>>>
>>> post=db(db.blog.id==request.args(0)).select().first()
>>> db.comments.post_id.default=post.id
>>> form=crud.create(db.comments)
>>>
>>> if form.process().accepted:
>>> session.flash = T('yes yes')
>>> redirect(URL('index.html'))
>>> else:
>>> print "error"
>>> session.flash = T('no no')
>>> raise HTTP(400, "no form validation")
>>>
>>> return dict(form=form)
>>>
>>> when I remove the if form... else... clause verification works but I
>>> don't have the redirect anymore:
>>>
>>> def comment():
>>>
>>> """ create comment form """
>>>
>>> post=db(db.blog.id==request.args(0)).select().first()
>>> db.comments.post_id.default=post.id
>>> form=crud.create(db.comments)
>>>
>>> return dict(form=form)
>>>
>>> Have no clue why. please help.
>
> --
>
>
>

-- 





Re: [web2py] Re: images not displayed when using img and URL

2012-12-05 Thread Jonas Fredriksson
no I didn't have it. added this:

def download():
return response.download(request, db)

and now it works. thanks

On Wed, Dec 5, 2012 at 6:56 PM, Niphlod  wrote:
> do you have a def download(): in controllers/default.py ?
> That one is the main handler for using URL('default', 'download',
> args=row.something) as a "downloader" of an 'upload' record.
>
>
> On Wednesday, December 5, 2012 6:41:58 PM UTC+1, jonas wrote:
>>
>> hi
>>
>> this is probably a trivial problem but I post it anyway:
>>
>> I have an image model:
>>
>> db.define_table('blog',
>> Field('date','datetime',default=request.now),
>> Field('image','upload'),
>> Field('imageTitle','text',default="image text"),
>> Field('title','text'),
>> Field('text','text'))
>> # format = '%(title)s')
>>
>> and the following controller:
>>
>>   query=db.blog.id>0
>>   res=db(query).select(orderby=~db.blog.date)
>>
>> return dict(res=res)
>>
>> but when I want to display my images they cannot be found:
>>
>> {{for result in res:}}
>>  {{=result.title}}
>> {{=result.date}}
>> {{if result.image:}}
>> if true...
>> > src="{{=URL('download',args=result.image)}}" />
>>  {{=result.imageTitle}}
>> {{pass}}
>> {{pass}}
>>
>> it seems that the img tag looks in the wrong dir: /default/download which
>> doesn't exist. do I have to create it or is there another way?
>
> --
>
>
>

-- 





Re: [web2py] Re: controller that don't returns a view?

2012-12-07 Thread Jonas Fredriksson
Thanks.

Actually the call comes from a button: 

It has to provide the right result.id so the like addition relates to
the right post.
I will try using callbacks from the button call to see if it works.

On Thu, Dec 6, 2012 at 11:17 PM, Niphlod  wrote:
> Learned something also today! Nice one Anthony!
>
>
> On Thursday, December 6, 2012 11:11:05 PM UTC+1, Anthony wrote:
>>
>>
>>> def plus_minus(fakearg=0):
>>> .
>>>
>>
>> Note, rather than using a fake argument to prevent public access, you can
>> also simply start the function name with a double underscore:
>>
>> def __plus_minus():
>>
>> Anthony
>
> --
>
>
>

-- 





Re: [web2py] Re: callback question

2012-12-08 Thread Jonas Fredriksson
Thanks, that solved the callback problem. now I just have to figure
how to update part of the index.html view.

On Sat, Dec 8, 2012 at 4:25 PM, Niphlod  wrote:
> use the power, Luke!
> you have something like this
> A(TAG.i(_class="icon-thumbs-up"), _rel="tooltip", _title="you like this",
> _class="btn", _href=URL("plus",args=result.id))
> and you can turn it into a callback using
> A(TAG.i(_class="icon-thumbs-up"), _rel="tooltip", _title="you like this",
> _class="btn", callback=URL("plus",args=result.id))
>
>
> On Saturday, December 8, 2012 3:42:49 PM UTC+1, jonas wrote:
>>
>> Hi
>>
>> I still have some problems with callbacks. I have a like button that is in
>> my index.html view that add 1 to a database, then displays it:
>>
>> > title="you like this">
>>
>> I want to call the plus function as a callback to avoid render another
>> view, i.e I want to render the result in the index view, but I don't know
>> how to replace  it in the above format. I also have to send the id to the
>> callback.
>>
>> the function:
>>
>> def plus():
>>
>> """ add or subtract likes """
>> print "called",request.args(0)
>> db(db.blog.id==request.args(0)).update(plus=db.blog.plus+1.0)
>> db.commit()
>>
>> #redirect(URL('index'))
>>
> --
>
>
>

-- 





Re: [web2py] Re: calling LOAD from a button

2012-12-14 Thread Jonas Fredriksson
thanks

I use the following solution;

{{for result in res:}}
{{=result.id}}
{{=result.title}}
{{=A(TAG.i(_class="icon-plus-sign"), _rel="tooltip", _title="testing",
_class="btn", _href='#', _onclick="jQuery('#uc').toggle();")}}

  {{=LOAD('default','comment.load',args=result.id,ajax=True)}}


with this I can load the form.
two things remains.
1. I need to close or clear the form so that it is clear that it has
been submitted.
2: I need an unique id for every comment, something like this:


{{a=0}}
{{for comment in com:}}
  {{if comment.post_id==result.id:}}
  {{a=1}}
{{=comment.created_on}}
{{=comment.created_by}}
{{=comment.comment}}
  
  {{pass}}
 {{pass}}

is it possible to create unique id in any other way? the above
solution to add result.id to the id works for displaying comments but
not for displaying forms.

On Tue, Dec 11, 2012 at 4:16 PM, Anthony  wrote:
>>
>> {{=LOAD('default','comment.load',args=result.id,ajax=True,ajax_trap=True,target="userComment")}}
>
>
> Note, the above will load the component immediately when the page is first
> loaded (even if the div is hidden). If you want to delay any loading until
> the link is clicked, you can just create an empty (possibly hidden) div:
>
> 
>
>> than you have a button call an action and refresh a component
>>
>> {{=A('click me', _href=URL('comment.load'), component='target')}}
>
>
> I think the correct syntax here is:
>
> {{=A('click me', component=URL('comment.load'), target='userComment')}}
>
> When the link is clicked, the component will be loaded into the
> "userComment" div (and will be re-loaded upon subsequent clicks).
>
> Anthony
>
> --
>
>
>

-- 





Re: [web2py] Re: custom form validation

2012-12-15 Thread Jonas Fredriksson
ok. another thing is that if I use a regular form, {{=form}}, then
validation works but not if I use the custom form. Also form.process()
works, so the problem seems to be related to custom forms.

On Sat, Dec 15, 2012 at 4:06 AM, Anthony  wrote:
>> form=crud.create(db.comments)
>> if form.process().accepted:
>
>
> Crud and form.process() do not go together. Crud is a higher level interface
> and automatically handles form processing. Once you call crud.create(), the
> form is already processed -- processing it the second time will not work
> (the formkey token used to protect against CSRF attacks and double
> submission is only good for one submission).
>
> Anthony
>
> --
>
>
>

-- 





Re: [web2py] Re: custom form validation doesn't work

2012-12-16 Thread Jonas Fredriksson
here is the custom form:

{{=form.custom.begin}}

  date: {{=form.custom.widget.created_on}}


  name: {{=form.custom.widget.created_by}}


  mail: {{=form.custom.widget.mail}}


  link: {{=form.custom.widget.link}}


  comment:{{=form.custom.widget.comment}}

{{=form.custom.submit}}
{{=form.custom.end}}


The second question is as follows: when the form is filled and
submitted, it should be clean, i.e no text in it or something else
that indicates that the submission was successful and possible
collapsed to. It is true that the redirect(index) returns data from
the data base but I want to avoid that in this case, so another form
of redirect would be better.

On Sun, Dec 16, 2012 at 3:35 PM, Massimo Di Pierro
 wrote:
> Hello Jonas,
>
> Can you show us your custom form, the one that does not work. Validation and
> form processing are done before the view is execued therefore it cannot
> affect form validation and processing. perhaps that is something in the
> custom form that prevents error messages from being displayed.
>
> I do not understand the second question. The index function returns all
> records for each table.
>
> Massimo
>
>
> On Saturday, 15 December 2012 17:27:51 UTC-6, jonas wrote:
>>
>> Hi.
>>
>> I have a default form that is passed in view: {{=form}}
>> using this validation and insertion works. but when I use a custom form
>> none of that works. why?
>> Also form.process().accepted works only when using default form.
>>
>> My second question is: when submitting the form I redirect to index, and
>> all entries in the db are returned. Is that because i reuse the index
>> function? Is there any way to clear all fields after a successful submit?
>>
>> the code:
>>
>> default.py:
>>
>> def index():
>>
>> query=db.blog.id>0
>> res=db(query).select(orderby=~db.blog.date)
>> query=db.about.id>0
>> about=db(query).select()
>> query=db.comments.post_id>0
>> com=db(query).select(orderby=~db.comments.created_on)
>>
>> return dict(res=res,about=about,com=com,message=T('Everything should
>> be made as simple as possible, but not simpler'))
>>
>> def comment():
>>
>> """ create comment form. Every comment is id locked to the specific
>> post """
>>
>> post=db(db.blog.id==request.args(0)).select().first()
>> db.comments.post_id.default=post.id
>> form=crud.create(db.comments)
>> if form.process().accepted:
>> print 'form accepted'
>> redirect(URL('index'))
>> else:
>> print 'not accepted'
>> return dict(form=form)
>>
>> index.html:
>>
>> {{=A(TAG.i(_class="icon-plus-sign"), _rel="tooltip", _title="testing",
>> _class="btn", _href='#', _onclick="jQuery('#uc').toggle();")}}
>> 
>>   {{=LOAD('default','comment.load',args=result.id,ajax=True)}}
>> 
>>
>> comment.load:
>>
>> {{=form}}
>>
>> thanks
>
> --
>
>
>

-- 





Re: [web2py] Re: custom form validation doesn't work

2012-12-16 Thread Jonas Fredriksson
I send the app to your gmail address.

On Sun, Dec 16, 2012 at 4:35 PM, Massimo Di Pierro
 wrote:
> This should work. I do not see why it does not work. Can you email me,
> perhaps privately, an example app so I can reproduce it?
>
>
> On Sunday, 16 December 2012 09:26:54 UTC-6, jonas wrote:
>>
>> here is the custom form:
>>
>> {{=form.custom.begin}}
>> 
>>   date: {{=form.custom.widget.created_on}}
>> 
>> 
>>   name: {{=form.custom.widget.created_by}}
>> 
>> 
>>   mail: {{=form.custom.widget.mail}}
>> 
>> 
>>   link: {{=form.custom.widget.link}}
>> 
>> 
>>   comment:{{=form.custom.widget.comment}}
>> 
>> {{=form.custom.submit}}
>> {{=form.custom.end}}
>>
>>
>> The second question is as follows: when the form is filled and
>> submitted, it should be clean, i.e no text in it or something else
>> that indicates that the submission was successful and possible
>> collapsed to. It is true that the redirect(index) returns data from
>> the data base but I want to avoid that in this case, so another form
>> of redirect would be better.
>>
>> On Sun, Dec 16, 2012 at 3:35 PM, Massimo Di Pierro
>>  wrote:
>> > Hello Jonas,
>> >
>> > Can you show us your custom form, the one that does not work. Validation
>> > and
>> > form processing are done before the view is execued therefore it cannot
>> > affect form validation and processing. perhaps that is something in the
>> > custom form that prevents error messages from being displayed.
>> >
>> > I do not understand the second question. The index function returns all
>> > records for each table.
>> >
>> > Massimo
>> >
>> >
>> > On Saturday, 15 December 2012 17:27:51 UTC-6, jonas wrote:
>> >>
>> >> Hi.
>> >>
>> >> I have a default form that is passed in view: {{=form}}
>> >> using this validation and insertion works. but when I use a custom form
>> >> none of that works. why?
>> >> Also form.process().accepted works only when using default form.
>> >>
>> >> My second question is: when submitting the form I redirect to index,
>> >> and
>> >> all entries in the db are returned. Is that because i reuse the index
>> >> function? Is there any way to clear all fields after a successful
>> >> submit?
>> >>
>> >> the code:
>> >>
>> >> default.py:
>> >>
>> >> def index():
>> >>
>> >> query=db.blog.id>0
>> >> res=db(query).select(orderby=~db.blog.date)
>> >> query=db.about.id>0
>> >> about=db(query).select()
>> >> query=db.comments.post_id>0
>> >> com=db(query).select(orderby=~db.comments.created_on)
>> >>
>> >> return dict(res=res,about=about,com=com,message=T('Everything
>> >> should
>> >> be made as simple as possible, but not simpler'))
>> >>
>> >> def comment():
>> >>
>> >> """ create comment form. Every comment is id locked to the specific
>> >> post """
>> >>
>> >> post=db(db.blog.id==request.args(0)).select().first()
>> >> db.comments.post_id.default=post.id
>> >> form=crud.create(db.comments)
>> >> if form.process().accepted:
>> >> print 'form accepted'
>> >> redirect(URL('index'))
>> >> else:
>> >> print 'not accepted'
>> >> return dict(form=form)
>> >>
>> >> index.html:
>> >>
>> >> {{=A(TAG.i(_class="icon-plus-sign"), _rel="tooltip", _title="testing",
>> >> _class="btn", _href='#', _onclick="jQuery('#uc').toggle();")}}
>> >> 
>> >>   {{=LOAD('default','comment.load',args=result.id,ajax=True)}}
>> >> 
>> >>
>> >> comment.load:
>> >>
>> >> {{=form}}
>> >>
>> >> thanks
>> >
>> > --
>> >
>> >
>> >
>
> --
>
>
>

-- 





Re: [web2py] Re: controller not returning variables

2012-12-24 Thread Jonas Fredriksson
ok, to include everything in the for loop is more elegant. The reason
why I wanted to separate the call to sidebar.py is that the sidebar
contains almost static material that doesn't change that much, while
the main page (index page) has content that changes more. In the first
version I had the db variable defined in the index.py controller. I
Think this is a common situation, sidebar content that doesn't change
much and a main part that is updated more frequently so some sort of
content separation is preferable.
The solution to put it in the view instead is ok for me.

On Mon, Dec 24, 2012 at 2:09 AM, Anthony  wrote:
>>  me (from sidebar.html):
>>
>> {{query=db.about.id>0}}
>> {{ab=db(query).select()}}
>> {{dict(ab=ab)}}
>
>
> The dict line above isn't necessary. The controller function returns a dict
> so that the dict's keys will be added as global variables in the view
> environment, but since you're already in the view here, simply defining the
> ab variable is sufficient.
>
>>
>> {{for pre in ab:}}
>
>
> Actually, you might as well just do this:
>
> {{for pre in db(db.about).select():}}
>
>>
>> but it would have been better to return the ab dict from the sidebar.py
>> controller instead.
>
>
> If you really want the sidebar created by its own controller function and
> view, you can use a component (i.e., the LOAD helper), though in this case
> that would probably generate an unnecessary amount of extra processing for
> something rather simple. If you don't want to run the query in the view but
> need the sidebar on every page, then you can simply define the ab variable
> in a model file (all variables defined in model files are available globally
> in all views).
>
> It might also be a good idea to cache the query for some amount of time to
> avoid a separate database hit on every page request.
>
> Anthony
>
> --
>
>
>

-- 





Re: [web2py] Re: anyone tried jQuery svg?

2013-01-08 Thread Jonas Fredriksson
Thanks for the replies. d3js looks very interesting, I will look into that.

On Tue, Jan 8, 2013 at 3:56 AM, Andrew W  wrote:
> I haven't either, but I'd recommend a look at d3js.org, if you want to use
> svg.
>
> I've done something similar to this one, using a web2py generated json data
> feed - data driven layout !
>
> http://mbostock.github.com/d3/talk/2016/bundle.html
>
>
>
>
>
>
> On Monday, January 7, 2013 7:29:10 AM UTC+13, villas wrote:
>>
>> Look at what he does here:
>>
>> http://keith-wood.name/svgBasics.html
>>
>> See the drawInitial function.
>> You need to load it, put it into a document.ready function or something.
>>
>>
>> On Sunday, January 6, 2013 2:14:13 PM UTC, jonas wrote:
>>>
>>> Hi.
>>>
>>> Has anyone here tried the jQuery svg lib http://keith-wood.name/svg.html?
>>>
>>> I tried to use it in web2py but with no success.
>>>
>>> the necessary lib was imported: >> src="{{=URL('static','js/jquery/jquery.svg.js')}}">
>>> but is seems that the svg function is not present :
>>>
>>> svg should be here
>>>
>>> 
>>>
>>> $('.test').svg();
>>>
>>> var svg=$('.test').svg('get');
>>> svg.circle(130, 75, 50, {fill: 'none', stroke: 'red', strokeWidth: 3});
>>>
>>> 
>>>
>>> the above snippet doesn't work. anyone tried this?
>>>
> --
>
>
>

--