Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
970 views
in Technique[技术] by (71.8m points)

Changing display order of tags in a table (Google App Engine-Python)

I have a table in UserAdminPage where tags are listed by alpha order (code below).

I want to add a link that will change the order to by date. I know I will change the query.order(owner_tag") to query.order("-date") but do I need to create a new handler?

I don't understand what the link should be where the question marks are.

Thanks

class UserAdminPage(webapp.RequestHandler):
    def get(self):

...

#-----------tags table-----------------#
            query = Owner.all()
            query.filter("owner =", user)
            query.order("owner_tag")
            w = query.fetch(500)

            user_tag_list = []
            for item in w:
                user_tag_list.append(item.owner_tag)

            unique_tags = sorted(f1.f2(user_tag_list))                 

#-----------holding table start--------#
            self.response.out.write("""
            <table border="0" cellpadding="0" cellspacing="20" >
            <tr>
            <td>""")

#-----------tags table start--------#                                   
            self.response.out.write("""<table border="1">
            <tr>
            <th colspan="3">tags<br />
            #the link that will sort by most recent:
            #<a href="?????">order tags by most recent</a></th>
            </tr>
            """)      

            for tag in unique_tags:

                 self.response.out.write("""
                    <tr>
                    <td><a href="/tag?tag=%s">%s</a></td>
                    </tr>
                    """ %
                    (tag, tag)
                    )

            self.response.out.write("""</table>""")  

            #holding table first column end
            self.response.out.write("""</td>""")
            #holding table second column start
            self.response.out.write("""<td style="vertical-align:top">""")

UPDATED CODE AS PER KEVIN P'S ANSWER:

class UserAdminPage(webapp.RequestHandler):
    def get(self):
        order_by = self.request.get("order")

...

#-----------tags table-----------------#
            query = Owner.all()
            query.filter("owner =", user)
            if not order_by:
                query.order("owner_tag")
            elif order_by == "date":
                query.order("-date")
            w = query.fetch(500)

            user_tag_list = []
            for item in w:
                user_tag_list.append(item.owner_tag)

            unique_tags = f1.f2(user_tag_list) 

#-----------holding table start--------#
            self.response.out.write("""
            <table border="0" cellpadding="0" cellspacing="20" >
            <tr>
            <td>""")

#-----------tags table start--------#                                 
#           I put the link here but when I click on it, no table is drawn
#           because the `for` block below draws the tag table
#           so I don't understand how I can draw the table with `order=date`

            self.response.out.write("""<table border="1">
            <tr>
            <th colspan="3">tags<br />
            <a href="/tag?order=date"><span id=small>most recent</span></a></th>
            </tr>
            """)      

            for tag in unique_tags:

                self.response.out.write("""
                    <tr>
                    <td><a href="/tag?tag=%s">%s</a></td>
                    </tr>
                    """ %
                    (tag, tag)
                    )

            self.response.out.write("""</table>""")  

...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...