# 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

#        import unicodedata
#        import uuid
#
#        _domain_prefix_re = re.compile("(http://www\.|http://)")
#        sites = self.db.query("select * from site")
#        if sites:
#            for site in sites:
#                slug = site.website.lower().strip()
#                slug = _domain_prefix_re.sub("", slug)
#                slug = unicodedata.normalize("NFKD", slug).encode("ascii", "ignore")
#                slug = re.sub(r"[^\w]+", " ", slug)
#                slug = "-".join(slug.split())
#                if not slug:
#                    slug = "site"
#                while True:
#                    e = self.db.get("SELECT * FROM site WHERE slug = %s", slug)
#                    if not e:
#                        break
#                    slug += "-" + uuid.uuid4().hex[0:2]
#
#                self.db.execute("UPDATE site SET slug = %s where id = %s", slug, site.id)
#
#        self.write("Update slug OK")

sub_handlers = ["^admin.poweredsites.org$",
                [(r"/?", AdminIndexHandler),
                 (r"/clearcache", AdminClearCacheHandler),
                 (r"/newusers", AdminNewUsersHandler),
                 ##(r"/addsiteslug", AdminAddSiteSlugHandler),
               ]

# 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

#        import unicodedata
#        import uuid
#
#        _domain_prefix_re = re.compile("(http://www\.|http://)")
#        sites = self.db.query("select * from site")
#        if sites:
#            for site in sites:
#                slug = site.website.lower().strip()
#                slug = _domain_prefix_re.sub("", slug)
#                slug = unicodedata.normalize("NFKD", slug).encode("ascii", "ignore")
#                slug = re.sub(r"[^\w]+", " ", slug)
#                slug = "-".join(slug.split())
#                if not slug:
#                    slug = "site"
#                while True:
#                    e = self.db.get("SELECT * FROM site WHERE slug = %s", slug)
#                    if not e:
#                        break
#                    slug += "-" + uuid.uuid4().hex[0:2]
#
#                self.db.execute("UPDATE site SET slug = %s where id = %s", slug, site.id)
#
#        self.write("Update slug OK")

sub_handlers = ["^admin.poweredsites.org$",
                [(r"/?", AdminIndexHandler),
                 (r"/clearcache", AdminClearCacheHandler),
                 (r"/newusers", AdminNewUsersHandler),
                 ##(r"/addsiteslug", AdminAddSiteSlugHandler),
               ]

            ]
