Dear all,

I'm building a website aimed at displaying some tournaments' results.
Here's how the main controller is designed :

    def GET(self, id):

        ...

        return views.layout(views.tournament(tournament,
                                             views.stats(tournament), #
statistics

views.results(tournament.results)), # results
                                    # some other stuff

On top of the tournament's page is a toolbar which allows the user to
"subscribe" to the current tournament. Once the subscribtion is OK, only the
statistics and the results should be refreshed.

Therefore, the subscribtion buttons fire a JavaScript event :

function updateStatus(tournament_id, statut) {

    $.post("/updateStatus?tournament_id=" + tournament_id + "&statut=" +
statut,
           function(data) {
               $("#stats").load("/tournament_stats?tournament_id=" +
tournament_id);
               $("#results").load("/tournament_results?tournament_id=" +
tournament_id);
           });

}

As you can see, I set up a POST method called updateStatus, the only purpose
of which is to commit the current subscribtion into the database. That
method returns None.

Once the POST is OK, the Ajax callbacks refresh only 2 parts of the page (I
don't want to refresh the whole page) : #stats and #results

class View_Results :

    def GET(self):
        return views.results(tournament.results)

class View_Stats :

    def GET(self):

        return views.stats(tournament)

Question 1) That works, but had to duplicate some code (eg
views.results(tournament.results), which also belongs to the main
controller)

Is there a way to factorize this ?

Question 2) The 2 methods /tournament_stats and /tournament_results are
exposed, in order to be callable by the ajax callbacks. However, some user
could also call http://myserver/tournaments_stats for instance

How can I prevent this ?

Thanks very much for your answers !
Franck

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to