<commit_before>from datetime import datetime
import logging
import os

from google.appengine.api import users
from google.appengine.ext import ndb
from google.appengine.ext.webapp import template

from controllers.base_controller import LoggedInHandler
from consts.account_permissions import AccountPermissions
from models.account import Account

import tba_config


class AdminUserList(LoggedInHandler):
    """
    List all Users.
    """
    PAGE_SIZE = 1000

    def get(self, page_num=0):
        self._require_admin()
        page_num = int(page_num)

        num_users = Account.query().count()
        max_page = num_users / self.PAGE_SIZE

        if page_num <= max_page:
            offset=self.PAGE_SIZE*page_num
        else:
            page_num = 0
            offset = 0
        users = Account.query().order(Account.created).fetch(self.PAGE_SIZE, offset=offset)

        self.template_values.update({
            "num_users": num_users,
            "users": users,
            "page_num": page_num,
            "page_labels": [p+1 for p in xrange(max_page)],
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/user_list.html')
        self.response.out.write(template.render(path, self.template_values))


class AdminUserLookup(LoggedInHandler):
    """
    Lookup a single user by email<commit_msg>Actually fix off-by-one admin user paging<commit_after>from datetime import datetime
import logging
import os

from google.appengine.api import users
from google.appengine.ext import ndb
from google.appengine.ext.webapp import template

from controllers.base_controller import LoggedInHandler
from consts.account_permissions import AccountPermissions
from models.account import Account

import tba_config


class AdminUserList(LoggedInHandler):
    """
    List all Users.
    """
    PAGE_SIZE = 1000

    def get(self, page_num=0):
        self._require_admin()
        page_num = int(page_num)

        num_users = Account.query().count()
        max_page = num_users / self.PAGE_SIZE

        if page_num <= max_page:
            offset=self.PAGE_SIZE*page_num
        else:
            page_num = 0
            offset = 0
        users = Account.query().order(Account.created).fetch(self.PAGE_SIZE, offset=offset)

        self.template_values.update({
            "num_users": num_users,
            "users": users,
            "page_num": page_num,
            "page_labels": [p+1 for p in xrange(max_page+1)],
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/user_list.html')
        self.response.out.write(template.render(path, self.template_values))


class AdminUserLookup(LoggedInHandler):
    """
    Lookup a single user by email
{'fraction_non_alphanumeric': 0.09744525547445256, 'fraction_numerical': 0.0062043795620437955, 'mean_word_length': 2.796398891966759, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2261424', 'n_tokens_mistral': 820, 'n_tokens_neox': 790, 'n_words': 184}