Exemple #1
0
    def post(self, request, step):
        if step == 2:
            params = dict(request.POST)
            image_first_filename = str(int(
                time.time())) + request.FILES['project_image_first'].name
            file_obj = request.FILES['project_image_first']
            with default_storage.open(
                    MEDIA_ROOT + '/uploadimage/' + image_first_filename,
                    'wb+') as file:
                for chunk in file_obj.chunks():
                    file.write(chunk)
            image_first_upload = 'uploadimage/' + image_first_filename
            params['project_image_first'] = image_first_upload

            image_detail_filename = str(int(
                time.time())) + request.FILES['project_image_detail'].name
            file_obj = request.FILES['project_image_detail']
            with default_storage.open(
                    MEDIA_ROOT + '/uploadimage/' + image_detail_filename,
                    'wb+') as file:
                for chunk in file_obj.chunks():
                    file.write(chunk)
            image_detail_upload = 'uploadimage/' + image_detail_filename
            params['project_image_detail'] = image_detail_upload

            project = Project()
            project.name = request.POST['project_name']
            project.desc = request.POST['project_desc']
            project.target_fund = request.POST['project_target_fund']
            project.deadline = request.POST['project_deadline']
            project.user_desc = request.POST['project_user_desc']
            project.user_detail = request.POST['project_user_detail']
            project.mobile = request.POST['project_mobile']
            project.service_mobile = request.POST['project_service_mobile']
            project.image_first = params['project_image_first']
            project.image_detail = params['project_image_detail']
            project.admin_id = request.user.id
            project.category_id = request.POST['project_category']
            project.company_id = Company.objects.get(
                admin_id=project.admin_id).id
            project.tags_id = 1
            project.save()
            request.session['temp_project_id'] = project.id
            return JsonResponse({'status': 'success'})

        if step == 3:
            params = dict(request.POST)
            item_image_filename = str(int(
                time.time())) + request.FILES['item_image'].name
            file_obj = request.FILES['item_image']
            with default_storage.open(
                    MEDIA_ROOT + '/uploadimage/' + item_image_filename,
                    'wb+') as file:
                for chunk in file_obj.chunks():
                    file.write(chunk)
            item_image_upload = 'uploadimage/' + item_image_filename
            params['item_image'] = item_image_upload

            project_item = ProjectItem()
            project_item.item_category = request.POST['item_category']
            project_item.item_value = request.POST['item_value']
            project_item.how_to_get = request.POST['how_to_get']
            project_item.item_nums = request.POST['item_nums']
            project_item.up_to_buy = request.POST['up_to_buy']
            project_item.project_id = request.session['temp_project_id']
            project_item.invoice = request.POST['invoice']
            project_item.item_send_day = request.POST['item_send_day']
            project_item.item_image = params['item_image']
            project_item.support_nums = 0 if not request.POST[
                'support_nums'] else request.POST['support_nums']
            project_item.item_freight = int(request.POST['item_freight'])
            project_item.save()
            return HttpResponse('{"status":"success"}',
                                content_type='application/json')
Exemple #2
0
    def post(self, request, step):
        if step == 2:
            params = dict(request.POST)
            image_first_filename = str(int(
                time.time())) + request.FILES['project_image_first'].name
            file_obj = request.FILES['project_image_first']
            with default_storage.open(
                    MEDIA_ROOT + '/uploadimage/' + image_first_filename,
                    'wb+') as file:
                for chunk in file_obj.chunks():
                    file.write(chunk)
            image_first_upload = 'uploadimage/' + image_first_filename
            params['project_image_first'] = image_first_upload

            image_detail_filename = str(int(
                time.time())) + request.FILES['project_image_detail'].name
            file_obj = request.FILES['project_image_detail']
            with default_storage.open(
                    MEDIA_ROOT + '/uploadimage/' + image_detail_filename,
                    'wb+') as file:
                for chunk in file_obj.chunks():
                    file.write(chunk)
            image_detail_upload = 'uploadimage/' + image_detail_filename
            params['project_image_detail'] = image_detail_upload

            project = Project()
            project.name = request.POST['project_name']
            project.desc = request.POST['project_desc']
            project.target_fund = request.POST['project_target_fund']
            project.deadline = request.POST['project_deadline']
            project.user_desc = request.POST['project_user_desc']
            project.user_detail = request.POST['project_user_detail']
            project.mobile = request.POST['project_mobile']
            project.service_mobile = request.POST['project_service_mobile']
            project.image_first = params['project_image_first']
            project.image_detail = params['project_image_detail']
            project.admin_id = request.user.id
            project.category_id = request.POST['project_category']
            project.company_id = Company.objects.get(
                admin_id=project.admin_id).id
            project.tags_id = 1
            project.save()
            request.session['temp_project_id'] = project.id
            return JsonResponse({'status': 'success'})

        if step == 3:
            params = dict(request.POST)
            item_image_filename = str(int(
                time.time())) + request.FILES['item_image'].name
            file_obj = request.FILES['item_image']
            with default_storage.open(
                    MEDIA_ROOT + '/uploadimage/' + item_image_filename,
                    'wb+') as file:
                for chunk in file_obj.chunks():
                    file.write(chunk)
            item_image_upload = 'uploadimage/' + item_image_filename
            params = {key: value[0] for key, value in params.items()}
            params['item_image'] = item_image_upload
            params['support_nums'] = params['support_nums'] or 0
            params['project_id'] = request.session.get('temp_project_id')
            params.pop('csrfmiddlewaretoken')
            ProjectItem.objects.create(**params)

            return HttpResponse('{"status":"success"}',
                                content_type='application/json')