# Path: poweredsites/libs/handler.py
# class StaffBaseHandler(BaseHandler):
#     """Administrator base handler.
#     
#     It's a shortcut of decorators.staff.
#         
#     """
#     def prepare(self):
#         if not self.current_user:
#             if self.request.method == "GET":
#                 url = self.get_login_url()
#                 if "?" not in url:
#                     url += "?" + urllib.urlencode(dict(next=self.request.full_url()))
#                 self.redirect(url)
#                 return
#             raise HTTPError(403)
#         elif not self.is_staff:
#             if self.request.method == "GET":
#                 self.redirect(options.home_url)
#                 return
#             raise HTTPError(403)
#         else:
#             pass
# 
#         super(StaffBaseHandler, self).prepare()
# 
# class AdminBaseHandler(BaseHandler):
#     """Administrator base handler.
#     
#     It's a shortcut of decorators.admin for every method(get, post, head etc),
#     so we need not write decorators.admin everywhere.
#     
#     """
#     def prepare(self):
#         if not self.current_user:
#             if self.request.method == "GET":
#                 url = self.get_login_url()
#                 if "?" not in url:
#                     url += "?" + urllib.urlencode(dict(next=self.request.full_url()))
#                 self.redirect(url)
#                 return
#             raise HTTPError(403)
#         elif not self.is_admin:
#             if self.request.method == "GET":
#                 self.redirect(options.home_url)
#                 return
#             raise HTTPError(403)
#         else:
#             pass
# 
#         super(AdminBaseHandler, self).prepare()
# 
# Path: poweredsites/db/caches.py
# class Cache(MongodbModel):
# class Page(Cache):
#     def collection(self):
#     def attributes(self):
#     def findby_key(self, key):
#     def name(self):
#     def attributes(self):
# def setup():
# 
# Path: poweredsites/libs/const.py
# class Status(object):
# class Role(object):
# class OpenID(object):
# class Category(object):
#     LOCK = -2
#     SPAM = -1
#     INIT = 0
#     PENDING = 1
#     UNVERIFIED = 2
#     ACTIVE = 9
#     NORMAL = 0
#     STAFF = 5
#     ADMIN = 9
#     GOOGLE = 1
#     FACEBOOK = 2
#     TWITTER = 3
#     FRIENDFEED = 4
#     NAME = {GOOGLE:"Google", FACEBOOK:"Facebook",
#             TWITTER:"Twitter", FRIENDFEED:"Friendfeed"}
#     TOOLKIT = 1
#     HOSTING = 2
#     SERVER = 3
#     DATABASE = 4
#     FRAMEWORK = 5
#     FRONTEND = 6
#     LANGUAGE = 7


from poweredsites.libs.handler import StaffBaseHandler, AdminBaseHandler
from poweredsites.db.caches import clearup
from poweredsites.libs import const

#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.



class AdminIndexHandler(AdminBaseHandler):
    def get(self):
        self.render("admin/index.html")


class AdminClearCacheHandler(AdminBaseHandler):
    def get(self):
        clearup()
        self.write("Clearup cache OK")


class AdminNewUsersHandler(AdminBaseHandler):
    def get(self):
        # New users list, temp
        users = self.db.query("select * from user order by id DESC limit 0, 200")
        count = self.db.get("select count(*) as c from user")
        if count:
            count = count.c
        else:
            count = 0

# Path: poweredsites/libs/handler.py
# class StaffBaseHandler(BaseHandler):
#     """Administrator base handler.
#     
#     It's a shortcut of decorators.staff.
#         
#     """
#     def prepare(self):
#         if not self.current_user:
#             if self.request.method == "GET":
#                 url = self.get_login_url()
#                 if "?" not in url:
#                     url += "?" + urllib.urlencode(dict(next=self.request.full_url()))
#                 self.redirect(url)
#                 return
#             raise HTTPError(403)
#         elif not self.is_staff:
#             if self.request.method == "GET":
#                 self.redirect(options.home_url)
#                 return
#             raise HTTPError(403)
#         else:
#             pass
# 
#         super(StaffBaseHandler, self).prepare()
# 
# class AdminBaseHandler(BaseHandler):
#     """Administrator base handler.
#     
#     It's a shortcut of decorators.admin for every method(get, post, head etc),
#     so we need not write decorators.admin everywhere.
#     
#     """
#     def prepare(self):
#         if not self.current_user:
#             if self.request.method == "GET":
#                 url = self.get_login_url()
#                 if "?" not in url:
#                     url += "?" + urllib.urlencode(dict(next=self.request.full_url()))
#                 self.redirect(url)
#                 return
#             raise HTTPError(403)
#         elif not self.is_admin:
#             if self.request.method == "GET":
#                 self.redirect(options.home_url)
#                 return
#             raise HTTPError(403)
#         else:
#             pass
# 
#         super(AdminBaseHandler, self).prepare()
# 
# Path: poweredsites/db/caches.py
# class Cache(MongodbModel):
# class Page(Cache):
#     def collection(self):
#     def attributes(self):
#     def findby_key(self, key):
#     def name(self):
#     def attributes(self):
# def setup():
# 
# Path: poweredsites/libs/const.py
# class Status(object):
# class Role(object):
# class OpenID(object):
# class Category(object):
#     LOCK = -2
#     SPAM = -1
#     INIT = 0
#     PENDING = 1
#     UNVERIFIED = 2
#     ACTIVE = 9
#     NORMAL = 0
#     STAFF = 5
#     ADMIN = 9
#     GOOGLE = 1
#     FACEBOOK = 2
#     TWITTER = 3
#     FRIENDFEED = 4
#     NAME = {GOOGLE:"Google", FACEBOOK:"Facebook",
#             TWITTER:"Twitter", FRIENDFEED:"Friendfeed"}
#     TOOLKIT = 1
#     HOSTING = 2
#     SERVER = 3
#     DATABASE = 4
#     FRAMEWORK = 5
#     FRONTEND = 6
#     LANGUAGE = 7


# Path: poweredsites/handlers/admin.py
from poweredsites.libs.handler import StaffBaseHandler, AdminBaseHandler
from poweredsites.db.caches import clearup
from poweredsites.libs import const

#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.



class AdminIndexHandler(AdminBaseHandler):
    def get(self):
        self.render("admin/index.html")


class AdminClearCacheHandler(AdminBaseHandler):
    def get(self):
        clearup()
        self.write("Clearup cache OK")


class AdminNewUsersHandler(AdminBaseHandler):
    def get(self):
        # New users list, temp
        users = self.db.query("select * from user order by id DESC limit 0, 200")
        count = self.db.get("select count(*) as c from user")
        if count:
            count = count.c
        else:
            count = 0

        self.render("admin/newusers.html", users=users, count=count, const=const)
