Example #1
0
 def get(self, request):
     g_id = request.GET.get('id')
     try:
         data = Goods.objects.get(id=g_id, is_delete=0)
     except Exception:
         data = None
     if public_user_match(g_id, data, request):
         return public_user_match(g_id, data, request)
     fineness = []
     for fin in Goods.comm_quality:
         fineness.append({'id': fin[0], 'value': fin[1]})
     addrs = data.addr.split(' ')
     province = addrs[0]
     try:
         city = addrs[1]
         district = addrs[2]
     except Exception:
         city = ""
         district = ""
     condition = Goods.comm_quality[data.fineness][1]
     context = {
         'fin': fineness,
         'gtype': GoodsType.objects.values('id', 'name'),
         'data': data,
         'province': province,
         'city': city,
         'district': district,
         'condition': condition
     }
     return render(request, 'goodalter.html', context)
Example #2
0
 def get(self, request):
     n_id = request.GET.get('id')
     try:
         data = Notice.objects.get(id=n_id, is_delete=0)
     except Exception:
         data = None
     if public_user_match(n_id, data, request):
         return public_user_match(n_id, data, request)
     return render(request, 'noticealter.html', {'data': data})
Example #3
0
 def get(self, request):
     g_id = request.GET.get('id')
     try:
         data = Goods.objects.get(id=g_id, is_delete=0)
     except Exception:
         data = None
     if public_user_match(g_id, data, request):
         return public_user_match(g_id, data, request)
     images = GoodsImage.objects.filter(goods=data, is_delete=0)
     context = {'images': images, 'goods_id': g_id}
     return render(request, 'goodalterimage.html', context)
Example #4
0
 def get(self, request):
     g_id = request.GET.get('id')
     try:
         data = Goods.objects.get(id=g_id, is_delete=0)
     except Exception:
         data = None
     if public_user_match(g_id, data, request):
         return public_user_match(g_id, data, request)
     data.is_delete = 1
     data.save()
     return render(request, 'skippage.html', {
         'msg': '删除成功!',
         'url': reverse('user:mygoods')
     })
Example #5
0
 def post(self, request):
     g_id = request.POST.get('id')
     try:
         data = Goods.objects.get(id=g_id, is_delete=0)
     except Exception:
         data = None
     if public_user_match(g_id, data, request):
         return public_user_match(g_id, data, request)
     files = request.FILES.getlist('files')
     fdfs = FDFSStorage()
     for file in files:
         try:
             url = fdfs.save(name=file.name, content=file)
             GoodsImage(goods=data, image=url).save()
         except Exception:
             GoodsImage(goods=data).save()
     return redirect(reverse('user:mygoods'))
Example #6
0
 def post(self, request):
     n_id = request.POST.get('id')
     try:
         data = Notice.objects.get(id=n_id, is_delete=0)
     except Exception:
         data = None
     if public_user_match(n_id, data, request):
         return public_user_match(n_id, data, request)
     title = request.POST.get('title')
     detail = request.POST.get('gcontent')
     das = {'title': title, 'detail': detail, 'id': n_id}
     context = {'data': das}
     if not all([title, detail]):
         context['msg'] = "数据填写不完整,每个都为必填项!"
         return render(request, 'noticealter.html', context)
     if len(title) > 256:
         context['msg'] = "标题过长!不能超过256个字符"
         return render(request, 'noticealter.html', context)
     data.title = title
     data.detail = detail
     data.update_time = datetime.datetime.now(tz=timezone.utc)
     data.save()
     return redirect(reverse('notice:index'))
Example #7
0
 def post(self, request):
     g_id = request.POST.get('id')
     try:
         data = Goods.objects.get(id=g_id, is_delete=0)
     except Exception:
         data = None
     if public_user_match(g_id, data, request):
         return public_user_match(g_id, data, request)
     title = request.POST.get('title')
     province = request.POST.get('province')
     city = request.POST.get('city')
     district = request.POST.get('district')
     gtype = request.POST.get('gtype')
     detail = request.POST.get('gcontent')
     price = request.POST.get('price')
     con = request.POST.get('condition')
     fineness = []
     for fin in Goods.comm_quality:
         fineness.append({'id': fin[0], 'value': fin[1]})
     condition = Goods.comm_quality[int(con)][1]
     das = {
         'title': title,
         'type': {
             'id': gtype,
             'name': GoodsType.objects.get(id=gtype, is_delete=0).name
         },
         'detail': detail,
         'price': price,
         'fineness': con,
         'id': g_id
     }
     context = {
         'fin': fineness,
         'gtype': GoodsType.objects.values('id', 'name'),
         'data': das,
         'province': province,
         'city': city,
         'district': district,
         'condition': condition
     }
     # 数据检查
     if not all(
         [gtype, title, province, city, district, detail, price, con]):
         context['msg'] = "数据填写不完整,每个都为必填项!"
         return render(request, 'goodalter.html', context)
     if len(title) > 256:
         context['msg'] = "标题过长!不能超过256个字符"
         return render(request, 'goodalter.html', context)
     if float(price) > 99999.00 or float(price) < 0.00:
         context['msg'] = "价格输入有误(0~99999)!"
         return render(request, 'goodalter.html', context)
     gtype = int(gtype)
     price = float(price)
     con = int(con)
     title.strip()
     city.strip()
     province.strip()
     district.strip()
     addr = ' '.join([province, city, district])
     up_date = str(datetime.datetime.now(tz=timezone.utc))
     # 保存商品信息
     try:
         gtype = GoodsType.objects.get(id=gtype, is_delete=0)
     except Exception:
         context['msg'] = "类型选择错误!"
         return render(request, 'goodalter.html', context)
     data.type = gtype
     data.price = price
     data.addr = addr
     data.update_time = up_date
     data.title = title.strip()
     data.detail = detail
     data.fineness = con
     data.update_time = datetime.datetime.now(tz=timezone.utc)
     data.save()
     return redirect(reverse('user:mygoods'))