コード例 #1
0
ファイル: gDefier.py プロジェクト: diego-G/gdefier
 def post(self):
     kind = self.request.get('classification')
     
     x =gDefier_model.GDefierPlayer.all()
     if kind=="score" or kind=="attempts" or kind=="wins":
         ascend="-"
     else:
         ascend=""
     y = x.order(ascend+kind)
     result = """<div align=center><table>"""
     me = self.get_user().nickname()
     num = 1
     for z in y:
         z = gDefier_model.to_dict(z)
         if me == z["name"]:
             result += """<tr style="color: black; background: white;"><td align="center" valign="middle">""" + str(num) + """. </td><td align="center" valign="middle">""" + z["name"] + """</td><td align="center" valign="middle">""" + z[kind] + "</td></tr>"
         else:
             result += """<tr><td align="center" valign="middle">""" + str(num) + """. </td><td align="center" valign="middle">""" + z["name"] + """</td><td align="center" valign="middle">""" + z[kind] + "</td></tr>"
         num+=1
     result += "</table></div>"    
     
     self.response.out.write(result)
コード例 #2
0
ファイル: gDefier.py プロジェクト: diego-G/gdefier
    def get(self):
        if not self.personalize_page_and_get_enrolled():
            return
         
        block_title = self.request.get('title')

        course_info = get_course_dict()
        for b in course_info['module']['blocks']:
            if b['block_title'] == block_title:
                b_info = b
 
        # Sending, accepting or rejecting an invitation to create challenge
        if self.request.get('request'):
            self.send_request(self.request.get('request'), block_title)
            
        if self.request.get('accept'):
            self.accept_request(self.request.get('accept'), block_title)

        if self.request.get('reject'):
            self.reject_request(self.request.get('reject'), block_title)

        block = gDefier_model.add_block_to_player(self, block_title)
        
        invitations=[]
        if block.request:
            invitations = block.request

        b_stats = gDefier_model.to_dict(block)
        b_stats.pop('player')
        b_stats.pop('blockID')
        b_info.pop('question_cast')

        path = sites.abspath(self.app_context.get_home_folder(),
                     GCB_GDEFIER_FOLDER_NAME)
        page = 'templates/gDefier_blocks.html'
        
        # Avoiding repeated opponents or defies
        players = gDefier_model.get_players(self)
        board_block = gDefier_model.GDefierBoardBlock.gql("WHERE blockID = '" + block_title + "'").get()
        opponents = []
        s1 = ""
        s2 = ""
        me = self.get_user().nickname()
        for p in players:
            existing_defy = False
            if p.blocks.count() == 0:
                #User unregistered in G-Defier module yet
                continue
            for s1 in block.sends:
                if p.name == s1:
                    break
            for s2 in block.request:
                if p.name == s2:
                    break
            if p.name == s1 or p.name == s2 or p.name == me:
                    continue
            for df in board_block.defies:
                if df.rname == p.name and df.lname == me:
                    existing_defy = True
                    break
                elif df.rname == me and df.lname == p.name:
                    existing_defy = True
                    break
            if existing_defy:
                continue
            opponents.append(p.name)
            
        my_defies = gDefier_model.player_defies(self, block_title)

        template = self.get_template(page, additional_dirs=[path])
        self.template_value['navbar'] = {'gDefier': True}
        self.template_value['w_module'] = course_info['module']['w_module']
        self.template_value['b_info'] = b_info
        self.template_value['b_stats'] = b_stats
        self.template_value['block'] = block
        self.template_value['players'] = opponents
        self.template_value['invitations'] = invitations
        self.template_value['user'] = self.get_user().nickname()
        self.template_value['my_defies'] = my_defies
        self.render(template)