コード例 #1
0
ファイル: views.py プロジェクト: imokyou/admin-project1
def payment(request):
    if not request.GET.get('point', 0):
        return utils.ErrResp(errors.ArgMiss)
    if not request.GET.get('amount', 0):
        return utils.ErrResp(errors.MonenyNotZero)
    bonus_id = request.GET.get('bonus_id', 0)
    # 生成订单写入数据库
    upayment = UserPayment(
        user=request.user,
        amount=float(request.GET.get('amount', 0)) * settings.CURRENCY_RATIO,
        point=int(request.GET.get('point', 0)),
        currency=1,
        pay_type='CSPAY',
        ip=get_ip(request),
        request_url=settings.PAYMENT_API,
        callback=settings.SITE_URL+'member/bonus/update/?id='+bonus_id
    )
    upayment.save()

    # 组织参数及签名
    data = {
        'Amount': int(upayment.amount),
        'BillNo': upayment.order_id,
        'MerNo': settings.PAYMENT_MERNO,
        'ReturnURL': settings.PAYMENT_RETURNURL
    }
    sign = services.get_sign(data, settings.PAYMENT_KEY)
    data['MD5info'] = sign
    data['PayType'] = upayment.pay_type
    data['NotifyURL'] = settings.PAYMENT_NOTIFYURL
    data['api'] = settings.PAYMENT_API

    return utils.crender(request, 'frontend/member/payment.html', data)
コード例 #2
0
ファイル: views.py プロジェクト: imokyou/scheduler
def get_schedule(request, id):
    try:
        try:
            s = Schedule.objects.get(id=id)
        except:
            return utils.ErrResp(errors.DataNotExists)
        data = {
            'id': s.id,
            'stype': s.stype,
            'subject': s.subject,
            'sdate': s.sdate.strftime('%Y-%m-%d'),
            'created_at': s.created_at.strftime('%Y-%m-%d %H:%M:%S'),
            'updated_at': '',
            'targets': []
        }
        try:
            data['updated_at'] = s.updated_at.strftime('%Y-%m-%d %H:%M:%S')
        except:
            pass
        try:
            data['targets'] = json.loads(s.targets)
        except:
            pass
        data['targets'] = fullfill_targets(data['targets'])
        return utils.NormalResp(data)
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.SthWrong)
コード例 #3
0
ファイル: views.py プロジェクト: imokyou/admin-project1
def cbcd_sell(request):
    if request.method == 'POST':
        # if not services.is_hall_open():
        #     return utils.ErrResp(errors.HallNotOpened)

        num = int(request.POST.get('num'))
        price = float(request.POST.get('price'))

        current_order = services.get_current_order()
        if int(price*1000) >= int(current_order['price'] * 1000 * 1.1):
            return utils.ErrResp(errors.PriceTooHigh)
        if int(price*1000) <= int(current_order['price'] * 1000 * 0.9):
            return utils.ErrResp(errors.PriceTooLow)
        try:
            ubalance = UserBalance.objects.get(user=request.user)
        except:
            return utils.ErrResp(errors.CBCDLimit)

        if not ubalance.point or int(ubalance.point*0.05) < num:
            return utils.ErrResp(errors.CBCDLimit)
        ubalance.point = ubalance.point - num
        ubalance.save()
        uorder = UserOrderSell(
            seller_user=request.user,
            num=num,
            num_unsell=num,
            price=price,
            status=0
        )
        uorder.save()
        return utils.NormalResp()
コード例 #4
0
ファイル: views.py プロジェクト: imokyou/scheduler
def add_schedule(request):
    try:
        stype = request.POST.get('stype', '')
        subject = request.POST.get('subject', '')
        sdate = request.POST.get('sdate', '')
        targets = request.POST.get('targets', '')
        if not stype or not subject or not sdate or not targets:
            return utils.ErrResp(errors.ArgMis)

        try:
            sdate = datetime.strptime(sdate, '%Y-%m-%d')
        except:
            return utils.ErrResp(errors.ArgFormatInvalid)

        try:
            targets = json.loads(targets)
        except:
            return utils.ErrResp(errors.ArgFormatInvalid)

        s = Schedule(stype=stype,
                     subject=subject,
                     sdate=sdate,
                     targets=json.dumps(targets))
        s.save()
        return utils.NormalResp({'id': s.id})
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.SthWrong)
コード例 #5
0
ファイル: views.py プロジェクト: imokyou/admin-project1
def find_password(request):
    hashkey = CaptchaStore.generate_key()
    captcha_url = captcha_image_url(hashkey)

    data = {
        'index': 'member',
        'sub_index': 'visa',
        'statics': services.get_statics(request.user.id),
        'news': News.objects.all().order_by('-id')[0:10],
        'hashkey': hashkey,
        'captcha_url': captcha_url,
        'ages': range(18, 61),
        'data': {},
        'errmsg': ''
    }
    if request.method == 'POST':
        try:
            captcha_code = request.POST.get('captcha_code', '')
            captcha_code_key = request.POST.get('captcha_code_key', '')
            email = request.POST.get('email', '')
            if not utils.verify_captcha(captcha_code, captcha_code_key):
                return utils.ErrResp(errors.CaptchCodeInvalid)
            try:
                u = Auth_user.objects.get(email=email)
            except:
                return utils.ErrResp(errors.EmailNotExists)
                
            uresetpwd = UserResetPwd(
                username=u.username,
                email=email
            )
            uresetpwd.save()

            # 发邮件
            resetpwd_dt = dict({
                'title': '重置密码',
                'email': email,
                'username': u.username,
                'reset_url': '/member/reset-pwd?hashkey=%s' % uresetpwd.hashkey
            })

            import email_template
            subject = email_template.resetpwd_template['subject']
            subject = subject.format(**resetpwd_dt)

            html = email_template.resetpwd_template['password']
            html = html.format(**resetpwd_dt)
            utils.mailgun_send_email([email], subject, html)
            return utils.NormalResp()
        except:
            traceback.print_exc()
            return utils.ErrResp(errors.FuncFailed)
    else:
        return utils.crender(request, 'frontend/member/find_password.html', data)
コード例 #6
0
ファイル: views.py プロジェクト: imokyou/scheduler
def delete_schedule(request, id):
    try:
        try:
            schedule = Schedule.objects.get(id=id)
        except:
            return utils.ErrResp(errors.DataNotExists)
        schedule.delete()
        return utils.NormalResp({'id': schedule.id})
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.SthWrong)
コード例 #7
0
def delete_codememo(request, id):
    try:
        try:
            code = CodeMemo.objects.get(id=id)
        except:
            return utils.ErrResp(errors.DataNotExists)
        code.delete()
        return utils.NormalResp({'id': code.id})
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.SthWrong)
コード例 #8
0
ファイル: views.py プロジェクト: imokyou/admin-project1
def payment_update(request):
    order_id = request.POST.get('order_id', '')
    if not order_id:
        return utils.ErrResp(errors.ArgMiss)
    try:
        upayment = UserPayment.objects.get(order_id=order_id)
    except:
        return utils.ErrResp(errors.DataNotExists)
    upayment.pay_type = request.POST.get('pay_type', upayment.pay_type)
    upayment.save()

    return utils.NormalResp()
コード例 #9
0
ファイル: views.py プロジェクト: imokyou/scheduler
def delete_schedule_config(request, schedule_id, id):
    try:
        try:
            sconfig = ScheduleConfig.objects.get(schedule_id=int(schedule_id),
                                                 id=int(id))
        except:
            return utils.ErrResp(errors.DataNotExists)
        sconfig.delete()
        return utils.NormalResp({'id': id})
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.SthWrong)
コード例 #10
0
ファイル: views.py プロジェクト: imokyou/admin-project1
def register(request):
    hashkey = CaptchaStore.generate_key()
    captcha_url = captcha_image_url(hashkey)

    invite_code = request.GET.get('invite_code', '')
    recommend_user = ''
    if invite_code:
        try:
            uinfo = UserInfo.objects.filter(invite_code=invite_code).first()
            recommend_user = uinfo.user.username
        except:
            pass

    data = {
        'index': 'register',
        'statics_info': Statics.objects.order_by('-id').first(),
        'chatlist': UserFeedback.objects.order_by('-id')[0:10],
        'recommend_user': recommend_user,
        'form': RegForm(initial={'recommend_user': recommend_user}),
        'ages': range(18, 61),
        'hashkey': hashkey,
        'captcha_url': captcha_url,
        'errmsg': ''
    }

    if request.method == 'POST':
        username = request.POST.get('username', '')
        email = request.POST.get('email', '')
        username_exists = Auth_user.objects.filter(username=username).exists()
        if username_exists:
            return utils.ErrResp(errors.UserExists)
        if len(username) < 6:
            return utils.ErrResp(errors.UsernameInvalid)
        email_exists = Auth_user.objects.filter(email=email).exists()
        if email_exists:
            return utils.ErrResp(errors.EmailExists)
        if len(request.POST.get('password', '')) < 8 or len(
                request.POST.get('password', '')) > 16:
            return utils.ErrResp(errors.PasswordInvalid)

        captcha_code = request.POST.get('captcha_code', '')
        captcha_code_key = request.POST.get('captcha_code_key', '')
        cs = CaptchaStore.objects.filter(hashkey=captcha_code_key)
        true_key = cs[0].response
        if captcha_code.lower() != true_key:
            return utils.ErrResp(errors.CaptchCodeInvalid)
        CaptchaStore.objects.filter(hashkey=captcha_code_key).delete()

        services.reg(request)
        return utils.NormalResp()
    else:
        return utils.crender(request, 'frontend/register.html', data)
コード例 #11
0
ファイル: views.py プロジェクト: imokyou/admin-project1
def cbcd_buy(request):
    if request.method == 'POST':
        if not services.is_hall_open():
            return utils.ErrResp(errors.HallNotOpened)

        num = int(request.POST.get('num', 0))
        price = float(request.POST.get('price', 0))

        if not num or not price:
            return utils.ErrResp(errors.ArgMiss)

        current_order = UserOrderSell.objects.filter(status=0).order_by('id').first()

        if num > int(current_order.num_unsell):
            return utils.ErrResp(errors.CBCDLimit)
        price = float(current_order.price)

        # 买家付款
        try:
            buyer = UserBalance.objects.get(user_id=request.user.id)
        except:
            utils.debug()
            return utils.ErrResp(errors.MoneyLimit)
        # 美元
        money = float(num * price)

        if not buyer.cash or float(buyer.cash) < money:
            return utils.ErrResp(errors.MoneyLimit)
        buyer.point = buyer.point + num
        buyer.cash = float(buyer.cash) - money
        buyer.save()

        # 更新订单状态
        current_order.num_unsell = current_order.num_unsell - num
        if int(current_order.num_unsell) == 0:
            current_order.status = 1
        current_order.save()

        # 卖家收钱
        seller = UserBalance.objects.get(user=current_order.seller_user)
        seller.cash = float(seller.cash) + float(num * price)
        seller.save()

        # 写买入记录
        buyorder = UserOrderBuy(
            seller_order_id=current_order.order_id,
            buyer_user=request.user,
            price=price,
            num=num
        )
        buyorder.save()
        return utils.NormalResp()
コード例 #12
0
ファイル: views.py プロジェクト: imokyou/scheduler
def add_schedule_config(request, schedule_id):
    try:
        key = request.POST.get('key', '')
        value = request.POST.get('value', '')
        if not key or not value:
            return utils.ErrResp(errors.ArgMis)

        s = ScheduleConfig(schedule_id=schedule_id, key=key, value=value)
        s.save()
        return utils.NormalResp({'id': s.id})
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.SthWrong)
コード例 #13
0
ファイル: views.py プロジェクト: imokyou/admin-project1
def visa_apply(request):
    hashkey = CaptchaStore.generate_key()
    captcha_url = captcha_image_url(hashkey)

    data = {
        'index': 'member',
        'sub_index': 'visa',
        'statics': services.get_statics(request.user.id),
        'news': News.objects.all().order_by('-id')[0:10],
        'hashkey': hashkey,
        'captcha_url': captcha_url,
        'ages': range(18, 61),
        'data': {},
        'errmsg': ''
    }
    if request.method == 'POST':
        try:
            exists = UserVisaApply.objects.filter(user=request.user).exists()
            if exists:
                return utils.ErrResp(errors.VisaApplyExists)

            captcha_code = request.POST.get('captcha_code', '')
            captcha_code_key = request.POST.get('captcha_code_key', '')
            cs = CaptchaStore.objects.filter(hashkey=captcha_code_key)
            true_key = cs[0].response
            print true_key, captcha_code.lower()
            if captcha_code.lower() != true_key:
                return utils.ErrResp(errors.CaptchCodeInvalid)
            CaptchaStore.objects.filter(hashkey=captcha_code_key).delete()
            uapply = UserVisaApply(
                user=request.user,
                first_name=request.POST.get('first_name', ''),
                last_name= request.POST.get('last_name', ''),
                age=request.POST.get('age', 0),
                email=request.POST.get('email', ''),
                phone=request.POST.get('phone', ''),
                id_card=request.POST.get('id_card', ''),
                address=request.POST.get('address', ''),
                city=request.POST.get('city', ''),
                provincy=request.POST.get('provincy', ''),
                country=request.POST.get('country', ''),
                zip_code=request.POST.get('zip_code', '')
            )
            uapply.save()
            return utils.NormalResp()
        except:
            traceback.print_exc()
            return utils.ErrResp(errors.FuncFailed)
    else:
        return utils.crender(request, 'frontend/member/visa_apply.html', data)
コード例 #14
0
def add_codememo(request):
    try:
        ctype = request.POST.get('ctype', '')
        description = request.POST.get('description', '')
        content = request.POST.get('content', '')
        if not ctype or not description or not content:
            return utils.ErrResp(errors.ArgMis)

        s = CodeMemo(ctype=ctype, description=description, content=content)
        s.save()
        return utils.NormalResp({'id': s.id})
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.SthWrong)
コード例 #15
0
ファイル: views.py プロジェクト: imokyou/scheduler
def update_schedule_config(request, schedule_id, id):
    try:
        try:
            sconfig = ScheduleConfig.objects.get(schedule_id=int(schedule_id),
                                                 id=int(id))
        except:
            return utils.ErrResp(errors.DataNotExists)

        sconfig.key = request.POST.get('key', sconfig.key)
        sconfig.value = request.POST.get('value', sconfig.value)
        sconfig.save()
        return utils.NormalResp({'id': id})
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.SthWrong)
コード例 #16
0
def update_codememo(request, id):
    try:
        try:
            code = CodeMemo.objects.get(id=id)
        except:
            return utils.ErrResp(errors.DataNotExists)

        code.ctype = request.POST.get('ctype', code.ctype)
        code.description = request.POST.get('description', code.description)
        code.content = request.POST.get('content', code.content)
        code.save()
        return utils.NormalResp({'id': code.id})
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.SthWrong)
コード例 #17
0
ファイル: views.py プロジェクト: imokyou/admin-project1
def visa_apply(request):
    try:
        p = int(request.GET.get('p', 1))
        n = int(request.GET.get('n', 25))
        username = request.GET.get('username', '')
        status = int(request.GET.get('status', -1))

        q = UserVisaApply.objects
        if username:
            try:
                u = Auth_user.objects.get(username=username)
                q = q.filter(user_id=u.id)
            except:
                pass
        if status != -1:
            q = q.filter(status=status)

        form_initial = {'username': username, 'status': status}
        form = VisaSearchForm(initial=form_initial)

        data = {
            'index': 'user',
            'paging': Pagination(request, q.count()),
            'forms': form,
            'list': {
                'p': p,
                'n': n,
                'data': q.all().order_by('-id')[(p - 1) * n:p * n],
            }
        }
        return render(request, 'backend/user/visa_apply.html', data)
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.FuncFailed)
コード例 #18
0
def login(request):
    try:
        next_url = request.GET.get('next', '')
        if request.user.is_authenticated():
            if not next_url:
                next_url = settings.BACKEND_INDEX
            return HttpResponseRedirect(next_url)
        data = {
            'error_msg': '',
            'next_url': next_url
        }
        if request.method == 'POST':
            account = request.POST.get('account', '')
            password = request.POST.get('password', '')
            user = authenticate(username=account, password=password)
            if user is not None and user.is_staff and user.is_active:
                auth_login(request, user)
                if not next_url:
                    next_url = settings.BACKEND_INDEX

                log = UserOplog(
                    user_id=user.id,
                    optype=1,
                    content=request.META['HTTP_USER_AGENT'],
                    ip=get_ip(request),
                )
                log.save()
                return HttpResponseRedirect(next_url)
            else:
                data['error_msg'] = '账号或密码错误, 请输新输入'
    except:
        return utils.ErrResp(errors.FuncFailed)
    return render(request, 'backend/login.html', data)
コード例 #19
0
ファイル: views.py プロジェクト: imokyou/admin-project1
def detail(request):
    try:
        data = {
            'user_info': {}
        }
        user_id = int(request.GET.get('id', 0))
        u_exists = Auth_user.objects.filter(id=user_id).exists()
        if u_exists:
            u = Auth_user.objects.get(id=user_id)
            date_joined = utils.dt_field_to_local(u.date_joined) \
                .strftime('%Y-%m-%d %H:%M:%S')
            try:
                last_login = utils.dt_field_to_local(u.last_login) \
                    .strftime('%Y-%m-%d %H:%M:%S')
            except:
                last_login = ''
            data['user_info'] = {
                'id': u.id,
                'username': u.username,
                'email': u.email,
                'first_name': u.first_name,
                'last_name': u.last_name,
                'role': UserInfo.ROLE[u.is_superuser],
                'status': UserInfo.STATUS[u.is_active],
                'date_joined': date_joined,
                'last_login': last_login,
                'reg_ip': '',
                'reg_code': '',
                'reg_type': '',
                'invite_code': '',
                'bank_code': '',
                'bank_card': '',
                'cash': 0,
                'invite_benifit': 0,
                'total_amount': 0
            }
            try:
                uinfo = UserInfo.objects.get(user=u)
                data['user_info']['pwd'] = uinfo.pwd
                data['user_info']['reg_ip'] = uinfo.reg_ip
                data['user_info']['reg_code'] = uinfo.reg_code
                data['user_info']['reg_type'] = UserInfo.REG_TYPE[uinfo.reg_type]
                data['user_info']['bank_code'] = uinfo.bank_code
                data['user_info']['bank_card'] = uinfo.bank_card
                data['user_info']['invite_code'] = uinfo.invite_code
                data['user_info']['invite_url'] = '%sregister/?invite_code=%s' % \
                    (settings.SITE_URL, uinfo.invite_code)
            except:
                pass
            try:
                ubalance = UserBalance.objects.get(user=u)
                data['user_info']['cash'] = float(ubalance.cash)
                data['user_info']['invite_benifit'] = float(ubalance.invite_benifit)
                data['user_info']['total_amount'] = float(ubalance.total)
            except:
                pass
    except:
        utils.debug()
        return utils.ErrResp(errors.FuncFailed)
    return render(request, 'backend/user/detail.html', data)
コード例 #20
0
def create(request):
    try:
        data = {
            'msg': '',
            'index': 'project',
            'form': CreateForm(request.POST)
        }
        if request.method == 'POST':
            name = request.POST.get('name', '')
            description = request.POST.get('description', '')
            try:
                price = float(request.POST.get('price', 0))
            except:
                price = 0
            try:
                total = int(request.POST.get('total', 0))
            except:
                total = 0
            if not name:
                data['msg'] = '项目名称不能为空'
            else:
                project = Projects(name=name,
                                   price=price,
                                   total=total,
                                   description=description,
                                   status=1)
                project.save()
                data['msg'] = '项目创建成功'
    except:
        utils.debug()
        return utils.ErrResp(errors.FuncFailed)
    return render(request, 'backend/project/create.html', data)
コード例 #21
0
def logout(request):
    try:
        next_url = request.GET.get('next', settings.LOGIN_URL)
        auth_logout(request)
        return HttpResponseRedirect(next_url)
    except:
        return utils.ErrResp(errors.FuncFailed)
コード例 #22
0
def change_password(request):
    try:
        data = {
            'error_msg': '',
            'index': 'admin'
        }
        if request.method == 'POST':
            new_password = request.POST.get('new_password', '')
            confirm_password = request.POST.get('confirm_password', '')
            if not new_password or not confirm_password:
                data['error_msg'] = '请输入新密码及确认密码'
            else:
                if new_password != confirm_password:
                    data['error_msg'] = '两次密码输入不相等, 请重新输入'
                elif len(new_password) < 10:
                    data['error_msg'] = '密码长度需为10'
                else:
                    u = Auth_user.objects.get(username=request.user.username)
                    u.set_password(new_password)
                    u.save()
                    logout(request)
                    return HttpResponseRedirect(settings.LOGIN_URL)
    except:
        return utils.ErrResp(errors.FuncFailed)
    return render(request, 'backend/change_password.html', data)
コード例 #23
0
ファイル: views.py プロジェクト: imokyou/scheduler
def get_schedules(request):
    try:
        p = int(request.GET.get('p', 1))
        n = int(request.GET.get('n', 7))
        stype = request.GET.get('stype', '')

        q = Schedule.objects
        if stype:
            q = q.filter(stype=stype)
        results = q.all()[n * (p - 1):n * p]
        data = []
        for r in results:
            info = {
                'id': r.id,
                'stype': r.stype,
                'subject': r.subject,
                'sdate': r.sdate.strftime('%Y-%m-%d'),
                'created_at': r.created_at.strftime('%Y-%m-%d %H:%M:%S'),
                'updated_at': '',
                'targets': []
            }
            try:
                info['updated_at'] = r.updated_at.strftime('%Y-%m-%d %H:%M:%S')
            except:
                pass
            try:
                info['targets'] = json.loads(r.targets)
            except:
                pass
            info['targets'] = fullfill_targets(info['targets'])
            data.append(info)
        return utils.NormalResp(data)
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.SthWrong)
コード例 #24
0
def home(request):
    try:
        p = int(request.GET.get('p', 1))
        n = int(request.GET.get('n', 25))
        q = CBCDInit.objects
        data = {
            'index': 'cbcd',
            'paging': Pagination(request, q.count()),
            'form': InitForm(),
            'inits': {
                'p': p,
                'n': n,
                'data': q.all().order_by('-id')[(p - 1) * n:p * n],
            }
        }
        if request.method == 'POST':
            data['form'] = InitForm(request.POST)
            if data['form'].is_valid():
                try:
                    CBCDInit.objects.all().update(status=0)
                except:
                    pass
                cinit = CBCDInit(total=int(request.POST.get('total')),
                                 unsell=int(request.POST.get('total')),
                                 price=float(request.POST.get('price')),
                                 status=1)
                cinit.save()
                return HttpResponseRedirect('/backend/cbcd/')
    except:
        utils.debug()
        return utils.ErrResp(errors.FuncFailed)
    return render(request, 'backend/cbcd/index.html', data)
コード例 #25
0
def get_codes(request):
    try:
        p = request.GET.get('p', 1)
        n = request.GET.get('n', 7)

        q = CodeMemo.objects
        results = q.all()[n * (p - 1):n * p]
        data = []
        for r in results:
            info = {
                'id': r.id,
                'ctype': r.ctype,
                'description': r.description,
                'content': r.content,
                'created_at': r.created_at.strftime('%Y-%m-%d %H:%M:%S'),
                'updated_at': ''
            }
            try:
                info['updated_at'] = r.updated_at.strftime('%Y-%m-%d %H:%M:%S')
            except:
                pass
            data.append(info)
        return utils.NormalResp(data)
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.SthWrong)
コード例 #26
0
ファイル: views.py プロジェクト: imokyou/admin-project1
def setting(request):
    data = {
        'index': 'member',
        'sub_index': 'home',
        'statics': services.get_statics(request.user.id),
        'news': News.objects.all().order_by('-id')[0:10],
        'changePwdForm': ChangePwdForm(),
        'changeInfoForm': ChangeUserInfoForm(),
        'userinfo': {},
        'errmsg': ''
    }
    if request.session['lang'] == 'cn':
        data['changePwdForm'] = ChangePwdForm()
    else:
        data['changePwdForm'] = EnChangePwdForm()
    uinfo = UserInfo.objects.get(user=request.user)
    data['userinfo'] = uinfo

    if request.method == 'POST':
        if request.POST.get('ctype') == 'changepwd':
            if request.session['lang'] == 'cn':
                data['changePwdForm'] = ChangePwdForm(request.POST)
            else:
                data['changePwdForm'] = EnChangePwdForm(request.POST)
            if data['changePwdForm'].is_valid():
                user = authenticate(username=request.user.username,
                                    password=request.POST['password'])
                if not user:
                    if request.session['lang'] == 'cn':
                        data['errmsg'] = '原密码输入有误'
                    else:
                        data['errmsg'] = 'old password invalid'
                else:
                    u = Auth_user.objects.get(username=request.user.username)
                    u.set_password(request.POST['new_password'])
                    u.save()

                    uinfo = UserInfo.objects.get(user=request.user)
                    uinfo.pwd = request.POST['new_password']
                    uinfo.save()

                    auth_logout(request)
                    return HttpResponseRedirect('/login/')
        elif request.POST.get('ctype', '') == 'changeinfo':
            try:
                uinfo = UserInfo.objects.get(user=request.user)
                uinfo.city = request.POST.get('city', uinfo.city)
                uinfo.provincy = request.POST.get('provincy', uinfo.provincy)
                uinfo.country = request.POST.get('country', uinfo.country)
                uinfo.phone_number = request.POST.get('phone', uinfo.phone_number)
                uinfo.bank_code = request.POST.get('bank_code', uinfo.bank_code)
                uinfo.bank_card = request.POST.get('bank_card', uinfo.bank_card)
                uinfo.save()
                return utils.NormalResp()
            except:
                traceback.print_exc()
                return utils.ErrResp(errors.FuncFailed)
    return utils.crender(request, 'frontend/member/settings.html', data)
コード例 #27
0
def edit(request):
    try:
        project_id = request.GET.get('id', '')
        form = EditForm()
        if project_id:
            try:
                u = Projects.objects.get(id=project_id)
                form_initial = {
                    'name': u.name,
                    'status': u.status,
                    'description': u.description,
                    'price': u.price,
                    'total': u.total
                }
                form = EditForm(initial=form_initial)
            except:
                pass
        data = {
            'msg': '',
            'index': 'project',
            'form': form,
            'project_id': project_id
        }
        if request.method == 'POST':
            name = request.POST.get('name', '')
            description = request.POST.get('description', '')
            try:
                status = int(request.POST.get('status', 1))
            except:
                status = 1
            try:
                total = int(request.POST.get('total', 0))
            except:
                total = 0
            try:
                price = float(request.POST.get('price', 0))
            except:
                price = 0

            if not name:
                data['msg'] = '项目名称不能为空'
            else:
                u_exists = Projects.objects.filter(name=name).exists()
                if not u_exists:
                    data['msg'] = '项目不存在'
                else:
                    u = Projects.objects.get(name=name)
                    u.status = status
                    u.price = price
                    u.total = total
                    u.description = description
                    u.save()
                    data['msg'] = '修改成功'
    except:
        utils.debug()
        return utils.ErrResp(errors.FuncFailed)
    return render(request, 'backend/project/edit.html', data)
コード例 #28
0
ファイル: views.py プロジェクト: imokyou/admin-project1
def withdraw(request):
    try:
        p = int(request.GET.get('p', 1))
        n = int(request.GET.get('n', 25))
        username = request.GET.get('username', '')

        q = UserWithDraw.objects
        if username:
            try:
                u = Auth_user.objects.get(username=username)
                q = q.filter(user=u)
            except:
                pass

        form_initial = {'username': username}
        form = WithDrawSearchForm(initial=form_initial)

        data = {
            'index': 'user',
            'paging': Pagination(request, q.count()),
            'forms': form,
            'withdraw_list': {
                'p': p,
                'n': n,
                'data': [],
            }
        }

        withdraws = q.all().order_by('-id')[(p - 1) * n:p * n]
        for w in withdraws:
            try:
                create_time = utils.dt_field_to_local(w.create_time) \
                    .strftime('%Y-%m-%d %H:%M:%S')
            except:
                create_time = ''
            try:
                update_time = utils.dt_field_to_local(w.update_time) \
                    .strftime('%Y-%m-%d %H:%M:%S')
            except:
                update_time = ''
            d = {
                'id': w.id,
                'username': w.user.username,
                'amount': float(w.amount),
                'pay_type': w.pay_type,
                'pay_account': w.pay_account,
                'order_id': w.order_id,
                'create_time': create_time,
                'update_time': update_time,
                'status': UserWithDraw.STATUS[w.status]
            }
            data['withdraw_list']['data'].append(d)
        return render(request, 'backend/user/withdraw.html', data)
    except:
        import traceback
        traceback.print_exc()
        return utils.ErrResp(errors.FuncFailed)
コード例 #29
0
ファイル: views.py プロジェクト: imokyou/admin-project1
def visa_update(request, f_id):
    try:
        vapply = UserVisaApply.objects.get(id=f_id)
        vapply.status = request.POST.get('status', vapply.status)
        vapply.save()
    except:
        traceback.print_exc()
        return utils.ErrResp(errors.FuncFailed)
    return utils.NormalResp()
コード例 #30
0
def home(request):
    try:
        p = int(request.GET.get('p', 1))
        n = int(request.GET.get('n', 25))
        code = request.GET.get('code', '')
        status = int(request.GET.get('status', -1))

        q = InviteCode.objects
        if status != -1:
            q = q.filter(status=status)
        if code:
            q = q.filter(code=code)

        form = SearchForm(initial={'status': status, 'code': code})
        quick_jump_form = QuickJumpForm(initial={
            'status': status,
            'code': code,
            'p': p,
            'n': n
        })
        data = {
            'index': 'admin',
            'paging': Pagination(request, q.count()),
            'forms': form,
            'quick_jump_form': quick_jump_form,
            'code_list': {
                'p': p,
                'n': n,
                'data': [],
            }
        }

        codes = q.all().order_by('-id')[(p - 1) * n:p * n]
        for c in codes:
            try:
                update_time = utils.dt_field_to_local(c.update_time) \
                    .strftime('%Y-%m-%d %H:%M:%S')
            except:
                update_time = ''
            data['code_list']['data'].append({
                'id':
                c.id,
                'code':
                c.code,
                'status':
                c.status,
                'status_name':
                InviteCode.STATUS[c.status],
                'update_time':
                update_time
            })
        return render(request, 'backend/invite_code.html', data)
    except:
        import traceback
        traceback.print_exc()
        return utils.ErrResp(errors.FuncFailed)