automated html helper converter?

27 views
Skip to first unread message

LoveWeb2py

unread,
Oct 13, 2014, 10:57:26 PM10/13/14
to web...@googlegroups.com
Hello,

I have a fair amount of HTML I would like to convert, but I would like to turn it into a function so I can use LOAD and have it automatically update each time a student guesses a question. I've tried implementing javascript, but couldn't get it to work.

Is there an automated HTML Helper converter? I could use to wrap all of these div's together? What would be the best way to approach this problem?

Here is my code:                         
<div id="challenge-accordion" class="styled-accordion panel-group">

                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <a class="accordion-toggle toggle" data-toggle="collapse" data-parent="#answer-accordion" href="#collapseAnswer">{{
                                         last_ten = db(db.questions_answered.question==request.vars['chal']).select(db.questions_answered.ALL, orderby=~db.questions_answered.id, limitby=(0,10))}}

                                            <span class="chevron glyphicon glyphicon-chevron-up icon-white icon-small"></span> Previous Submissions
                                        </a>
                                    </div>
                                    <div id="collapseFlag" class="panel-body collapse">
                                        <div class="panel-body">
                                            <ul>{{for answer in last_ten:
                                            if answer['correct'] == True:}}
                                                <li class="correct">{{=answer['submitted']}}</li>
                                            {{else:}}
                                            <li class="incorrect">{{=answer['submitted']}}
                                            </li>
                                            {{pass}}
                                            {{pass}}
                                            </ul>
                                        </div>
                                    </div>
                                </div>

                            </div>

Anthony

unread,
Oct 13, 2014, 11:41:50 PM10/13/14
to web...@googlegroups.com
Why do you need a function? Why not just make that HTML the view for your LOAD action?

Also, you should pull that db select out of the view and put it in the controller.

Anthony

LoveWeb2py

unread,
Oct 13, 2014, 11:44:14 PM10/13/14
to web...@googlegroups.com
Hi Anthony,

I think that is the ultimate goal. Wouldn't I have to use the helpers or is there someway to use the XML function in the load? I wouldn't even know where to start

Anthony

unread,
Oct 14, 2014, 12:43:46 AM10/14/14
to web...@googlegroups.com
LOAD simply makes an Ajax call to a controller action, which has its own view and works like any other controller action. Your HTML would be in a template file, just like any other template. Check out the documentation on components: http://web2py.com/books/default/chapter/29/12/components-and-plugins#Components--LOAD-and-Ajax.

Anthony

Reply all
Reply to author
Forward
0 new messages