class AdminUser(db.Document): """ 管理员 """ xid = db.IntField(verbose_name='XID') username = db.StringField(verbose_name='用户') password = db.StringField(verbose_name='密码') group = db.ReferenceField('Group', verbose_name='组') root = db.BooleanField(default=False, verbose_name='超级管理员') active = db.BooleanField(default=True, verbose_name='激活') freezed = db.DateTimeField(verbose_name='冻结时间') logined = db.DateTimeField(default=datetime.now, verbose_name='登录时间') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') def __unicode__(self): return self.username def is_user(self): return True def is_authenticated(self): """ 是否登录 """ return True def is_active(self): """ 是否激活 """ return self.active def is_anonymous(self): """ 是否游客 """ return False def get_id(self): s = sign(current_app.config.get('SECRET_KEY'), password=self.password) return '{0}|{1}'.format(self.id, s)
class Group(db.Document): """ 管理组 """ name = db.StringField(verbose_name='组名') power = db.ListField(db.ReferenceField('View'), verbose_name='使用权限') can_create = db.ListField(db.ReferenceField('View'), verbose_name='创建权限') can_edit = db.ListField(db.ReferenceField('View'), verbose_name='编辑权限') can_delete = db.ListField(db.ReferenceField('View'), verbose_name='删除权限') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') def __unicode__(self): return self.name @cached_property def power_list(self): return [x.name for x in self.power] @cached_property def can_create_list(self): return [x.name for x in self.can_create] @cached_property def can_edit_list(self): return [x.name for x in self.can_edit] @cached_property def can_delete_list(self): return [x.name for x in self.can_delete]
class User(db.Document, UserMixin): """ 用户模型 """ MENU_ICON = 'user' SEX_UNKNOWN = 'unknown' SEX_MALE = 'male' SEX_FEMALE = 'female' SEX_CHOICES = ( (SEX_UNKNOWN, '保密'), (SEX_MALE, '男'), (SEX_FEMALE, '女'), ) SEX_VALUES = [x[0] for x in SEX_CHOICES] SEX_DICT = dict(SEX_CHOICES) SEX_FROM_WECHAT = {0: SEX_UNKNOWN, 1: SEX_MALE, 2: SEX_FEMALE} id = db.IntField(primary_key=True, verbose_name='ID') phone = db.StringField(max_length=20, verbose_name='手机') email = db.StringField(max_length=40, verbose_name='邮箱') password = db.StringField(max_length=40, verbose_name='密码') nickname = db.StringField(max_length=40, verbose_name='昵称') avatar = db.XImageField(verbose_name='头像') birthday = db.DateTimeField(verbose_name='生日') sex = db.StringField(default=SEX_UNKNOWN, choices=SEX_CHOICES, verbose_name='性别') location = db.AreaField(verbose_name='所在地') address = db.StringField(max_length=100, verbose_name='通讯地址') resume = db.StringField(max_length=100, verbose_name='简介') debug = db.BooleanField(default=False, verbose_name='允许调试') active = db.BooleanField(default=True, verbose_name='激活') inviter = db.ReferenceField('User', verbose_name='邀请者') inviter2 = db.ReferenceField('User', verbose_name='邀请者2') inviter3 = db.ReferenceField('User', verbose_name='邀请者3') channel = db.IntField(verbose_name='注册渠道ID') spm = db.StringField(max_length=100, verbose_name='登录SPM') ip = db.StringField(max_length=20, verbose_name='登录IP') generate = db.BooleanField(default=False, verbose_name='生成') error = db.IntField(default=0, verbose_name='登录错误次数') locked = db.DateTimeField(default=lambda: datetime(1970, 1, 1), verbose_name='锁定时间') logined = db.DateTimeField(default=lambda: datetime.now(), verbose_name='登录时间') registered = db.DateTimeField(default=lambda: datetime.now(), verbose_name='注册时间') meta = { 'indexes': [ 'phone', 'nickname', 'ip', '-logined', '-registered', ], } @property def sex_text(self): return self.SEX_DICT[self.sex]
class IOSVersion(db.Document): """ IOS版本 """ MENU_ICON = 'mobile' id = db.IntField(primary_key=True, verbose_name='ID') version = db.StringField(max_length=200, verbose_name='版本') log = db.StringField(verbose_name='更新日志') url = db.StringField(verbose_name='应用地址') force = db.StringField(verbose_name='强制更新') enable = db.StringField(default=Enable.ENABLED, verbose_name='状态', choices=Enable.CHOICES) modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ '-created', ] } def __unicode__(self): return '%d - %s' % (self.id, self.version) def create(self): """ 创建版本 """ if not self.id: self.id = Item.inc('ios_version_index', 100) self.save() return self.id
class APIItem(db.Document): """ 接口模型 """ MENU_ICON = 'server' name = db.StringField(verbose_name='名称') key = db.StringField(verbose_name='键名') url = db.StringField(verbose_name='链接') expire = db.IntField(default=0, verbose_name='缓存') is_cache = db.BooleanField(verbose_name='已缓存') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ '-created', ] } @property def detail(self): return dict( name=self.name, key=self.key, url=self.url, expire=self.expire, is_cache=self.is_cache, )
class WeiBoUser(db.Document): """ QQ用户信息 """ user = db.IntField(verbose_name='用户') uid = db.IntField(verbose_name='ID') nickname = db.StringField(verbose_name='昵称') sex = db.IntField(verbose_name='性别') country = db.StringField(verbose_name='国家') province = db.StringField(verbose_name='省份') city = db.StringField(verbose_name='城市') headimgurl = db.StringField(verbose_name='头像链接') headimgurl_large = db.StringField(verbose_name='头像链接2') headimgurl_hd = db.StringField(verbose_name='头像链接3') subscribe = db.BooleanField(default=False, verbose_name='是否关注') subscribe_time = db.DateTimeField(verbose_name='关注时间') follow = db.IntField(verbose_name='是否关注') access_token = db.StringField(verbose_name='令牌') expires_in = db.DateTimeField(verbose_name='过期时间') refresh_token = db.StringField(verbose_name='令牌刷新') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ 'user', 'uid', '-modified', '-created', ], } def __unicode__(self): return 'WeiBo %d - %d' % (self.user or 0, self.uid) def oauth(self): User.from_weibo(self) def is_user(self): return False def is_authenticated(self): """ 是否登录 """ return True def is_active(self): """ 是否激活 """ return True def is_anonymous(self): """ 是否游客 """ return False def get_id(self): """ 获取用户ID """ return 'weibo:%s' % str(self.id)
class QQUser(db.Document): """ QQ用户信息 """ user = db.IntField(verbose_name='用户') openid = db.StringField(verbose_name='开放ID') nickname = db.StringField(verbose_name='昵称') figureurl = db.StringField(verbose_name='空间头像') figureurl_1 = db.StringField(verbose_name='空间头像1') figureurl_2 = db.StringField(verbose_name='空间头像2') figureurl_qq_1 = db.StringField(verbose_name='头像链接') figureurl_qq_2 = db.StringField(verbose_name='头像链接2') is_yellow_vip = db.IntField(verbose_name='黄钻') vip = db.IntField(verbose_name='黄钻2') yellow_vip_level = db.IntField(verbose_name='黄钻等级') level = db.IntField(verbose_name='黄钻等级2') is_yellow_year_vip = db.IntField(verbose_name='年黄钻') access_token = db.StringField(verbose_name='令牌') expires_in = db.DateTimeField(verbose_name='过期时间') refresh_token = db.StringField(verbose_name='令牌刷新') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ 'user', 'openid', '-modified', '-created', ], } def __unicode__(self): return 'QQ %d - %s' % (self.user or 0, self.openid) def oauth(self): User.from_qq(self) def is_user(self): return False def is_authenticated(self): """ 是否登录 """ return True def is_active(self): """ 是否激活 """ return True def is_anonymous(self): """ 是否游客 """ return False def get_id(self): """ 获取用户ID """ return 'qq:%s' % str(self.id)
class TPLItem(db.Document): """ 模板模型 """ name = db.StringField(verbose_name='名称') key = db.StringField(verbose_name='键名') tpl = db.XFileField(verbose_name='文件', allows=['html', 'htm']) enable = db.StringField(default=Enable.ENABLED, verbose_name='状态', choices=Enable.CHOICES) modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间')
class Choices(db.Document): """ 选项模型 """ MENU_ICON = 'plus-circle' fields = dict() key = db.StringField(verbose_name='键名') name = db.StringField(verbose_name='名称') default = db.StringField(verbose_name='默认值') choices = db.XListField(db.EmbeddedDocumentField(Choice), verbose_name='选项') enable = db.BooleanField(default=True, verbose_name='启用') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = dict(indexes=['key']) def __unicode__(self): return '%s - %s' % (self.key, self.name) @staticmethod def init(): for key, field in Choices.fields.iteritems(): Choices.init_field(key, field[1], field[0]) @staticmethod def init_field(key, name, field, choices=None): choices = choices or Choices.objects(key=key).first() if choices: if choices.enable: if choices.default: field.default = choices.default field.choices = [(x.key, x.name) for x in choices.choices] else: field.default = None field.choices = None else: Choices(key=key, name=name).save() Choices.refresh(field.owner_document) @staticmethod def refresh(model): if model: for admin in current_app.extensions.get('admin', []): for view in admin._views: if model == getattr(view, 'model', None): view._refresh_cache() def save(self): super(Choices, self).save() field = self.fields.get(self.key) if field: self.init_field(self.key, field[1], field[0], self)
class IP(db.Document): """ IP名单 """ MENU_ICON = 'wifi' TYPE = db.choices(register='注册', sms='短信') ip = db.StringField(verbose_name='IP') type = db.StringField(default=TYPE.REGISTER, choices=TYPE.CHOICES, verbose_name='类型') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = dict(indexes=['-created', ('type', 'ip')])
class OptionItem(db.Document): """ 配置模型 """ MENU_ICON = 'gear' name = db.StringField(verbose_name='名称') key = db.StringField(verbose_name='键名') value = db.StringField(verbose_name='值') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = dict(indexes=['-created'])
class Action(db.Document): """ 功能模型 """ MENU_ICON = 'bars' key = db.StringField(verbose_name='ID') name = db.StringField(verbose_name='名称') desc = db.StringField(verbose_name='描述') icon = db.Base64ImageField(verbose_name='图标') active_icon = db.Base64ImageField(verbose_name='激活图标') module = choice(db.StringField(verbose_name='模块'), 'action_module', '功能模块') data = db.StringField(verbose_name='数据') target = db.StringField(verbose_name='目标') share = db.EmbeddedDocumentField(Share, verbose_name='分享') sort = db.IntField(verbose_name='排序') android_start = db.ReferenceField(AndroidVersion, verbose_name='安卓版本') android_end = db.ReferenceField(AndroidVersion, verbose_name='安卓最大版本') ios_start = db.ReferenceField(IOSVersion, verbose_name='IOS版本') ios_end = db.ReferenceField(IOSVersion, verbose_name='IOS最大版本') login = db.BooleanField(default=False, verbose_name='登陆') login_show = db.BooleanField(default=False, verbose_name='显示') debug = db.BooleanField(default=False, verbose_name='调试') enable = db.StringField(default=Enable.ENABLED, verbose_name='状态', choices=Enable.CHOICES) modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ 'key', 'sort', '-created', ] } @property def detail(self): return dict( id=self.key, name=self.name, desc=self.desc, icon=self.icon.base64, active_icon=self.active_icon.base64, data=self.data, target=self.target, share=unicode(self.share), login=self.login, login_show=self.login_show, debug=self.debug, )
class ActionItem(db.Document): """ 功能模型 """ MENU_ICON = 'bars' name = db.StringField(verbose_name='名称') key = db.StringField(verbose_name='键名') desc = db.StringField(verbose_name='描述') icon = db.XImageField(verbose_name='图标') module = db.ReferenceField('ActionModule', verbose_name='模块') action = db.StringField(default=Action.DEFAULT, verbose_name='动作', choices=Action.CHOICES) url = db.StringField(verbose_name='链接') share = db.EmbeddedDocumentField(ShareItem, verbose_name='分享') sort = db.IntField(verbose_name='排序') android_version = db.ReferenceField(AndroidVersion, verbose_name='安卓版本') android_version_end = db.ReferenceField(AndroidVersion, verbose_name='安卓最大版本') ios_version = db.ReferenceField(IOSVersion, verbose_name='IOS版本') ios_version_end = db.ReferenceField(IOSVersion, verbose_name='IOS最大版本') login = db.BooleanField(default=False, verbose_name='登陆') login_show = db.BooleanField(default=False, verbose_name='登录显示') enable = db.StringField(default=Enable.ENABLED, verbose_name='状态', choices=Enable.CHOICES) modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ 'key', 'sort', '-created', ] } @property def detail(self): return dict( name=self.name, key=self.key, desc=self.desc, icon=self.icon.link, action=self.action, login=self.login, url=self.url, share=unicode(self.share), extras='', )
class Model(db.Document): """ 建模 """ MENU_ICON = 'database' name = db.StringField(max_length=100, verbose_name='名称') desc = db.StringField(max_length=100, verbose_name='描述') fields = db.XListField(db.EmbeddedDocumentField(Field), verbose_name='字段') modified_field = db.BooleanField(default=True, verbose_name='修改') created_field = db.BooleanField(default=True, verbose_name='创建') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') def __unicode__(self): return self.name
class Icon(db.Document): """ 图标模型 """ MENU_ICON = 'picture-o' key = db.StringField(verbose_name='ID') icon = db.Base64ImageField(verbose_name='图标') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ '-created', ] }
class UserImage(db.Document): """ 用户图片 """ user = db.IntField(verbose_name='用户') source = db.StringField(verbose_name='来源') image = db.XImageField(config='USER_IMAGES', verbose_name='图片') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ 'source', '-created', ] }
class AdminUserLoginLog(db.Document): """ 管理登录日志 """ TYPE = db.choices(login='******', logout='退出', error='密码错误') user = db.ReferenceField('AdminUser', verbose_name='用户') type = db.StringField(choices=TYPE.CHOICES, verbose_name='类型') spm = db.StringField(max_length=100, verbose_name='SPM') ip = db.StringField(max_length=20, verbose_name='IP') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') def __unicode__(self): return '%s' % self.user.username @staticmethod def log(user, type, spm=None, ip=None): spm = spm if spm else get_spm() ip = ip if ip else get_ip() AdminUserLoginLog(user=user, type=type, spm=spm, ip=ip).save() @staticmethod def login(user): AdminUserLoginLog.log(user, AdminUserLoginLog.TYPE.LOGIN) @staticmethod def logout(user): AdminUserLoginLog.log(user, AdminUserLoginLog.TYPE.LOGOUT) @staticmethod def error(user): AdminUserLoginLog.log(user, AdminUserLoginLog.TYPE.ERROR)
class ImageItem(db.Document): """ 图片模型 """ MENU_ICON = 'picture-o' image = db.XImageField(verbose_name='图片') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间')
class Channel(db.Document): """ 渠道模型 """ MENU_ICON = 'road' id = db.IntField(primary_key=True, verbose_name='ID') name = db.StringField(max_length=40, verbose_name='名称') password = db.StringField(max_length=40, verbose_name='密码') desc = db.StringField(verbose_name='描述') url = db.StringField(verbose_name='链接') image = db.XImageField(verbose_name='二维码') active = db.BooleanField(default=True, verbose_name='激活') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ '-created', ] } def is_user(self): return True def is_authenticated(self): """ 是否登录 """ return True def is_active(self): """ 是否激活 """ return True def is_anonymous(self): """ 是否游客 """ return False def get_id(self): """ 获取用户ID """ return '%s:%s' % ('channel', str(self.id)) def create(self): """ 创建渠道 """ if not self.id: self.id = Item.inc('channel_index', 1000) self.save() return self.id
class PhoneCode(db.Document): """ 手机验证码 """ MENU_ICON = 'volume-control-phone' ACTION_BIND = 'bind' ACTION_REGISTER = 'register' ACTION_RESET_PASSWORD = '******' ACTION_CHOICES = [ (ACTION_BIND, '绑定'), (ACTION_REGISTER, '注册'), (ACTION_RESET_PASSWORD, '重置密码'), ] ACTION_VALUES = [x[0] for x in ACTION_CHOICES] REGISTERED_ACTIONS = [ACTION_REGISTER] UNREGISTERED_ACTIONS = [ACTION_RESET_PASSWORD] PASS_ACTIONS = [] phone = db.StringField(max_length=20, verbose_name='手机') action = db.StringField(choices=ACTION_CHOICES, verbose_name='类型') code = db.StringField(max_length=40, verbose_name='验证码') error = db.IntField(default=0, verbose_name='错误次数') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ ('phone', 'action'), '-created', ], } def __unicode__(self): return '<%s - %s>' % (self.phone, self.action) @property def timelimit(self): return datetime.now() < self.created + timedelta(seconds=60) @property def timeout(self): return datetime.now() > self.created + timedelta(seconds=1800) @property def registered(self): User = um.models.User return User.objects(phone=self.phone).count() > 0 def make(self): self.created = datetime.now() self.code = str(random.randint(1000, 9999)) self.save() def send(self): um.funcs.send_sms(self) def access(self): self.error += 1 self.save()
class ActionItem(db.Document): """ 功能模型 """ DEFAULT = 'default' MODULE_CHOICES = ((DEFAULT, '默认')) MODULE_VALUES = [x[0] for x in MODULE_CHOICES] name = db.StringField(verbose_name='名称') key = db.StringField(verbose_name='键名') icon = db.XImageField(verbose_name='图标') module = db.StringField(default=DEFAULT, verbose_name='模块', choices=MODULE_CHOICES) action = db.StringField(default=Action.DEFAULT, verbose_name='动作', choices=Action.CHOICES) url = db.StringField(verbose_name='链接') share = db.EmbeddedDocumentField(ShareItem, verbose_name='分享') sort = db.IntField(verbose_name='排序') login = db.BooleanField(default=False, verbose_name='登陆') enable = db.StringField(default=Enable.ENABLED, verbose_name='状态', choices=Enable.CHOICES) modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ 'key', 'sort', '-created', ] } @property def detail(self): return dict( name=self.name, key=self.key, icon=self.icon.link, action=self.action, login=self.login, url=self.url, share=unicode(self.share), )
class Message(db.Document): """ 消息回复 """ TYPE_ARTICLE = "article" TYPE_TEXT = "text" TYPE_MUSIC = "music" TYPE_CHOICES = ( (TYPE_ARTICLE, '文章'), (TYPE_TEXT, '文本'), (TYPE_MUSIC, '音乐'), ) keyword = db.XListField(db.StringField(), verbose_name='关键字') type = db.StringField(default=TYPE_TEXT, verbose_name='类型', choices=TYPE_CHOICES) content = db.StringField(verbose_name='文本回复') music = db.EmbeddedDocumentField((MusicItem), verbose_name='音乐') article = db.XListField(db.EmbeddedDocumentField(ArticleItem), verbose_name='文章') default = db.BooleanField(default=False, verbose_name='默认回复') follow = db.BooleanField(default=False, verbose_name='关注回复') enable = db.StringField(default=Enable.ENABLED, verbose_name='状态', choices=Enable.CHOICES) created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = dict(indexes=[ 'default', 'keyword', ]) def reply(self, message, **kwargs): if self.type == 'text': return TextReply( message=message, content=self.content if self.content else '欢迎关注花胶!') elif self.type == 'music': if self.music.url: return MusicReply(message=message, title=self.music.music_title, description=self.music.music_description, url=self.music.url.link, hq_url=self.music.hq_url.link) elif self.type == 'article': reply = ArticlesReply(message=message) if self.article: for art in self.article: article = Article( title=art.title, description=art.description, img=art.img.get_link(), url=art.url, ) reply.add_article(article) return reply return ''
class WXMenu(db.Document): """ 微信菜单 """ name = db.StringField(verbose_name='主菜单') second = db.ListField(db.EmbeddedDocumentField(Second), verbose_name='二级菜单') url = db.StringField(verbose_name='链接') sort = db.IntField(verbose_name='排序') make = db.BooleanField(verbose_name='使用', default=False) created = db.DateTimeField(verbose_name='创建时间', default=datetime.now)
class SlideItem(db.Document): """ 广告模型 """ MODULE_HEAD = 'home_head' MODULE_FOOT = 'home_foot' MODULE_CHOICES = ( (MODULE_HEAD, '头部'), (MODULE_FOOT, '底部'), ) name = db.StringField(verbose_name='名称') image = db.XImageField(verbose_name='图片') module = db.StringField(default=MODULE_HEAD, verbose_name='模块', choices=MODULE_CHOICES) action = db.StringField(default=Action.DEFAULT, verbose_name='动作', choices=Action.CHOICES) url = db.StringField(verbose_name='链接') share = db.EmbeddedDocumentField(ShareItem, verbose_name='分享') sort = db.IntField(verbose_name='排序') enable = db.StringField(default=Enable.ENABLED, verbose_name='状态', choices=Enable.CHOICES) modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ 'sort', '-created', ] } @property def detail(self): return dict( name=self.name, icon=self.image.link, action=self.action, url=self.url, share=unicode(self.share), )
class SlideItem(db.Document): """ 广告模型 """ MENU_ICON = 'paw' name = db.StringField(verbose_name='名称') key = db.StringField(verbose_name='键名') icon = db.XImageField(verbose_name='图标') module = db.ReferenceField('SlideModule', verbose_name='模块') action = db.StringField(default=Action.DEFAULT, verbose_name='动作', choices=Action.CHOICES) url = db.StringField(verbose_name='链接') share = db.EmbeddedDocumentField(ShareItem, verbose_name='分享') sort = db.IntField(verbose_name='排序') login = db.BooleanField(default=False, verbose_name='登陆') enable = db.StringField(default=Enable.ENABLED, verbose_name='状态', choices=Enable.CHOICES) modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ 'key', 'sort', '-created', ] } @property def detail(self): return dict( name=self.name, key=self.key, icon=self.icon.link, action=self.action, login=self.login, url=self.url, share=unicode(self.share), extras='', )
class Menu(db.Document): """ 菜单模型 """ MENU_ICON = 'sitemap' key = db.StringField(verbose_name='键名') name = db.StringField(verbose_name='名称') link = db.StringField(verbose_name='链接') icon = db.XImageField(verbose_name='图标') module = choice(db.StringField(verbose_name='模块'), 'menu_module', '菜单模块') sort = db.IntField(verbose_name='排序') enable = db.StringField(default=Enable.ENABLED, verbose_name='状态', choices=Enable.CHOICES) modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = dict(indexes=[('enable', 'module', 'sort')]) @staticmethod def get(module): return Menu.objects(module=module, enable=Enable.get()).order_by('sort')
class Slide(db.Document): """ 广告模型 """ MENU_ICON = 'paw' key = db.StringField(verbose_name='ID') name = db.StringField(verbose_name='名称') icon = db.XImageField(verbose_name='图标') module = choice(db.StringField(verbose_name='模块'), 'slide_module', '广告模块') target = db.StringField(verbose_name='目标') share = db.EmbeddedDocumentField(Share, verbose_name='分享') sort = db.IntField(verbose_name='排序') android_start = db.ReferenceField(AndroidVersion, verbose_name='安卓版本') android_end = db.ReferenceField(AndroidVersion, verbose_name='安卓最大版本') ios_start = db.ReferenceField(IOSVersion, verbose_name='IOS版本') ios_end = db.ReferenceField(IOSVersion, verbose_name='IOS最大版本') login = db.BooleanField(default=False, verbose_name='登陆') enable = db.StringField(default=Enable.ENABLED, verbose_name='状态', choices=Enable.CHOICES) modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ 'key', 'sort', '-created', ] } @property def detail(self): return dict( id=self.key, name=self.name, icon=self.icon.link, action=self.action, login=self.login, url=self.url, share=unicode(self.share), extras='', )
class Page(db.Document): """ 网页模型 """ MENU_ICON = 'globe' id = db.IntField(primary_key=True, verbose_name='ID') key = db.StringField(verbose_name='键名') bg = db.StringField(verbose_name='背景颜色(#FFF)') name = db.StringField(verbose_name='名称') content = db.StringField(verbose_name='正文') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = dict(indexes=['-created']) def create(self): """ 创建用户 """ if not self.id: self.id = Item.inc('page_index', 1000) self.save() return self.id
class Channel(db.Document): """ 渠道模型 """ id = db.IntField(primary_key=True, verbose_name='ID') name = db.StringField(max_length=40, verbose_name='名称') desc = db.StringField(verbose_name='描述') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ '-created', ] } def create(self): """ 创建渠道 """ if not self.id: self.id = Item.inc('channel_index', 1000) self.save() return self.id
class WeiBoUser(db.Document, ThirdUserMixin): """ 微博用户 """ MENU_ICON = 'weibo' key = 'weibo' user = db.IntField(verbose_name='用户') uid = db.IntField(verbose_name='ID') nickname = db.StringField(verbose_name='昵称') sex = db.IntField(verbose_name='性别') country = db.StringField(verbose_name='国家') province = db.StringField(verbose_name='省份') city = db.StringField(verbose_name='城市') headimgurl = db.StringField(verbose_name='头像链接') headimgurl_large = db.StringField(verbose_name='头像链接2') headimgurl_hd = db.StringField(verbose_name='头像链接3') subscribe = db.BooleanField(default=False, verbose_name='是否关注') subscribe_time = db.DateTimeField(verbose_name='关注时间') follow = db.IntField(verbose_name='是否关注') access_token = db.StringField(verbose_name='令牌') expires_in = db.DateTimeField(verbose_name='过期时间') refresh_token = db.StringField(verbose_name='令牌刷新') modified = db.DateTimeField(default=datetime.now, verbose_name='修改时间') created = db.DateTimeField(default=datetime.now, verbose_name='创建时间') meta = { 'indexes': [ 'user', 'uid', '-modified', '-created', ], } def __unicode__(self): return 'WeiBo %d - %d' % (self.user or 0, self.uid) def oauth(self): return um.models.User.from_weibo(self)