Beispiel #1
0
    def create(self, request):
        """创建"""
        # 创建时:blockid,title字段是必须的,\url\pic\mark\status是可选字段
        user = request.user
        result = {}

        if 'blockid' in request.POST and 'title' in request.POST:
            title = request.POST['title'].strip()
            blockid = request.POST['blockid'].strip()

            try:
                block = models.AdaptorBaseBlock.objects.get(pk=blockid)
                item = models.AdaptorBaseBlockItem.objects.create(block=block,
                                                                  title=title)
                if 'url' in request.POST:
                    url = request.POST['url'].strip()
                    item.url = url

                if 'pic' in request.FILES:
                    pic = request.FILES['pic']
                    pic_url = handle_uploaded_file(pic, user.id)
                    item.pic = pic_url

                if 'mark' in request.POST:
                    mark = request.POST['mark'].strip()
                    if mark:
                        item.mark = mark

                if 'status' in request.POST:
                    status = request.POST['status'].strip()
                    if status:
                        item.status = status

                if 'label' in request.POST:
                    label = request.POST['label'].strip()
                    # 将中文的符号替换为英文的
                    label = label.replace(',', ',')
                    item.lables = label

                if 'date' in request.POST:
                    date = request.POST['date'].strip()
                    if date:
                        item.date = date

                item.save()
                result['id'] = item.id
                result['status'] = 'ok'
                result['msg'] = _('Saved completely!')
            except models.AdaptorBaseBlock.DoesNotExist:
                result['status'] = 'error'
                result['msg'] = _('Not found')
        else:
            result['status'] = 'error'
            result['msg'] = 'Need title  in POST'
        return self.httpjson(result)
Beispiel #2
0
    def add_delivery_info(self, request):
        """
        添加货运信息
        """
        user = request.user
        result = {}
        isMble = dmb.process_request(request)
        if 'logistics_name' in request.POST and 'logistics_nub' in request.POST:

            logistics_name = request.POST['logistics_name'].strip()  # 物流公司名称
            logistics_nub = request.POST['logistics_nub'].strip()  # 物流单号
            if logistics_name and logistics_nub:
                aftersaleid = request.POST['aftersaleid']
                aftersale = AfterSales.objects.get(id=aftersaleid)

                if 'picture' in request.FILES:
                    code = ''.join(
                        random.choice(string.ascii_letters + string.digits)
                        for i in range(4))
                    filename = handle_uploaded_file(request.FILES['picture'],
                                                    str(user.id) + '_' + code)
                    aftersale.delivery_pic = filename

                aftersale.status = AfterSales.DELIVERIED
                aftersale.delivery_company = logistics_name
                aftersale.delivery_number = logistics_nub

                aftersale.delivery_date = datetime.today()
                aftersale.save()

                result['status'] = 'ok'
                result['msg'] = "提交成功..."
                if isMble:
                    return render(request,
                                  'aftersales/usercenterl_apply_done.html',
                                  result)
                else:
                    return render(request,
                                  'aftersales/usercenterl_apply_done.html',
                                  result)
            else:
                result['status'] = 'error'
                result['msg'] = '请填写物流公司和物流单号...'
                if isMble:
                    return render(request,
                                  'aftersales/m_usercenter_delivery.html',
                                  result)
                else:
                    return render(request,
                                  'aftersales/usercenter_delivery.html',
                                  result)
        else:
            result['status'] = 'error'
            result['msg'] = 'Need logistics_name and logistics_nub  in POST'
Beispiel #3
0
    def put(self, request):
        """修改"""
        # 修改时:blockid字段是必须的,title\url\pic\mark\status是可选字段
        user = request.user
        result = {}
        if 'blockid' in request.POST:
            blockid = request.POST['blockid'].strip()

            # 创建Block
            block = models.AdaptorBaseBlock.objects.get(pk=blockid)

            if 'title' in request.POST:
                title = request.POST['title'].strip()
                block.title = title

            if 'pic' in request.FILES:
                pic = request.FILES['pic']
                pic_url = handle_uploaded_file(pic, user.id)
                block.pic = pic_url

            if 'url' in request.POST:
                url = request.POST['url'].strip()
                block.url = url

            if 'mark' in request.POST:
                mark = request.POST['mark'].strip()
                if mark:
                    block.mark = mark

            if 'status' in request.POST:
                status = request.POST['status'].strip()
                block.status = int(status)

            block.save()
            result['id'] = block.id
            result['status'] = 'ok'
            result['msg'] = _('Saved completely!')
        else:
            result['status'] = 'error'
            result['msg'] = 'Need title  in POST'
        return self.httpjson(result)
Beispiel #4
0
    def create(self, request):
        """创建寄修服务单"""
        # 创建时:
        user = request.user
        result = {}
        isMble = dmb.process_request(request)

        if 'name' in request.POST and 'phone' in request.POST and \
            'address' in request.POST and 'number' in request.POST and \
             'date' in request.POST and  'description' in request.POST and \
             'service_type' in request.POST :

            name = request.POST['name'].strip()
            phone = request.POST['phone'].strip()
            back_addr = request.POST['address'].strip()

            proudct_code = request.POST['number'].strip()  #产品系列号
            buy_date = request.POST['date'].strip()  #购买日期
            description = request.POST['description'].strip()

            service_type = request.POST['service_type']

            aftersale = AfterSales.objects.create(user=user,
                                                  name=name,
                                                  phone=phone,
                                                  back_addr=back_addr,
                                                  proudct_code=proudct_code,
                                                  buy_date=buy_date,
                                                  description=description,
                                                  service_type=service_type)

            if 'email' in request.POST:
                email = request.POST['email'].strip()
                aftersale.email = email

            if 'color' in request.POST:
                device_color = request.POST['color'].strip()
                aftersale.device_color = device_color

            if 'dealer' in request.POST:
                saller = request.POST['dealer'].strip()
                aftersale.saller = saller

            if 'appphone' in request.POST:
                appphone = request.POST['appphone'].strip()
                aftersale.appphone = appphone

            if 'invoice' in request.FILES:

                code = ''.join(
                    random.choice(string.ascii_letters + string.digits)
                    for i in range(4))
                filename = handle_uploaded_file(request.FILES['invoice'],
                                                str(user.id) + '_' + code)
                aftersale.invoice = filename

            if 'rule' in request.POST:
                device_type = request.POST['rule'].strip()
                aftersale.device_type = device_type

            aftersale.save()
            return aftersale.id
            """
            result['id'] = aftersale.id
            result['status'] ='ok'
            result['msg'] = "提交成功..." 
            """
        else:
            result['status'] = 'error'
            result['msg'] = 'Need title  in POST'

        if isMble:
            return render(request, 'aftersales/lists.html', result)
        else:
            return render(request, 'aftersales/lists.html', result)