Ejemplo n.º 1
0
def login(request):
    posted_data = {}
    user = UserDetail(request).getLoginUser()
    if user:
        if UserDetail(request).is_vendor():
            return redirect("/dashboard")
        else:
            return redirect("/mvpadmin")
    if request.method == "POST":
        posted_data = request.POST
        emailid = request.POST['emailid']
        password = request.POST['password']

        form = LoginForm(request.POST, request=request)

        if form.is_valid():
            user = Account.objects.get(emailid=emailid)
            # user_id = user.id
            # user_type= user.account_id
            # request.session['user_id'] = user_id
            UserDetail(request).setSession(user)
            if UserDetail(request).is_admin():
                return redirect('/mvpadmin')
            return redirect('/dashboard')
    else:
        form = LoginForm(request=request)
    return render(request, "login.html", {
        'form': form,
        'posted_data': posted_data
    })
def index(request):

	user=UserDetail(request).getLoginUser()	

	if not user:
		return redirect("/")

	if UserDetail(request).is_vendor():
		if request.path == '/mvpadmin/':
			return redirect('/dashboard')

	products_list = []
	merchants_list = []

	try:
		raw_query = "select * from merchants_productdetail where vendor_id={user} group by product_id".format(user=user['id'])
		products_count = ProductDetail.objects.raw(raw_query)
		for p in products_count:
			products_list.append(p.id)
	except:
		pass

	try:
		query = "select * from merchants_productdetail where vendor_id={user} group by merchant_id".format(user=user['id'])
		merchants_count = ProductDetail.objects.raw(query)

		for m in merchants_count:
			merchant_id = m.merchant_id
			detail = AccountDetail.objects.get(id=merchant_id)
			merchants_list.append({'username': detail.username, 'email': detail.email, 'platform': detail.platform, 'shopify_domain': detail.shopify_domain, 'main_domain': detail.main_domain, 'merchant_id': merchant_id})
	except:
		pass

	products_length = 0
	if products_list:
		products_length = len(products_list)
		
	total_merchants = AccountDetail.objects.all().count()

	today = date.today()

	total_orders = 0

	user_id = user['id']

	if UserDetail(request).is_vendor():
		total_orders = OrderProducts.objects.filter(user_id=user_id, date__month=today.month, date__year=today.year).values_list('order_id').distinct().count()
	else:
		total_orders = Orders.objects.filter(date__month=today.month, date__year=today.year).count()

	total_vendors = Account.objects.filter(account_id=3).count()
	return render(request,"index.html", {'total_vendors': total_vendors, 'page_name': 'Dashboard', 'products_length': products_length, 'merchants_list': merchants_list, 'total_merchants': total_merchants, 'total_orders': total_orders})
def denyaccess(request):
	merchant_id = request.POST['merchant_id']
	status = request.POST['status']

	user=UserDetail(request).getLoginUser()
	vendor_id = user['id']

	response = {}

	existing_access = DenyAccess.objects.filter(merchant_id=merchant_id, vendor_id=vendor_id)

	if status == "yes":
		if not existing_access:
			try:
				detail = DenyAccess(merchant_id=merchant_id, vendor_id=vendor_id)
				detail.save()
				response = {"success": "Merchant is not allowed to access your products."}
			except:
				response = {"error": "Error while updating!"}
		else:
			response = {"already_updated": "Merchant is not allowed to access your products."}
	else:
		if existing_access:
			DenyAccess.objects.filter(merchant_id=merchant_id, vendor_id=vendor_id).delete()
			response = {"success": "Merchant is allowed to access your products."}
	return HttpResponse(json.dumps(response))
def merchants_list(request):
	user=UserDetail(request).getLoginUser()

	merchants_accounts = AccountDetail.objects.all().order_by('id').reverse()
	paginator=Paginator(list(merchants_accounts),10)
	page=request.GET.get("page")
	try:
		merchants_accounts=paginator.page(page)
	except PageNotAnInteger:
		merchants_accounts=paginator.page(1)
	except EmptyPage:
		merchants_accounts=paginator.page(paginator.num_pages)

	if not user:
		#messages.add_message(request, messages.INFO, 'Please login firstly !!')
		return redirect("/")
	else:
		account_type = user['account_type']['admin']

		if account_type == False:
			vendor_id = user['id']
			deniedusers = []
			denied_users = DenyAccess.objects.filter(vendor_id=vendor_id).order_by('id').reverse()
			for denied_user in denied_users:
				deniedusers.append(denied_user.merchant_id)
			return render(request, "show_merchants.html", {'page_name': 'merchants_list', 'merchants_accounts': merchants_accounts, 'deniedusers': deniedusers})
			#return render(request, "not_allowed.html", {})

	return render(request, "merchants_list.html", {'page_name': 'merchants_list', 'merchants_accounts': merchants_accounts})
Ejemplo n.º 5
0
def add_image(request):
    if 'token' in request.POST:
        token = request.POST['token']

    userdetail = UserDetail(request).getLoginUser()
    user_id = userdetail['id']

    data = {}

    if 'file' in request.FILES:
        image = request.FILES.get('file')
        file_type = image.content_type.split('/')[0]

        print "\n\n type of image :   ", type(file_type)

        if str(file_type) != "image":
            data = {'is_valid': False, 'message': 'Please upload Images Only.'}
            return HttpResponse(json.dumps(data))
        try:
            images = Images(user_id=user_id, image=request.FILES.get('file'))
            images.save()
            token = images.token
            image_id = images.id
            image_name = images.image_name
            url = "http://" + request.META['HTTP_HOST'] + "/images/view/" + str(
                token) + "/" + str(image_id)
            data = {
                'is_valid': True,
                'name': image_name,
                'url': url,
                'token': token
            }
        except:
            data = {'is_valid': False, 'message': 'Cannot Be Uploaded.'}
    return HttpResponse(json.dumps(data))
Ejemplo n.º 6
0
def vendors(request):

	user=UserDetail(request).getLoginUser()	
	if not user:
		#messages.add_message(request, messages.INFO, 'Please login firstly !!')
		return redirect("/")
	else:
		account_type = user['account_type']['admin']

		if account_type == False:
			return render(request, "not_allowed.html", {})

	user_id = request.GET['user_id']
	
	products_list = []
	sql='SELECT dp.*, di.* FROM shopify_products AS dp LEFT JOIN (SELECT t1.* FROM images_images t1 WHERE t1.updated_date =(SELECT MAX(t2.updated_date) FROM images_images t2 WHERE t2.product_id = t1.product_id) ) di ON dp.id = di.product_id  where dp.user_id={0} ORDER BY di.product_id'.format(user_id)
	products = Products.objects.raw(sql)
	paginator=Paginator(list(products),6)
	page=request.GET.get("page")
	try:
		products=paginator.page(page)
	except PageNotAnInteger:
		products=paginator.page(1)
	except EmptyPage:
		products=paginator.page(paginator.num_pages)

	login_user = "******"
	page = "dashboard"

	if UserDetail(request).is_vendor():
		login_user = "******"
	else:
		login_user = "******"
		page = "products"

	vendor_detail = Vendor.objects.get(user_id=user_id)
	vendor_name = vendor_detail.vendor

	page_name = "Vendor Products"

	return render(request, "dashboard.html", {'products_list': products, 'login_user': login_user, 'page': page, 'vendor_name': vendor_name, 'page_name': page_name, 'user_id': user_id})
    def clean(self):
        title = self.request.POST['title']

        user = UserDetail(self.request).getLoginUser()
        user_id = user['id']

        existing_title = Products.objects.filter(user_id=user_id, title=title)
        if existing_title:
            raise forms.ValidationError(_("Title Already Exists."))

        sku = self.request.POST['sku']
        if sku:
            existing = Products.objects.filter(sku=sku)
            if existing:
                raise forms.ValidationError(_("SKU Already Exists"))
        return self.cleaned_data
def vendors_list(request):

	user=UserDetail(request).getLoginUser()	
	if not user:
		#messages.add_message(request, messages.INFO, 'Please login firstly !!')
		return redirect("/")
	else:
		account_type = user['account_type']['admin']

		if account_type == False:
			return render(request, "not_allowed.html", {})
	users = Account.objects.filter(account_id=3).order_by('id').reverse()

	users_list = []

	for user in users:
		fname = user.first_name
		lname = user.last_name
		user_name = fname + " " + lname
		user_name = user_name.title()
		status = user.status
		user_id = user.id

		#commission
		commission = 0
		com = Commission.objects.filter(user_id=user_id)
		if com:
			commission = com[0].commission
		try:
			vendor_detail = Vendor.objects.get(user_id=user_id)
			vendor_name = vendor_detail.vendor
			users_list.append({'user_name': vendor_name, 'status': status, 'user_id': user_id, 'commission': commission})
		except:
			pass

	paginator=Paginator(list(users_list),10)
	page=request.GET.get("page")
	try:
		users_list=paginator.page(page)
	except PageNotAnInteger:
		users_list=paginator.page(1)
	except EmptyPage:
		users_list=paginator.page(paginator.num_pages)

	return render(request, "vendors_list.html", {'page_name': 'vendors_list', 'users_list': users_list})
def labels_orders(request):
	user=UserDetail(request).getLoginUser()	
	if not user:
		return redirect("/")
	else:
		account_type = user['account_type']['admin']

		if account_type == False:
			return render(request, "not_allowed.html", {})

	users = Account.objects.filter(account_id=3).order_by('id').reverse()

	users_list = []

	today = date.today()

	for user in users:
		user_id = user.id
		try:
			vendor_detail = Vendor.objects.get(user_id=user_id)
			vendor_name = vendor_detail.vendor

			orders_count = OrderProducts.objects.filter(user_id=user_id, date__month=today.month, date__year=today.year).values_list('order_id').distinct().count()

			orders = OrderProducts.objects.filter(user_id=user_id, date__month=today.month, date__year=today.year)

			serializer = OrderProductsSerializer(orders, many=True, context={'user_id': user_id, 'user_type': 'admin'})

			total_amount = sum([order['total_price'] for order in serializer.data])

			if orders_count != 0:
				users_list.append({'label': vendor_name, 'user_id': user_id, 'orders_count': orders_count, 'total_amount': total_amount})
		except:
			pass

	paginator=Paginator(list(users_list),10)
	page=request.GET.get("page")
	try:
		users_list=paginator.page(page)
	except PageNotAnInteger:
		users_list=paginator.page(1)
	except EmptyPage:
		users_list=paginator.page(paginator.num_pages)

	return render(request, "labels_orders.html", {'page_name': 'labels_orders', 'users_list': users_list})
    def post(self, request):
        form = AddAccountForm(request.POST, request=request)

        if 'email' not in request.POST or not request.POST['email']:
            response = {'error': 'Please enter Email.'}
            return HttpResponse(json.dumps(response))

        if 'platform' not in request.POST or not request.POST['platform']:
            response = {'error': 'Please enter Platform.'}
            return HttpResponse(json.dumps(response))

        if 'name' not in request.POST or not request.POST['name']:
            response = {'error': 'Please enter Name.'}
            return HttpResponse(json.dumps(response))

        if 'myshopify_domain' not in request.POST or not request.POST[
                'myshopify_domain']:
            response = {'error': 'Please enter Shopify Domain.'}
            return HttpResponse(json.dumps(response))

        if 'domain' not in request.POST or not request.POST['domain']:
            response = {'error': 'Please enter Domain.'}
            return HttpResponse(json.dumps(response))

        if 'token' not in request.POST or not request.POST['token']:
            response = {'error': 'Please enter Token.'}
            return HttpResponse(json.dumps(response))

        if 'HTTP_API_KEY' not in request.META or not request.META[
                'HTTP_API_KEY']:
            existing_detail = AccountDetail.objects.filter(
                platform=platform, shopify_domain=shopify_domain)
            if not existing_detail:
                response = {"error": "You don't have access to add merchant."}
                return HttpResponse(json.dumps(response))
        else:
            api_key = request.META['HTTP_API_KEY']
            if api_key != "pbkdf2_sha256$29000$p7lpJChcK4Lo$IHMul9j5lcPNJP4f/W1nXZknVi2N+GJIR1tZCo5C7uM=":
                response = {"error": "You don't have access to add merchant."}
                return HttpResponse(json.dumps(response))

        email = request.POST['email']
        platform = request.POST['platform']
        username = request.POST['name']
        shopify_domain = request.POST['myshopify_domain']
        main_domain = request.POST['domain']
        token = request.POST['token']

        update(platform, shopify_domain, main_domain, token)

        isenabled = False
        response = {}

        if form.is_valid():
            existing_detail = AccountDetail.objects.filter(
                platform=platform, shopify_domain=shopify_domain)
            if not existing_detail:
                try:
                    detail = AccountDetail(email=email,
                                           platform=platform,
                                           username=username,
                                           shopify_domain=shopify_domain,
                                           main_domain=main_domain,
                                           token=token)
                    detail.save()
                    access_token = binascii.hexlify(os.urandom(20)).decode()
                    AccessToken.objects.create(merchant_id=detail.id,
                                               access_token=access_token)

                    admin_detail = UserDetail(request).get_admin()
                    admin_email = admin_detail.emailid

                    # email1
                    Vars1 = {"account_type": "retailer"}
                    template_id1 = "138014"
                    send_template(admin_email, Vars1, template_id1)

                    # email2
                    Vars = {
                        "first_name": username,
                        "merchant_name": shopify_domain
                    }
                    template_id = "136351"
                    send_template(email, Vars, template_id)
                    enabled = int(detail.status)
                    if enabled == 1:
                        isenabled = True
                    response = {
                        'Success': 'Saved Successfully',
                        'is_enabled': isenabled,
                        'access_token': access_token
                    }
                except:
                    response = {'error': 'Error While Saving!'}
                    return HttpResponse(json.dumps(response))
            else:
                is_deleted = int(existing_detail[0].is_deleted)

                if is_deleted == 1:
                    admin_detail = UserDetail(request).get_admin()
                    admin_email = admin_detail.emailid
                    Vars1 = {"account_type": "retailer"}
                    template_id1 = "138014"
                    send_template(admin_email, Vars1, template_id1)

                    # email2
                    Vars = {
                        "first_name": username,
                        "merchant_name": shopify_domain
                    }
                    template_id = "136351"
                    send_template(email, Vars, template_id)
                    AccountDetail.objects.filter(
                        platform=platform,
                        shopify_domain=shopify_domain).update(is_deleted=0)

                enabled = int(existing_detail[0].status)
                if enabled == 1:
                    isenabled = True
                merchant_id = existing_detail[0].id
                token_detail = AccessToken.objects.get(merchant_id=merchant_id)
                access_token = token_detail.access_token
                response = {
                    'is_enabled': isenabled,
                    'access_token': access_token
                }
        else:
            form = str(form)
            soup = BeautifulSoup(form, 'html.parser')
            if soup:
                ul = soup.find("ul", {"class": "errorlist nonfield"})
                if ul:
                    error = ul.find("li").text
                    response = {'error': error, 'is_enabled': isenabled}
                    return HttpResponse(json.dumps(response))
        return HttpResponse(json.dumps(response))
Ejemplo n.º 11
0
def register(request):
    posted_data = {}
    #get the current page url request.build_absolute_uri()
    if request.method == "POST":

        posted_data = request.POST
        form = RegisterForm(request.POST, request=request)
        if form.is_valid():
            first_name = request.POST['first_name']
            last_name = request.POST['last_name']
            emailid = request.POST['emailid']
            password = request.POST['password']
            website = request.POST['website']
            country = request.POST['country']

            if not website.startswith("http://"):
                website = "http://" + website

            encrypted_password = handler.encrypt(password)

            if 'vendor' in request.POST:
                account_type = AccountType.objects.get(type="vendor")
            else:
                account_type = AccountType.objects.get(type="user")

            detail = Account(first_name=first_name,
                             last_name=last_name,
                             emailid=emailid,
                             paypal_emailid=emailid,
                             password=encrypted_password,
                             account_id=account_type.id,
                             website=website,
                             country=country)
            detail.save()
            if account_type.type == "vendor":
                vendor_detail = Vendor(user_id=detail.id,
                                       vendor=request.POST['vendor'])
                vendor_detail.save()

                link = "http://" + request.META['HTTP_HOST']

                admin_detail = UserDetail(request).get_admin()
                admin_email = admin_detail.emailid

                # add commission
                add_commission = Commission(user_id=detail.id, commission=10)
                add_commission.save()

                # email1
                Vars1 = {"account_type": "label"}
                template_id1 = "138014"
                send_template(admin_email, Vars1, template_id1)

                # email2
                Vars = {
                    "first_name": first_name,
                    "label_name": request.POST['vendor']
                }
                template_id = "136350"
                send_template(emailid, Vars, template_id)

                messages.add_message(
                    request, messages.SUCCESS,
                    'Registered Successfully. We will send you an email once your application and account has been approved.'
                )
            return redirect("/")

            #return HttpResponse("Registered Successfully. Please check your mail to activate your account.")
    else:
        form = RegisterForm(request=request)

    all_countries = []

    countries_list = list(pycountry.countries)
    for country in countries_list:
        all_countries.append(country.name)

    return render(request, "register.html", {
        'form': form,
        'posted_data': posted_data,
        'all_countries': all_countries
    })
Ejemplo n.º 12
0
def logout(request):
    UserDetail(request).clearSession()
    return redirect('/')
Ejemplo n.º 13
0
def index(request):
	if UserDetail(request).is_vendor():
		return redirect("/dashboard")

	total_vendors = Account.objects.filter(account_id=3).count()
	return render(request,"index.html", {'total_vendors': total_vendors, 'page': 'dashboard'})
Ejemplo n.º 14
0
def orders_list(request):
    user = UserDetail(request).getLoginUser()
    if not user:
        return redirect("/")

    user_id = user['id']

    today = date.today()

    orders = OrderProducts.objects.filter(user_id=user_id,
                                          date__month=today.month,
                                          date__year=today.year)
    serializer = OrderProductsSerializer(orders,
                                         many=True,
                                         context={'user_type': "vendor"})
    total_amount = sum([order['total_price'] for order in serializer.data])

    filtered_orders = OrderProducts.objects.filter(
        user_id=user_id, date__month=today.month,
        date__year=today.year).values_list('order_id').distinct()

    order_list = []

    for order in filtered_orders:
        order_id = order[0]
        existing_order = Orders.objects.get(id=order_id)
        OrderId = existing_order.OrderId
        order_date = existing_order.date.strftime("%d %B, %Y")
        orderdetail = OrderProducts.objects.filter(order_id=order_id,
                                                   user_id=user_id)

        all_orders = []

        for detail in orderdetail:
            product_name = detail.product_name
            product_price = detail.product_price
            ProductQty = detail.ProductQty
            total_price = 0.00
            if UserDetail(request).is_vendor():
                total_price = ProductQty * product_price
            else:
                commission = 0
                commission_detail = Commission.objects.filter(user_id=user_id)
                if commission_detail:
                    commission = commission_detail[0].commission

                productprice = ProductQty * product_price
                total_price = productprice + productprice * commission / 100

            image = "https://app.fashioncircle.de/media/default_image.gif"

            product_id = detail.product_id
            image_detail = Images.objects.filter(product_id=product_id)
            if image_detail:
                image_name = image_detail[0].image_name
                image_id = image_detail[0].id
                token = image_detail[0].token
                if token:
                    image = "https://" + request.META[
                        'HTTP_HOST'] + "/images/view/" + str(
                            token) + "/" + str(image_id)
            all_orders.append({
                'product_name': product_name,
                'total_price': total_price,
                'ProductQty': ProductQty,
                'image': image
            })
        order_list.append({
            order_id: all_orders,
            'OrderId': OrderId,
            'order_date': order_date
        })

    paginator = Paginator(list(order_list), 6)
    page = request.GET.get("page")
    try:
        order_list = paginator.page(page)
    except PageNotAnInteger:
        order_list = paginator.page(1)
    except EmptyPage:
        order_list = paginator.page(paginator.num_pages)

    date_obj = today.strftime("%B")

    vendor_name = "Orders of Month : " + str(date_obj)
    return render(
        request, "dashboard.html", {
            'page_name': 'Orders',
            'vendor_name': vendor_name,
            'products_type': 'orders_products',
            'total_amount': total_amount,
            'order_list': order_list
        })
Ejemplo n.º 15
0
def add_product(request):
    posted_data = {}
    user = UserDetail(request).getLoginUser()
    if not user:
        #messages.add_message(request, messages.INFO, 'Please login firstly !!')
        return redirect("/")

    user_id = user['id']
    login_user = "******"
    page = "add_product"

    if UserDetail(request).is_vendor():
        login_user = "******"
    else:
        login_user = "******"

    if request.method == "POST":
        posted_data = request.POST
        title = request.POST['title']
        description = request.POST['description']
        category = request.POST['category']
        selling_price = float(request.POST['selling_price'])
        compare_price = float(request.POST['compare_price'])

        token = request.POST['token']

        if 'is_tax' in request.POST:
            is_tax = request.POST['is_tax']
        else:
            is_tax = 0
        if 'sku' in request.POST:
            sku = request.POST['sku']
        else:
            sku = 0
        barcode = request.POST['barcode']
        user_id = user_id

        form = ProductForm(request.POST, request=request)
        if form.is_valid():
            product_detail = Products(user_id=user_id,
                                      title=title,
                                      description=description,
                                      selling_price=selling_price,
                                      compare_price=compare_price,
                                      sku=sku,
                                      barcode=barcode,
                                      category_id=category)
            product_detail.save()
            product_id = product_detail.id

            # images
            Images.objects.filter(token=token).update(product_id=product_id)

            #messages.add_message(request, messages.SUCCESS, 'Products saved successfully')
            if login_user == "vendor":
                return redirect("/dashboard")
            else:
                return redirect('/mvpadmin/products')
    else:
        form = ProductForm(request=request)

    vendor = ''

    categories_list = []

    categories = Categories.objects.filter(user_id=1)
    for category in categories:
        category_id = category.id
        category_name = category.title
        categories_list.append({
            'category_id': category_id,
            'category_name': category_name
        })
    user_detail = Account.objects.filter(id=user_id)
    # if user_detail:
    # 	vendor = user_detail[0].account_id
    return render(
        request, "add_product.html", {
            'categories_list': categories_list,
            'login_user': login_user,
            'form': form,
            'page': page,
            'posted_data': posted_data
        })
def label_order(request):
	user=UserDetail(request).getLoginUser()	
	if not user:
		return redirect("/")
	else:
		account_type = user['account_type']['admin']

		if account_type == False:
			return render(request, "not_allowed.html", {})

	try:
		label = request.GET['label']
	except:
		response = {"Error": "Please enter label."}
		return HttpResponse(json.dumps(response))

	today = date.today()
	date_obj = today.strftime("%B")
	vendor_name = "Orders of Month : " + str(date_obj)

	label_detail = Vendor.objects.get(vendor=label)
	user_id = label_detail.user_id

	existing_label = label
	
	filtered_orders = OrderProducts.objects.filter(user_id=user_id, date__month=today.month, date__year=today.year).values_list('order_id').distinct()

	order_list = []

	for order in filtered_orders:
		order_id = order[0]
		existing_order = Orders.objects.get(id=order_id)
		OrderId = existing_order.OrderId
		merchant_id = existing_order.merchant_id
		platform = existing_order.platform
		order_date = existing_order.date.strftime("%d %B, %Y")

		# merchant detail
		merchant_detail = AccountDetail.objects.get(id=merchant_id)
		shopify_domain = merchant_detail.shopify_domain

		orderdetail = OrderProducts.objects.filter(order_id=order_id, user_id=user_id)

		all_orders = []

		for detail in orderdetail:
			product_name = detail.product_name
			product_price = detail.product_price
			ProductQty = detail.ProductQty

			commission = 0
			commission_detail = Commission.objects.filter(user_id=user_id)
			if commission_detail:
				commission = commission_detail[0].commission

			productprice = ProductQty * product_price
			total_price = productprice + productprice * commission / 100

			image = "https://app.fashioncircle.de/media/default_image.gif"

			product_id = detail.product_id
			image_detail = Images.objects.filter(product_id=product_id)
			if image_detail:
				image_name = image_detail[0].image_name
				image_id = image_detail[0].id
				token = image_detail[0].token
				if token:
					image = "https://"+ request.META['HTTP_HOST'] + "/images/view/" + str(token) + "/" + str(image_id)

			all_orders.append({'product_name': product_name, 'total_price': total_price, 'ProductQty': ProductQty, 'image': image})
		order_list.append({order_id: all_orders, 'OrderId': OrderId, 'platform': platform, 'shopify_domain': shopify_domain, 'order_date': order_date})

	paginator=Paginator(list(order_list),6)
	page=request.GET.get("page")
	try:
		order_list=paginator.page(page)
	except PageNotAnInteger:
		order_list=paginator.page(1)
	except EmptyPage:
		order_list=paginator.page(paginator.num_pages)

	orders = OrderProducts.objects.filter(user_id=user_id, date__month=today.month, date__year=today.year)
	serializer = OrderProductsSerializer(orders, many=True, context={'user_type': 'admin'})
	total_amount = sum([order['total_price'] for order in serializer.data])

	return render(request, "dashboard.html", {'page_name': 'Label Orders', 'vendor_name': vendor_name, 'products_type': 'orders_products', 'total_amount': total_amount, 'order_list': order_list, 'existing_label': existing_label})
Ejemplo n.º 17
0
def dashboard(request):
    user = UserDetail(request).getLoginUser()
    if not user:
        #messages.add_message(request, messages.INFO, 'Please login firstly !!')
        return redirect("/")
    user_id = user['id']
    products_list = []
    products = []
    # sql='SELECT dp.*, di.* FROM shopify_products AS dp LEFT JOIN (SELECT t1.* FROM images_images t1 WHERE t1.updated_date =(SELECT MAX(t2.updated_date) FROM images_images t2 WHERE t2.product_id = t1.product_id) ) di ON dp.id = di.product_id LEFT JOIN shopify_account as ac ON dp.user_id=ac.id WHERE dp.user_id={0} AND ac.is_app_uninstall=False ORDER BY di.product_id'.format(user_id)
    accounts = Account.objects.filter(id=user_id)
    check_status = accounts[0].is_app_uninstall
    if check_status is False:
        product = Products.objects.filter(user_id=user_id)
        for prod in product:
            id = prod.id
            title = prod.title
            description = prod.description
            selling_price = prod.selling_price
            dropshipping_price = prod.dropshipping_price
            wholesale_price = prod.wholesale_price
            sku = prod.sku
            quantity = prod.quantity
            image = Images.objects.filter(
                user_id=user_id, product_id=prod.id).order_by('-id')[0]
            image = image.image
            weight = prod.weight
            weight_unit = prod.weight_unit
            # image=image[-1]
            products.append({
                'id': id,
                'title': title,
                'description': description,
                'selling_price': selling_price,
                'dropshipping_price': dropshipping_price,
                'wholesale_price': wholesale_price,
                'sku': sku,
                'quantity': quantity,
                'image': image,
                'weight': weight,
                'weight_unit': weight_unit
            })
    else:
        product = Products.objects.filter(user_id=user_id, PlatformProductId=0)
        for prod in product:
            id = prod.id
            title = prod.title
            description = prod.description
            selling_price = prod.selling_price
            dropshipping_price = prod.dropshipping_price
            wholesale_price = prod.wholesale_price
            sku = prod.sku
            quantity = prod.quantity
            image = Images.objects.filter(
                user_id=user_id, product_id=prod.id).order_by('-id')[0]
            image = image.image
            weight = prod.weight
            weight_unit = prod.weight_unit

            products.append({
                'id': id,
                'title': title,
                'description': description,
                'selling_price': selling_price,
                'dropshipping_price': dropshipping_price,
                'wholesale_price': wholesale_price,
                'sku': sku,
                'quantity': quantity,
                'image': image,
                'weight': weight,
                'weight_unit': weight_unit
            })

    paginator = Paginator(list(products), 6)
    page = request.GET.get("page")
    try:
        products = paginator.page(page)
    except PageNotAnInteger:
        products = paginator.page(1)
    except EmptyPage:
        products = paginator.page(paginator.num_pages)

    login_user = "******"
    page_name = "My Products"

    all_images = Images.objects.filter(user_id=user_id)

    if UserDetail(request).is_vendor():
        login_user = "******"
    else:
        login_user = "******"
        page_name = "My Products"

    vendor_name = "My Products"

    return render(
        request, "dashboard.html", {
            'products_list': products,
            'login_user': login_user,
            'page': page,
            'vendor_name': vendor_name,
            'page_name': page_name
        })