本文整理汇总了Python中util.jsonresult.get_result函数的典型用法代码示例。如果您正苦于以下问题:Python get_result函数的具体用法?Python get_result怎么用?Python get_result使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_result函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_sms_code
def send_sms_code(request, tel):
"""
发送修改密码的验证码
:param request:
:param tel:
:return:
发送修改密码的验证码
by:王健 at:2016-04-21
"""
# todo:虚假发送验证码,待完善
before_sms = request.session.get('smstime')
if before_sms and time.time() - before_sms < 60:
return get_result(False, u'每分钟只能发送一条验证码短信')
num = request.session.get('smsnum', 0)
if num > 10:
return get_result(False, u'当天发送短信验证码太多')
if get_user_model().objects.filter(username=tel).exists():
request.session['smsusername'] = tel
request.session['smstime'] = time.time()
request.session['smscode'] = 1234
request.session['smsnum'] = num + 1
else:
return get_result(False, u'手机号不存在')
return get_result(True, u'发送验证码成功')
示例2: remove_manager_org
def remove_manager_org(request, org_id, user_id, person):
"""
移除管理员
:param user_id:
:param person:
:param request:
:param org_id:
:return:
移除管理员
by:王健 at:2016-04-27
组织成员变动事件
by:王健 at:2016-05-03
"""
if person.manage_type == 2:
return get_result(False, u'只有超级管理员才能移除管理员')
try:
member = Person.objects.get(user_id=user_id, org_id=org_id, is_active=True)
member.copy_old()
member.manage_type = 0
create, diff = member.compare_old()
if diff:
member.save()
org_commend("remove_manager_org", org_id, u"%s 取消您 %s 管理员身份" % (person.realname, person.org.name), [user_id])
org_commend("org_member_change", org_id, None)
return get_result(True, u'成功将用户设置成管理员', member)
except Person.DoesNotExist:
return get_result(False, u'用户不是该组织成员')
示例3: transfer_manager_org
def transfer_manager_org(request, org_id, user_id, person):
"""
添加新的超级管理员
:param user_id:
:param person:
:param request:
:param org_id:
:return:
添加新的超级管理员
by:王健 at:2016-04-27
组织成员变动事件
by:王健 at:2016-05-03
"""
if person.manage_type == 2:
return get_result(False, u'只有超级管理员才能添加新的超级管理员')
try:
member = Person.objects.get(user_id=user_id, org_id=org_id, is_active=True)
member.copy_old()
member.manage_type = 2
create, diff = member.compare_old()
if diff:
member.save()
org_commend("transfer_manager_org", org_id, u"%s 设置您为 %s 超级管理员身份" % (person.realname, person.org.name), [user_id])
member_ids = get_org_member_ids_by_manage_type(org_id, [1, 2])
member_ids.remove(user_id)
org_commend("transfer_manager_org", org_id, u"%s 设置 %s 为 %s 超级管理员" % (person.realname, member.realname, person.org.name), member_ids)
org_commend("org_member_change", org_id, None)
return get_result(True, u'成功将用户设置成超级管理员', member)
except Person.DoesNotExist:
return get_result(False, u'用户不是该组织成员')
示例4: change_password_by_code
def change_password_by_code(request, username, newpassword, code):
"""
通手机验证码修改密码
:param username:
:param request:
:param newpassword:
:param code:
:return:
通手机验证码修改密码
by:王健 at:2016-04-21
"""
if code != request.session.get('smscode', 1234):
return get_result(False, u'短信验证码输入错误,请核实!')
if username != request.session.get('smsusername'):
return get_result(False, u'手机号和短信验证码发送的手机号不一致,请核实!', None)
try:
user = get_user_model().objects.get(username=username)
except get_user_model().DoesNotExist:
return get_result(False, u'用户不存在')
if not user.is_active:
return get_result(False, u'用户已经停止使用。')
user.set_password(newpassword)
user.save(update_fields=['password'])
return get_result(True, u'重置密码成功,请重新登录')
示例5: make_appinfo_permission
def make_appinfo_permission(request, org_id, app_id, user_id, role_id, person):
"""
从组织中删除应用
:param request:
:param org_id:
:return:
从组织中删除应用
by:王健 at:2016-04-27
"""
try:
org = person.org
app = AppInfo.objects.get(pk=app_id, orgapp__org_id=org_id, is_active=True, orgapp__is_active=True)
person = Person.objects.get(org_id=org_id, user_id=user_id, is_active=True)
permission, created = Permissions.objects.get_or_create(org=org, person=person, app=app)
permission.copy_old()
if role_id is None:
permission.is_active = False
else:
permission.role = AppRole.objects.get(app_id=app_id, pk=role_id, is_active=True)
create, diff = permission.compare_old()
if diff:
permission.save()
return get_result(True, u'修改用户在应用中的角色成功')
except OrgApp.DoesNotExist:
return get_result(False, u'组织中没有这个应用')
except AppInfo.DoesNotExist:
return get_result(False, u'应用不存在')
except Person.DoesNotExist:
return get_result(False, u'用户不是组织的成员')
except AppRole.DoesNotExist:
return get_result(False, u'应用中不存在这个角色')
示例6: remove_person_org
def remove_person_org(request, org_id, user_id, person):
"""
把用户移出组织
:param user_id:
:param person:
:param request:
:param org_id:
:return:
把用户移出组织
by:王健 at:2016-04-27
组织成员变动事件
by:王健 at:2016-05-03
"""
try:
member = Person.objects.get(user_id=user_id, org_id=org_id)
member.copy_old()
member.is_active = False
create, diff = member.compare_old()
if diff:
member.save()
org_commend("remove_person_org", org_id, u"%s 将您移出 %s " % (person.realname, person.org.name), [user_id])
org_commend("org_member_change", org_id, None)
return get_result(True, u'成功将用户移出组织', member)
except Person.DoesNotExist:
return get_result(False, u'用户不是该组织成员')
示例7: reject_organization
def reject_organization(request, org_id, orgapply_id, person):
"""
拒绝加入组织
:param orgapply_id:
:param person:
:param request:
:param org_id:
:return:
拒绝加入组织
by:王健 at:2016-04-27
拒绝加入事件
by:王健 at:2016-05-03
"""
try:
apporg = OrgApply.objects.get(id=orgapply_id, org_id=org_id)
if apporg.status != 0:
if apporg.status == 1:
return get_result(False, u'该申请已经被 %s 通过' % apporg.checker)
elif apporg.status == 2:
return get_result(False, u'该申请已经被 %s 拒绝' % apporg.checker)
else:
return get_result(False, u'该申请已经被 %s 处理' % apporg.checker)
apporg.copy_old()
apporg.status = 2
apporg.compare_old()
apporg.save()
org_commend("reject_organization", org_id, u"您被拒绝加入 %s" % apporg.org.name, [apporg.user_id])
return get_result(True, u'已经绝用户的加入组织申请', apporg)
except OrgApply.DoesNotExist:
return get_result(False, u'这不是发给您的组织的申请,您不能处理')
示例8: remove_talkgroup
def remove_talkgroup(request, talkgroup_id, user_id, talkuser):
"""
踢人出群
:param talkuser:
:param user_id:
:param request:
:param talkgroup_id:
:return:
踢出群
by:王健 at:2016-04-25
"""
if talkuser.talkgroup.owner_id != request.user.id and talkuser.role != 1:
return get_result(False, u'只有群主和管理员才能踢人出群')
member = TalkUser.objects.get(talkgroup_id=talkgroup_id, user_id=user_id)
member.copy_old()
member.is_active = False
member.compare_old()
member.save()
member.push_im_event(request.user)
talkgroup = talkuser.talkgroup
talkgroup.copy_old()
talkgroup.make_md5_flag()
created, diff = talkgroup.compare_old()
if diff:
talkgroup.save()
im_commend("im_group_change", talkgroup.id)
return get_result(True, u'踢出群成功')
示例9: process_exception
def process_exception(self, request, e):
"""
程序遇到未捕获的异常,会在此处整理出错误信息,和代码行数
by:王健 at:2015-1-3
修改日志 配置
by:王健 at:2015-3-10
修改获取用户手机号
by:王健 at:2015-3-15
优化 日志输入
by:王健 at:2015-3-17
修改错误堆栈信息 获取方式
by:王健 at:2015-4-7
修改错误输出格式
by: 范俊伟 at:2015-04-19
修改log输出函数
by: 范俊伟 at:2015-05-05
:param request:
:param e:
:return:
"""
import time
errorid = time.time()
# client.user_context({
# "errorid": errorid,
# "url": request.path,
# "method": request.method,
# "post": json.dumps(request.POST.items(), ensure_ascii=False),
# "get": json.dumps(request.GET.items(), ensure_ascii=False),
# "ENVIRONMENT": settings.ENVIRONMENT,
#
# })
# client.captureException()
log = logging.getLogger('django')
s = [u'错误码:%s' % errorid, u'%s:%s' % (request.method, request.path)]
user = getattr(request, 'user', None)
if hasattr(user, "tel"):
s.append(u'用户:%s' % user.tel)
else:
s.append(u'未登录用户')
s.append(u'出现以下错误:')
# s.append(traceback.format_exc())
etype, value, tb = sys.exc_info()
s.append(repr(value.message))
s.append(u'错误代码位置如下:')
while tb is not None:
f = tb.tb_frame
lineno = tb.tb_lineno
co = f.f_code
filename = co.co_filename
name = co.co_name
s.append(u'File "%s", line %d, in %s' % (filename, lineno, name))
tb = tb.tb_next
if not settings.DEBUG:
log.exception('\n '.join(s))
return get_result(False, u'服务器端错误,请联系管理员,错误标记码:%s' % errorid, dialog=2)
else:
m = '\n '.join(s)
log.exception(m)
return get_result(False, u'服务器端错误,错误如下:\n%s' % (m), dialog=2)
示例10: create_organization
def create_organization(request, name, icon_url):
"""
创建组织
:param icon_url:
:param name:
:param request:
:return:
创建组织
by:王健 at:2016-04-26
"""
try:
obj = Organization()
obj.name = name
obj.icon_url = icon_url
obj.save()
person = Person()
person.org = obj
person.manage_type = 2
person.user = request.user
person.realname = request.user.realname
person.email = request.user.email
person.save()
org_commend("org_change", obj.id, None)
return get_result(True, None, obj)
except Organization.DoesNotExist:
return get_result(False, u'组织不存在')
示例11: add_talkgroup
def add_talkgroup(request, talkgroup_id, user_id, talkuser):
"""
拉人入群
:param talkuser:
:param user_id:
:param request:
:param talkgroup_id:
:return:
拉人入群
by:王健 at:2016-04-25
"""
if not talkuser.talkgroup.is_add and talkuser.talkgroup.owner_id != request.user.id and talkuser.role != 1:
return get_result(False, u'只有群主和管理员才能拉人入群')
member, created = TalkUser.objects.get_or_create(talkgroup_id=talkgroup_id, user_id=user_id)
member.copy_old()
member.is_active = True
member.read_timeline = int(time.time())
member.is_muted = False
member.compare_old()
member.save()
member.push_im_event(request.user)
talkgroup = talkuser.talkgroup
talkgroup.copy_old()
talkgroup.make_md5_flag()
created, diff = talkgroup.compare_old()
if diff:
talkgroup.save()
im_commend("im_group_change", talkgroup.id)
return get_result(True, u'踢出群成功')
示例12: update_person_group
def update_person_group(request, org_id, user_id, realname, title, email, is_gaoguan, is_show_tel, is_show_email,
person):
"""
修改组织成员信息
:param group:
:param person:
:param user_id:
:param request:
:param org_id:
:return:
部门加人
by:王健 at:2016-04-27
"""
if person.manage_type in [1, 2]:
try:
member = Person.objects.get(org_id=org_id, user_id=user_id, is_active=True)
member.copy_old()
member.realname = realname
member.email = email
member.title = title
member.is_gaoguan = is_gaoguan
member.is_show_tel = is_show_tel
member.is_show_email = is_show_email
created, diff = member.compare_old()
if diff:
member.save()
org_commend("org_group_change", org_id, None)
return get_result(True, u'成员信息修改成功', member)
except Person.DoesNotExist:
return get_result(False, u'成员不存在')
else:
return get_result(False, u'只有管理员可以设置成员信息')
示例13: remove_group
def remove_group(request, org_id, person, group):
"""
删除部门
:param group:
:param person:
:param request:
:param org_id:
:return:
删除部门
by:王健 at:2016-04-27
部门变动事件
by:王健 at:2016-05-03
"""
if check_person_group_permiss(person, group, True):
if group.members.all().exist():
return get_result(False, u'部门内还有成员, 请先移除成员')
group.copy_old()
group.is_active = False
created, diff = group.compare_old()
if diff:
group.save()
org_commend("org_group_change", org_id, None)
return get_result(True, u'删除部门成功', group)
else:
return get_result(False, u'只有管理员、部门主管、父级部门主管、父级部门主管助手可以删除部门')
示例14: add_person_group
def add_person_group(request, org_id, user_id, person, group):
"""
部门加人
:param group:
:param person:
:param user_id:
:param request:
:param org_id:
:return:
部门加人
by:王健 at:2016-04-27
部门变动事件
by:王健 at:2016-05-03
"""
if check_person_group_permiss(person, group):
try:
group.members.add(Person.objects.get(org_id=org_id, user_id=user_id, is_active=True))
except Person.DoesNotExist:
return get_result(False, u'用户不是当前组织的成员,不能加入部门')
clean_organization_groups_cache(org_id)
org_commend("org_group_change", org_id, None)
if group.talkgroup_id:
talkuser, created = TalkUser.objects.get_or_create(talkgroup_id=group.talkgroup_id, user_id=user_id)
talkuser.copy_old()
talkuser.is_active = True
crea, diff = talkuser.compare_old()
if created or diff:
talkuser.save()
talkuser.push_im_event(request.user)
im_commend("im_group_change", group.talkgroup_id)
return get_result(True, u'部门加人成功')
else:
return get_result(False, u'只有管理员、部门主管、部门主管助手、父级部门主管、父级部门主管助手可以添加部门成员')
示例15: add_charge_group
def add_charge_group(request, org_id, group_id, user_id, person, group):
"""
添加部门主管
:param request:
:param org_id:
:return:
添加部门主管
by:王健 at:2016-04-27
部门变动事件
by:王健 at:2016-05-03
"""
if check_person_group_permiss(person, group, True):
group.copy_old()
try:
group.charge = Person.objects.get(org_id=org_id, user_id=user_id, is_active=True)
except Person.DoesNotExist:
return get_result(False, u'用户不是当前组织的成员,不能设置成主管')
created, diff = group.compare_old()
if diff:
group.save()
org_commend("org_group_change", org_id, None)
if group.talkgroup_id is not None:
talkuser, created = TalkUser.objects.get_or_create(talkgroup_id=group.talkgroup_id, user_id=user_id)
talkuser.copy_old()
talkuser.is_active = True
crea, diff = talkuser.compare_old()
if created or diff:
talkuser.save()
talkuser.push_im_event(request.user)
im_commend("im_group_change", group.talkgroup_id)
return get_result(True, u'设置部门主管成功', group)
else:
return get_result(False, u'只有管理员、部门主管、父级部门主管、父级部门主管助手可以添加部门主管')