# Path: doodle/core/models/tag.py
# class Tag(SimpleModel):
#     @classmethod
#     def get_all(cls):
#         names = cls.redis_client.smembers(cls.KEY)
#         return [unicode(name, 'utf-8') for name in names]
# 
#     @classmethod
#     def add(cls, name):
#         cls.redis_client.sadd(cls.KEY, name)
# 
#     @classmethod
#     def exists(cls, name):
#         return cls.redis_client.sismember(cls.KEY, name)
# 
#     @classmethod
#     def get_count(cls, name):
#         return cls.redis_client.zcard(TagArticle.KEY % name)
# 
#     @classmethod
#     def get_counts(cls):
#         names = cls.get_all()
#         if names:
#             with cls.redis_client.pipeline(transaction=False) as pipe:
#                 for name in names:
#                     pipe.zcard(TagArticle.KEY % name)
#                 counts = pipe.execute()
#             return dict(izip(names, counts))
#         return {}
# 
# Path: doodle/views/base_handler.py
# class AdminHandler(UserHandler):
#     def prepare(self):
#         super(AdminHandler, self).prepare()
#         self.set_cache(is_public=False)
# 
#         if CONFIG.ENABLE_HTTPS and not self.is_https:
#             request = self.request
#             if request.version == 'HTTP/1.0':
#                 if request.method in ('GET', 'HEAD'):
#                     self.redirect('https://%s%s' % (request.host, request.uri))
#                 else:
#                     raise HTTPError(403)
#             else:
#                 self.redirect('https://%s%s' % (request.host, request.uri), status=307)
#             return
# 
#         if not self.is_admin:
#             if not self.current_user_id:
#                 request = self.request
#                 if request.method in ('GET', 'HEAD'):
#                     state = Auth.generate(request.uri)
#                     self.set_state_cookie(state)
#                     self.redirect(self.get_login_url(), status=302 if request.version == 'HTTP/1.0' else 303)
#                     return
#                 self.set_session_time_cookie()  # force check user status
#             raise HTTPError(403)


from doodle.core.models.tag import Tag
from ..base_handler import AdminHandler
# -*- coding: utf-8 -*-




class CreateTagHandler(AdminHandler):
    def get(self):
        self.render('admin/create_tag.html', {
            'title': '添加新标签',
            'page': 'create_tag'
        })

    def post(self):
        name = self.get_argument('name', None)
        if not name:

# Path: doodle/core/models/tag.py
# class Tag(SimpleModel):
#     @classmethod
#     def get_all(cls):
#         names = cls.redis_client.smembers(cls.KEY)
#         return [unicode(name, 'utf-8') for name in names]
# 
#     @classmethod
#     def add(cls, name):
#         cls.redis_client.sadd(cls.KEY, name)
# 
#     @classmethod
#     def exists(cls, name):
#         return cls.redis_client.sismember(cls.KEY, name)
# 
#     @classmethod
#     def get_count(cls, name):
#         return cls.redis_client.zcard(TagArticle.KEY % name)
# 
#     @classmethod
#     def get_counts(cls):
#         names = cls.get_all()
#         if names:
#             with cls.redis_client.pipeline(transaction=False) as pipe:
#                 for name in names:
#                     pipe.zcard(TagArticle.KEY % name)
#                 counts = pipe.execute()
#             return dict(izip(names, counts))
#         return {}
# 
# Path: doodle/views/base_handler.py
# class AdminHandler(UserHandler):
#     def prepare(self):
#         super(AdminHandler, self).prepare()
#         self.set_cache(is_public=False)
# 
#         if CONFIG.ENABLE_HTTPS and not self.is_https:
#             request = self.request
#             if request.version == 'HTTP/1.0':
#                 if request.method in ('GET', 'HEAD'):
#                     self.redirect('https://%s%s' % (request.host, request.uri))
#                 else:
#                     raise HTTPError(403)
#             else:
#                 self.redirect('https://%s%s' % (request.host, request.uri), status=307)
#             return
# 
#         if not self.is_admin:
#             if not self.current_user_id:
#                 request = self.request
#                 if request.method in ('GET', 'HEAD'):
#                     state = Auth.generate(request.uri)
#                     self.set_state_cookie(state)
#                     self.redirect(self.get_login_url(), status=302 if request.version == 'HTTP/1.0' else 303)
#                     return
#                 self.set_session_time_cookie()  # force check user status
#             raise HTTPError(403)


# Path: doodle/views/admin/tag.py
from doodle.core.models.tag import Tag
from ..base_handler import AdminHandler

# -*- coding: utf-8 -*-




class CreateTagHandler(AdminHandler):
    def get(self):
        self.render('admin/create_tag.html', {
            'title': '添加新标签',
            'page': 'create_tag'
        })

    def post(self):
        name = self.get_argument('name', None)
        if not name:

            self.finish('添加失败，标签名不能为空')