def picture_edit(request, housingpicture_id): housing_picture = HousingPicture.objects.get(pk=housingpicture_id) context = { 'client': housing_picture, 'module': 'listings', } if request.method == 'POST': error = {} if request.FILES: if request.FILES.get('picture', None): # 上传图片 img = request.FILES['picture'] ts = int(time.time()) ext = get_extension(img.name) key = 'picture_{}.{}'.format(ts, ext) handle_uploaded_file(img, key) upload(key, os.path.join(UPLOAD_DIR, key)) housing_picture.picture = key housing_picture.save() return HttpResponseRedirect( reverse('web:listings_picture_list', kwargs={ 'housingresources_id': housing_picture.housing_resources.id })) return render(request, 'super/housing/listings/img/create.html', context)
def index(request): c_user = request.session.get('c_user', {}) profile = Profile.obs.get_queryset().filter(pk=c_user.get('id', 0)).first() infrastructures = Infrastructure.obs.get_queryset().order_by('-order_no') if request.method == 'POST': c_user_id = request.POST.get('c_user_id', '') user_name = request.POST.get('user_name', '') gender = request.POST.get('gender', '') birbath = request.POST.get('birbath', '') mobile = request.POST.get('mobile', '') # bank_acount = request.POST.get('bank_acount', '') id_card = request.POST.get('id_card', '') promo_code = request.POST.get('promo_code', '') employe = request.POST.get('employe', '') # try: profile.user_name = user_name if gender: profile.gender = gender birbath = datetime.datetime.strptime(birbath, "%Y-%m-%d") profile.birbath = birbath profile.mobile = mobile # profile.bank_acount = bank_acount profile.promo_code = promo_code profile.employe = employe profile.id_card = id_card if request.FILES: if request.FILES.get('test-image-file', None): # 上传图片 id_card_picture = request.FILES['test-image-file'] ts = int(time.time()) ext = get_extension(id_card_picture.name) key = 'id_card_picture_{}.{}'.format(ts, ext) handle_uploaded_file(id_card_picture, key) upload(key, os.path.join(UPLOAD_DIR, key)) profile.id_card_picture = key profile.save() context = { 'module': 'index', 'sub_module': 'user_index', 'client': profile, 'infrastructures': infrastructures, 'qiniu_domain': QINIU_DOMAIN, } return render(request, 'frontend/user/05-4-member01.html', context)
def bedroom_edit(request, bedroom_id): bedroom = Bedroom.objects.get(pk=bedroom_id) context = { 'client': bedroom, 'module': 'listings', } house_configs = HouseConfig.obs.get_queryset() context['house_configs'] = house_configs if request.method == 'POST': error = {} error = {} intro = request.POST.get('intro', '') area = request.POST.get('area', 0) status = request.POST.get('status', 0) house_config = request.POST.getlist('house_config', []) if request.FILES: if request.FILES.get('cover', None): # 上传图片 img = request.FILES['cover'] ts = int(time.time()) ext = get_extension(img.name) key = 'cover_{}.{}'.format(ts, ext) handle_uploaded_file(img, key) upload(key, os.path.join(UPLOAD_DIR, key)) bedroom.cover = key bedroom.intro = intro bedroom.area = area bedroom.status = status bedroom.save() bedroom.house_config = [] house_config = [int(h) for h in house_config] for h in house_config: house_config = HouseConfig.objects.get(pk=h) bedroom.house_config.add(house_config) bedroom.save() return HttpResponseRedirect( reverse( 'web:listings_bedroom_list', kwargs={'housingresources_id': bedroom.housing_resources.id})) return render(request, 'super/housing/listings/bedroom/create.html', context)
def ckeditor_many_upload(request): if request.FILES: ts = int(time.time()) img_file = request.FILES.get('upload', '') checkNum = request.GET.get('CKEditorFuncNum', '') ext = get_extension(request.FILES['upload'].name) random_num = ''.join([random.choice(string.digits) for _ in range(4)]) key = 'ckeditor_many_{}_{}.{}'.format(ts, random_num, ext) handle_uploaded_file(img_file, key) # 上传图片到qiniu upload(key, os.path.join(UPLOAD_DIR, key)) return JsonResponse({'uploaded': 1, 'fileName': key, 'url': url(key)})
def ckeditor_upload(request): if request.FILES: ts = int(time.time()) img_file = request.FILES.get('upload', '') checkNum = request.GET.get('CKEditorFuncNum', '') ext = get_extension(request.FILES['upload'].name) key = 'ckeditor_{}.{}'.format(ts, ext) handle_uploaded_file(img_file, key) # 上传图片到qiniu upload(key, os.path.join(UPLOAD_DIR, key)) return HttpResponse("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(\ '"+checkNum+"','"+url(key)+"','')</script>")
def update_profile(request): c_user_id = request.POST.get('c_user_id', '') user_name = request.POST.get('user_name', '') gender = request.POST.get('gender', '') birbath = request.POST.get('jHsDateInput', '') mobile = request.POST.get('mobile', '') # bank_acount = request.POST.get('bank_acount', '') id_card = request.POST.get('id_card', '') promo_code = request.POST.get('promo_code', '') employe = request.POST.get('employe', '') # try: profile = Profile.obs.get_queryset().filter(pk=c_user_id).first() profile.user_name = user_name profile.gender = gender birbath = datetime.datetime.strptime(birbath, "%Y-%m-%d") profile.birbath = birbath profile.mobile = mobile # profile.bank_acount = bank_acount profile.promo_code = promo_code profile.employe = employe profile.id_card = id_card if request.FILES: if request.FILES.get('test-image-file', None): # 上传图片 id_card_picture = request.FILES['test-image-file'] ts = int(time.time()) ext = get_extension(id_card_picture.name) key = 'id_card_picture_{}.{}'.format(ts, ext) handle_uploaded_file(id_card_picture, key) upload(key, os.path.join(UPLOAD_DIR, key)) profile.id_card_picture = key profile.save() # except Exception as e: # logging.error(e) # return JsonResponse({ # 'error_code': 1, # 'error_msg': '保存失败', # }) return JsonResponse({ 'error_code': 0, 'error_msg': '保存成功', })
def advertising_create(request): context = { 'module': 'advertising', } if request.method == 'POST': error = {} name = request.POST.get('name', '') target_url = request.POST.get('target_url', '') flag = True advertising = Advertising() if not len(name): flag = False error['name_msg'] = FILED_CHECK_MSG else: advertising.name = name # 进行类型判断 advertising.target_url = target_url if flag: if request.FILES: if request.FILES.get('img', None): # 上传图片 img = request.FILES['img'] ts = int(time.time()) ext = get_extension(img.name) key = 'logo_{}.{}'.format(ts, ext) handle_uploaded_file(img, key) upload(key, os.path.join(UPLOAD_DIR, key)) advertising.img = key advertising.save() # 序号 advertising.order_no = advertising.id advertising.save() return HttpResponseRedirect(reverse('web:advertising_list')) else: context['client'] = advertising context['error'] = error return render(request, 'super/index/advertising/create.html', context)
def edit(request, infrastructure_id): page = request.GET.get('page', '') client = Infrastructure.objects.filter(id=infrastructure_id).first() context = { 'client': client, 'module': 'infrastructure', 'page': page, } if request.method == 'POST': error = {} name = request.POST.get('name', '') flag = True if not len(name): flag = False error['name_msg'] = FILED_CHECK_MSG else: client.name = name if flag: if request.FILES: if request.FILES.get('cover', None): # 上传图片 img = request.FILES['cover'] ts = int(time.time()) ext = get_extension(img.name) key = 'cover_{}.{}'.format(ts, ext) handle_uploaded_file(img, key) upload(key, os.path.join(UPLOAD_DIR, key)) client.cover = key client.save() return HttpResponseRedirect( reverse('web:infrastructure_list') + '?page=' + page) else: context['error'] = error return render(request, 'super/housing/infrastructure/create.html', context)
def create(request): context = {'module': 'infrastructure'} if request.method == 'POST': error = {} name = request.POST.get('name', '') flag = True infrastructure = Infrastructure() if not len(name): flag = False error['name_msg'] = FILED_CHECK_MSG else: infrastructure.name = name if flag: if request.FILES: if request.FILES.get('cover', None): # 上传图片 img = request.FILES['cover'] ts = int(time.time()) ext = get_extension(img.name) key = 'cover_{}.{}'.format(ts, ext) handle_uploaded_file(img, key) upload(key, os.path.join(UPLOAD_DIR, key)) infrastructure.cover = key infrastructure.save() infrastructure.order_no = infrastructure.id infrastructure.save() return HttpResponseRedirect(reverse('web:infrastructure_list')) else: context['client'] = infrastructure context['error'] = error return render(request, 'super/housing/infrastructure/create.html', context)
def housing_resource_edit(request, housing_resources_id): c_user = request.session.get('c_user', {}) profile = Profile.obs.get_queryset().filter(pk=c_user.get('id', 0)).first() infrastructures = Infrastructure.objects.filter( is_del=False, is_valid=True).order_by('-order_no') housing_resources = HousingResources.objects.get(pk=housing_resources_id) house_configs = HouseConfig.obs.get_queryset().order_by('-order_no') if request.method == 'POST': content = request.POST.get('content', '') lease = request.POST.get('lease', 0) category = request.POST.get('category', '') province = request.POST.get('province', '') city = request.POST.get('city', '') area = request.POST.get('area', '') bet = request.POST.get('bet', 0) month_rent = request.POST.get('month_rent', 0) pay = request.POST.get('pay', 0) direction = request.POST.get('direction', 0) layer = request.POST.get('layer', 0) total_layer = request.POST.get('total_layer', 0) community = request.POST.get('community', '') address = request.POST.get('address', '') infrastructures = request.POST.getlist('infrastructures', '') bus = request.POST.get('bus', '') subway = request.POST.get('subway', '') buy = request.POST.get('buy', '') sitting_room = request.POST.get('sitting_room', '') sitting_room_area = request.POST.get('sitting_room_area', '') sitting_room_complete = request.POST.getlist('sitting_room_complete', '') bedroom_count = request.POST.get('bedroom_count', 0) bedroom_files = request.POST.get('bedroom_files', '') # try: # 保存房源信息 with transaction.atomic(): housing_resources.user = profile.get_user() housing_resources.content = content housing_resources.lease = lease housing_resources.category = category housing_resources.province = province housing_resources.bet = bet housing_resources.pay = pay housing_resources.direction = direction housing_resources.layer = layer housing_resources.total_layer = total_layer housing_resources.community = community housing_resources.month_rent = month_rent housing_resources.address = address housing_resources.bus = bus housing_resources.subway = subway housing_resources.buy = buy housing_resources.audit_status = 0 housing_resources.sitting_room_area = float( sitting_room_area) if sitting_room_area else 0 housing_resources.save() # 获取基础设施 infrastructure_list = Infrastructure.objects.filter( pk__in=infrastructures).all() housing_resources.infrastructure = infrastructure_list if not sitting_room: housing_resources.sitting_room = 1 if isinstance(sitting_room_complete, list): housing_resources.sitting_room_complete = ','.join( sitting_room_complete) housing_resources.save() if bedroom_files: HousingPicture.objects.filter( housing_resources=housing_resources).delete() bedroom_files = bedroom_files.rstrip(',').split(',') for index, b in enumerate(bedroom_files): if not index: housing_resources.cover = b housing_resources.save() HousingPicture.objects.create( housing_resources=housing_resources, picture=b, ) if request.FILES: if request.FILES.get('deedPic', None): # 上传图片 id_card_picture = request.FILES['deedPic'] ts = int(time.time()) ext = get_extension(id_card_picture.name) key = 'id_card_picture_{}.{}'.format(ts, ext) handle_uploaded_file(id_card_picture, key) upload(key, os.path.join(UPLOAD_DIR, key)) housing_resources.house_pcover = key housing_resources.save() # 存储卧室信息 Bedroom.obs.get_queryset().filter( housing_resources=housing_resources).delete() for i in range(1, int(bedroom_count) + 1): areai = request.POST.get('area' + str(i), 0) detailsi = request.POST.getlist('details' + str(i), []) logging.error(detailsi) logging.error('------------detailsi--------------') detailsi = [int(d) for d in detailsi] house_configs = HouseConfig.obs.get_queryset().filter( pk__in=detailsi) bedroom = Bedroom.objects.create( housing_resources=housing_resources, area=areai, ) bedroom.house_config = house_configs bedroom.save() # 获取支付的金额 # setting = Setting.objects.filter( # is_del=False, # is_valid=True, # code='housing_resources_pay' # ).first() # # 创建订单 # hro = HousingResourcesOrder.objects.create( # user=profile.get_user(), # order_num=generate_order_num(), # total_fee=setting.value, # real_fee=setting.value, # status=1 # ) # subject = u'房源发布' # channel = 'alipay_pc_direct' # if not hro.pay_way: # channel = 'alipay_pc_direct' # client_ip = '127.0.0.1' # success_url = DOMAIN + '/hrs' # charge_id = create_ping_order(hro.order_num, subject, subject, hro.real_fee, channel, client_ip, success_url=success_url) return JsonResponse({'error_code': 0, 'error_msg': '提交审核成功'}) context = { 'module': 'index', 'sub_module': 'housing_resource_create', 'client': profile, 'infrastructures': infrastructures, 'housing_resources': housing_resources, 'qiniu_domain': QINIU_DOMAIN, 'house_configs': house_configs, } return render(request, 'frontend/user/05-4-member02.html', context)
def create(request): context = {'module': 'listings', 'qq_map_api_url': QQ_MAP_API_URL} infrastructures = Infrastructure.obs.get_queryset().order_by('-order_no') context['infrastructures'] = infrastructures if request.method == 'POST': error = {} content = request.POST.get('content', '') lease = request.POST.get('lease', 0) category = request.POST.get('category', '') province = request.POST.get('province', '') city = request.POST.get('city', '') area = request.POST.get('area', '') bet = request.POST.get('bet', 0) month_rent = request.POST.get('month_rent', 0) pay = request.POST.get('pay', 0) direction = request.POST.get('direction', 0) layer = request.POST.get('layer', 0) total_layer = request.POST.get('total_layer', 0) community = request.POST.get('community', '') address = request.POST.get('address', '') bus = request.POST.get('bus', '') subway = request.POST.get('subway', '') buy = request.POST.get('buy', '') sitting_room = request.POST.get('sitting_room', 0) sitting_room_area = request.POST.get('sitting_room_area', 0) sitting_room_complete = request.POST.getlist('sitting_room_complete', []) infrastructure_id = request.POST.getlist('infrastructure_id', []) lng = request.POST.get('lng', 0) lat = request.POST.get('lat', 0) flag = True housing_resources = HousingResources() if not len(content): flag = False error['content_msg'] = FILED_CHECK_MSG else: housing_resources.content = content if flag: if request.FILES: if request.FILES.get('cover', None): # 上传图片 img = request.FILES['cover'] ts = int(time.time()) ext = get_extension(img.name) key = 'cover_{}.{}'.format(ts, ext) handle_uploaded_file(img, key) upload(key, os.path.join(UPLOAD_DIR, key)) housing_resources.cover = key if request.FILES.get('house_pcover', None): # 上传图片 img = request.FILES['house_pcover'] ts = int(time.time()) ext = get_extension(img.name) key = 'house_pcover_{}.{}'.format(ts, ext) handle_uploaded_file(img, key) upload(key, os.path.join(UPLOAD_DIR, key)) housing_resources.house_pcover = key # 获取基础设施 infrastructure_id = [int(i) for i in infrastructure_id] if infrastructure_id: infrastructures = Infrastructure.objects.filter( pk__in=infrastructure_id) housing_resources.infrastructure = infrastructures if sitting_room_complete: housing_resources.sitting_room_complete = ','.join( sitting_room_complete) housing_resources.lease = lease housing_resources.category = category housing_resources.month_rent = month_rent housing_resources.lat = lat housing_resources.lng = lng housing_resources.bet = bet housing_resources.pay = pay housing_resources.direction = direction housing_resources.sitting_room = sitting_room housing_resources.layer = layer housing_resources.total_layer = total_layer housing_resources.community = community housing_resources.bus = bus housing_resources.subway = subway housing_resources.buy = buy housing_resources.province = province housing_resources.city = city housing_resources.area = area housing_resources.address = address housing_resources.sitting_room_area = sitting_room_area housing_resources.status = 2 housing_resources.audit_status = 2 housing_resources.save() return HttpResponseRedirect(reverse('web:listings_list')) else: context['client'] = housing_resources context['error'] = error return render(request, 'super/housing/listings/create.html', context)