def addcode(request): """添加分类""" user = request.user if request.method == "POST": code = request.POST.get("code").strip().lower() c_id = Type.objects.create(user=user.id, name=code).id return ajax.ajax_ok(c_id)
def addcode(request): """添加分类""" user = request.user if request.method == 'POST': code = request.POST.get('code').strip().lower() c_id = Type.objects.create(user=user.id, name=code).id return ajax.ajax_ok(c_id)
def addType(request): """添加分类""" user = request.user if request.method == 'POST': name = request.POST.get('name').strip().lower() if not Type.objects.filter(name__iexact=name).exists(): c_id = Type.objects.create(name=name).id return ajax.ajax_ok(c_id)
def addcode(request): """添加分类""" user = request.user if request.method == "POST": code = request.POST.get("code").strip().lower() if not Type.objects.filter(name__iexact=code).exists(): c_id = Type.objects.create(user=user.id, name=code).id return ajax.ajax_ok(c_id)
def deltheme(request): """删除主题""" if request.method == "POST": id = request.POST.get("id") ThemeTag.objects.filter(theme__id=id).delete() Node.objects.filter(obj__id=id).delete() Love.objects.filter(theme__id=id).delete() Comment.objects.filter(type=1, obj=id).delete() Signal.objects.filter(type=4, obj=id).delete() ThemeUrl.objects.filter(theme__id=id).delete() Theme.objects.filter(id=id).delete() return ajax.ajax_ok()
def deltheme(request): """删除主题""" if request.method == 'POST': id = request.POST.get('id') ThemeTag.objects.filter(theme__id=id).delete() Node.objects.filter(obj__id=id).delete() Love.objects.filter(theme__id=id).delete() Comment.objects.filter(type=1, obj=id).delete() Signal.objects.filter(type=4, obj=id).delete() ThemeUrl.objects.filter(theme__id=id).delete() Theme.objects.filter(id=id).delete() return ajax.ajax_ok()
def changeSchedule(request): """更改主题进度""" if request.method == "POST": id = request.POST.get("id") schedule = request.POST.get("schedule", 0) theme = get_object_or_404(Theme, pk=int(id)) theme.schedule = schedule if schedule == "100" and theme.status != 2: theme.status = 2 if theme.status == 0: theme.status = 1 theme.save() return ajax.ajax_ok("进度设置成功")
def changeSchedule(request): """更改主题进度""" if request.method == 'POST': id = request.POST.get('id') schedule = request.POST.get('schedule', 0) theme = get_object_or_404(Theme, pk=int(id)) theme.schedule = schedule if schedule == '100' and theme.status != 2: theme.status = 2 if theme.status == 0: theme.status = 1 theme.save() return ajax.ajax_ok('进度设置成功')
def UploadPic(request): """upload pic to qiniu.""" if request.method == 'POST': img = request.FILES.get('Filedata', None) type = request.POST.get('type', None) if type: qn = SuperQiniu(img, w=800, h=520) else: qn = SuperQiniu(img) qn.uploadFile() remote_url = qn.downloadFile() key = qn.getKey() pic = Pic.objects.create(img=remote_url, key=key) return ajax.ajax_ok({'id':pic.id, 'url':pic.img, 'key':key})
def UploadPic(request): """upload pic to qiniu.""" if request.method == 'POST': img = request.FILES.get('Filedata', None) type = request.POST.get('type', None) if type: qn = SuperQiniu(img, w=800, h=520) else: qn = SuperQiniu(img) qn.uploadFile() remote_url = qn.downloadFile() key = qn.getKey() pic = Pic.objects.create(img=remote_url, key=key) return ajax.ajax_ok({'id': pic.id, 'url': pic.img, 'key': key})
def changeUserInfo(request): """修改用户""" import re RESERVED_WORDS = [ 'root', 'admin', 'bot', 'robot', 'master', 'webmaster', 'account', 'people', 'user', 'users', 'project', 'projects', 'search', 'action', 'favorite', 'like', 'love', 'none', 'team', 'teams', 'group', 'groups', 'organization', 'organizations', 'package', 'packages', 'org', 'com', 'net', 'help', 'doc', 'docs', 'document', 'documentation', 'blog', 'bbs', 'forum', 'forums', 'static', 'assets', 'repository', u'傻逼', u'牛逼', u'二逼', u'2b' 'public', 'private', 'mac', 'windows', 'ios', 'lab', ] if request.method == 'POST': user = request.user data = request.POST.get('obj', '').strip() type = int(request.POST.get('type')) if type == 0: # 更改用户名 if data and len(data) > 20 and len(data) < 3: return ajax.ajax_ok(u'用户名不能超过20个字符,不小于3个字符') if data in RESERVED_WORDS: return ajax.ajax_ok(u'该名称太特殊,已禁用') if MyUser.objects.filter(username=data).exists() and user.username != data: return ajax.ajax_ok(u'用户名已被注册') user.username = data user.save() if type == 1: # 更改邮箱 if data and len(data) < 7 and not re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", data): return ajax.ajax_ok(u'邮箱格式不对') if MyUser.objects.filter(email=data).exists() and user.email != data: return ajax.ajax_ok(u'该邮箱已存在') user.email = data user.save() if type == 2: # 更改性别 sex = 1 if data == u'男' else 0 user.sex = sex user.save() if type == 3: # 更改站点 user.url = data user.save() if type == 4: if len(data) > 1000: return ajax.ajax_ok(u'字数太多了……') user.desc = data user.save() return ajax.ajax_ok(u'修改成功')
def shareDel(request): """删除""" if request.method == 'POST': id = request.POST.get('id') Share.objects.filter(id=id).delete() return ajax.ajax_ok()
def delMs(request): """删除消息""" if request.method == 'POST': id = request.POST.get('id') Signal.objects.filter(id=id).update(status=2) return ajax.ajax_ok()
def readMs(request): """标记消息未已读""" if request.method == 'POST': id = request.POST.get('m_id') Signal.objects.filter(id=id).update(status=1) return ajax.ajax_ok(id)
def changeUserInfo(request): """修改用户""" import re RESERVED_WORDS = [ 'root', 'admin', 'bot', 'robot', 'master', 'webmaster', 'account', 'people', 'user', 'users', 'project', 'projects', 'search', 'action', 'favorite', 'like', 'love', 'none', 'team', 'teams', 'group', 'groups', 'organization', 'organizations', 'package', 'packages', 'org', 'com', 'net', 'help', 'doc', 'docs', 'document', 'documentation', 'blog', 'bbs', 'forum', 'forums', 'static', 'assets', 'repository', u'傻逼', u'牛逼', u'二逼', u'2b' 'public', 'private', 'mac', 'windows', 'ios', 'lab', ] if request.method == 'POST': user = request.user data = request.POST.get('obj', '').strip() type = int(request.POST.get('type')) if type == 0: # 更改用户名 if data and len(data) > 20 and len(data) < 3: return ajax.ajax_ok(u'用户名不能超过20个字符,不小于3个字符') if data in RESERVED_WORDS: return ajax.ajax_ok(u'该名称太特殊,已禁用') if MyUser.objects.filter( username=data).exists() and user.username != data: return ajax.ajax_ok(u'用户名已被注册') user.username = data user.save() if type == 1: # 更改邮箱 if data and len(data) < 7 and not re.match( "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", data): return ajax.ajax_ok(u'邮箱格式不对') if MyUser.objects.filter( email=data).exists() and user.email != data: return ajax.ajax_ok(u'该邮箱已存在') user.email = data user.save() if type == 2: # 更改性别 sex = 1 if data == u'男' else 0 user.sex = sex user.save() if type == 3: # 更改站点 user.url = data user.save() if type == 4: if len(data) > 1000: return ajax.ajax_ok(u'字数太多了……') user.desc = data user.save() return ajax.ajax_ok(u'修改成功')