Example #1
0
def gen_invite_code(request):
    '''
    生成用户的邀请码
    返回是否成功
    '''
    u = request.user
    if u.is_superuser is True:
        # 针对管理员特出处理,每次生成5个邀请码
        num = 5
    else:
        num = u.invitecode_num - len(InviteCode.objects.filter(code_id=u.pk))
    if num > 0:
        for i in range(num):
            code = InviteCode(code_type=0, code_id=u.pk)
            code.save()
        registerinfo = {
            'title': '成功',
            'subtitle': '添加邀请码{}个,请刷新页面'.format(num),
            'status': 'success',
        }
    else:
        registerinfo = {
            'title': '失败',
            'subtitle': '已经不能生成更多的邀请码了',
            'status': 'error',
        }
    return JsonResponse(registerinfo)
Example #2
0
 def post(self, request):
     num = int(request.POST.get("num", 0))
     for i in range(num):
         code = InviteCode(code_type=request.POST.get("type"))
         code.save()
     messages.success(request, "添加邀请码{}个".format(num), extra_tags="成功")
     return HttpResponseRedirect(reverse("sspanel:admin_invite"))
Example #3
0
def gen_invite_code(request):
    """
    生成用户的邀请码
    返回是否成功
    """
    u = request.user
    if u.is_superuser is True:
        # 针对管理员特出处理,每次生成5个邀请码
        num = 5
    else:
        num = u.invitecode_num - len(InviteCode.objects.filter(code_id=u.pk))
    if num > 0:
        for i in range(num):
            code = InviteCode(code_type=0, code_id=u.pk)
            code.save()
        registerinfo = {
            "title": "成功",
            "subtitle": "添加邀请码{}个,请刷新页面".format(num),
            "status": "success",
        }
    else:
        registerinfo = {
            "title": "失败",
            "subtitle": "已经不能生成更多的邀请码了",
            "status": "error"
        }
    return JsonResponse(registerinfo)
Example #4
0
def gen_invite_code(request):
    '''
    生成用户的邀请码
    返回是否成功
    '''
    u = request.user
    if u.is_superuser is True:
        # 针对管理员特出处理,每次生成5个邀请码
        num = 5
    else:
        num = u.invitecode_num - len(InviteCode.objects.filter(code_id=u.pk))
    if num > 0:
        for i in range(num):
            code = InviteCode(code_type=0, code_id=u.pk)
            code.save()
        registerinfo = {
            'title': '成功',
            'subtitle': '添加邀请码{}个,请刷新页面'.format(num),
            'status': 'success',
        }
    else:
        registerinfo = {
            'title': '失败',
            'subtitle': '已经不能生成更多的邀请码了',
            'status': 'error',
        }
    return JsonResponse(registerinfo)
Example #5
0
def gen_invite_code(request):

    Num = request.GET.get("num")
    code_type = request.GET.get("type")
    for i in range(int(Num)):
        code = InviteCode(code_type=code_type)
        code.save()
    messages.success(request, "添加邀请码{}个".format(Num), extra_tags="成功")
    return HttpResponseRedirect(reverse("sspanel:backend_invite"))