Example #1
0
    def post(self):
        account = self.has_access()
        if not account:
            self.redirect(users.create_logout_url(config.ADMIN_URL))
            return

        self.response.headers['Content-Type'] = 'text/plain'
        player_name = self.request.get('u')
        if not player_name:
            self.response.out.write('no player name entered')
            return

        choice = self.request.get('choice')
        if not choice:
            self.response.out.write('no choice selected')
            return

        reason = self.request.get('r')
        if not reason:
            self.response.out.write('no reason specified')
            return

        p = models.PlayerModel.get(models.playermodel_key(player_name))
        if not p:
            self.response.out.write('cannot find player in database')
            return

        if choice == 'block':
            p.blocked = True
        elif choice == 'unblock':
            p.blocked = False
        else:
            self.response.out.write('choice not block or unblock')
            return

        # Record this action
        d = dict(
            action='block_player' if choice == 'block' else 'unblock_player',
            player_name=player_name,
            reason=reason)
        admin.save_action(account.name, self.request.remote_addr, d)

        p.put()
        self.response.out.write('success. %s is now blocked=%s, reason: %s.' %
                                (player_name, choice == 'block', reason))
Example #2
0
    def post(self):
        account = self.has_access()
        if not account:
            self.redirect(users.create_logout_url(config.ADMIN_URL))
            return

        self.response.headers['Content-Type'] = 'text/plain'
        player_name = self.request.get('u')
        if not player_name:
            self.response.out.write('no player name entered')
            return

        choice = self.request.get('choice')
        if not choice:
            self.response.out.write('no choice selected')
            return

        reason = self.request.get('r')
        if not reason:
            self.response.out.write('no reason specified')
            return
            
        p = models.PlayerModel.get(models.playermodel_key(player_name))
        if not p:
            self.response.out.write('cannot find player in database')
            return
            
        if choice == 'hide':
            p.hidden = True
        elif choice == 'show':
            p.hidden = False
        else:
            self.response.out.write('choice not hide or show')
            return
        p.put()

        # Record this action
        d = dict(action='hide_player' if choice == 'hide' else 'show_player', player_name=player_name, reason=reason)
        admin.save_action(account.name, self.request.remote_addr, d)

        # Return the response
        self.response.out.write('success. %s is now hidden=%s, reason: %s.' % (player_name, choice == 'hide', reason))
Example #3
0
    def get(self):
        account = self.has_access()
        if not account:
            self.redirect(users.create_login_url(self.request.uri))
            return
        type = self.request.get('t').lower()
        u = self.request.get('u').lower()
        player_name = self.request.get('p').lower()
        message = ''

        # if no type specified, there is no query
        rating = 0
        next_type = ''
        if not type:
            # The next request will be a query for a player name's score
            next_type = 'q'

        # Validate the user. Is this a query or set score request?
        p = None
        if type == 'q' or type == 's':
            # This is a query for a user. Make sure the user is valid
            if not u:
                message = 'No player name entered!'
                type = ''
                next_type = 'q'
            else:
                p = models.PlayerModel.get(models.playermodel_key(u))
                if not p:
                    message = 'Could not find player %s! Please try again:' % u
                    u = ''
                    type = ''
                    next_type = 'q'

        # Step through the states
        rating = 0
        reason = ''
        if type == 'q':
            # The next request will be for changing a score
            next_type = 's'
            rating = p.rating

        if type == 's':
            # Is the new rating valid?
            rating = self.request.get('s')
            reason = self.request.get('r')
            success = True
            try:
                rating = int(rating)
            except:
                success = False
                
            if not success or rating >= 3000 or rating < 0:
                message = '"%s" is an invalid score. Please try again:' % rating
                rating = p.rating
                type = 'q'
                next_type = 's'

            elif not reason:
                message = 'Must enter a reason. Please try again:'
                rating = p.rating
                type = 'q'
                next_type = 's'

            else:
                # Record this action
                d = dict(action='adjust_score', player_name=u, old_rating=p.rating, new_rating=rating, reason=reason)
                admin.save_action(account.name, self.request.remote_addr, d)

                p.rating = rating
                p.put()
                message = 'Successfully set the score of player %s to %s, reason: %s.' % (u, rating, reason)
                type = ''
                next_type = 'q'

        template_values = {
            'tabs': config.get_tabs(player_name, account),
            'selected_tab': config.TAB_NONE,
            'form_url': config.ADJUSTSCORE_URL,
            'message': message,
            'player_name': player_name,
            'u': u,
            'rating': rating,
            'type': type,
            'reason': reason,
            'next_type': next_type
        }

        self.response.headers['Content-Type'] = 'application/xhtml+xml'
        path = os.path.join(os.path.dirname(__file__), 'adjustscore.xhtml')
        self.response.out.write(template.render(path, template_values))