|
|
|
@ -1,4 +1,6 @@ |
|
|
|
import base64 |
|
|
|
import base64 |
|
|
|
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
|
|
from django.contrib.auth import authenticate, login |
|
|
|
from django.contrib.auth import authenticate, login |
|
|
|
from django.core.mail import mail_managers, mail_admins |
|
|
|
from django.core.mail import mail_managers, mail_admins |
|
|
|
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage |
|
|
|
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage |
|
|
|
@ -19,6 +21,8 @@ from django.http import JsonResponse |
|
|
|
from datetime import datetime |
|
|
|
from datetime import datetime |
|
|
|
from django.conf import settings |
|
|
|
from django.conf import settings |
|
|
|
from django.contrib.sitemaps import Sitemap |
|
|
|
from django.contrib.sitemaps import Sitemap |
|
|
|
|
|
|
|
import xml.etree.ElementTree as ET |
|
|
|
|
|
|
|
from django.http import HttpResponse |
|
|
|
import kkb |
|
|
|
import kkb |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -92,8 +96,8 @@ class CategoryView(CategoryBaseView, TemplateView): |
|
|
|
attr_values = [v.strip() for v in attr_values] |
|
|
|
attr_values = [v.strip() for v in attr_values] |
|
|
|
if attr_values: |
|
|
|
if attr_values: |
|
|
|
self.products_qs = self.products_qs.filter( |
|
|
|
self.products_qs = self.products_qs.filter( |
|
|
|
product_attributes__attribute__attribute__in=attr, |
|
|
|
product_attributes__attribute__attribute__in=attr, |
|
|
|
product_attributes__value__in=attr_values).distinct() |
|
|
|
product_attributes__value__in=attr_values).distinct() |
|
|
|
|
|
|
|
|
|
|
|
def get_brands_by_products(self): |
|
|
|
def get_brands_by_products(self): |
|
|
|
pass |
|
|
|
pass |
|
|
|
@ -105,14 +109,14 @@ class CategoryView(CategoryBaseView, TemplateView): |
|
|
|
|
|
|
|
|
|
|
|
if self.is_search: |
|
|
|
if self.is_search: |
|
|
|
q = self.request.GET.get('q', '') |
|
|
|
q = self.request.GET.get('q', '') |
|
|
|
self.products_qs = Product.objects.filter(title__icontains=q).\ |
|
|
|
self.products_qs = Product.objects.filter(title__icontains=q). \ |
|
|
|
sorted_in_stock_by_field('-pk') |
|
|
|
sorted_in_stock_by_field('-pk') |
|
|
|
brands_pks = [item.brand.pk for item in self.products_qs] |
|
|
|
brands_pks = [item.brand.pk for item in self.products_qs] |
|
|
|
retval['brands'] = Brand.objects.filter(pk__in=brands_pks).order_by( |
|
|
|
retval['brands'] = Brand.objects.filter(pk__in=brands_pks).order_by( |
|
|
|
'title') # list(set(map(lambda item: item.brand, self.products_qs))) |
|
|
|
'title') # list(set(map(lambda item: item.brand, self.products_qs))) |
|
|
|
|
|
|
|
|
|
|
|
elif self.is_sale: |
|
|
|
elif self.is_sale: |
|
|
|
self.products_qs = Product.objects.filter(variations__discount__gt=0).distinct().\ |
|
|
|
self.products_qs = Product.objects.filter(variations__discount__gt=0).distinct(). \ |
|
|
|
sorted_in_stock_by_field('-pk') |
|
|
|
sorted_in_stock_by_field('-pk') |
|
|
|
brands_pks = [item.brand.pk for item in self.products_qs] |
|
|
|
brands_pks = [item.brand.pk for item in self.products_qs] |
|
|
|
retval['brands'] = Brand.objects.filter(pk__in=brands_pks).order_by('title') |
|
|
|
retval['brands'] = Brand.objects.filter(pk__in=brands_pks).order_by('title') |
|
|
|
@ -131,7 +135,7 @@ class CategoryView(CategoryBaseView, TemplateView): |
|
|
|
|
|
|
|
|
|
|
|
if self.brand_pks: |
|
|
|
if self.brand_pks: |
|
|
|
self.products_qs = self.products_qs.filter( |
|
|
|
self.products_qs = self.products_qs.filter( |
|
|
|
brand__pk__in=self.brand_pks) |
|
|
|
brand__pk__in=self.brand_pks) |
|
|
|
|
|
|
|
|
|
|
|
if self.sort: |
|
|
|
if self.sort: |
|
|
|
sort_parameter = dict(self.ORDER_PARAMETERS)[self.sort] |
|
|
|
sort_parameter = dict(self.ORDER_PARAMETERS)[self.sort] |
|
|
|
@ -139,12 +143,12 @@ class CategoryView(CategoryBaseView, TemplateView): |
|
|
|
|
|
|
|
|
|
|
|
if sort_parameter in ['price_min', '-price_min']: |
|
|
|
if sort_parameter in ['price_min', '-price_min']: |
|
|
|
preordered_qs = self.products_qs.extra( |
|
|
|
preordered_qs = self.products_qs.extra( |
|
|
|
select={ |
|
|
|
select={ |
|
|
|
'price_min': |
|
|
|
'price_min': |
|
|
|
'SELECT MIN(price) FROM store_productvariation ' + |
|
|
|
'SELECT MIN(price) FROM store_productvariation ' + |
|
|
|
'WHERE store_productvariation.product_id ' + |
|
|
|
'WHERE store_productvariation.product_id ' + |
|
|
|
'= store_product.id' |
|
|
|
'= store_product.id' |
|
|
|
}) |
|
|
|
}) |
|
|
|
if preordered_qs: |
|
|
|
if preordered_qs: |
|
|
|
self.products_qs = preordered_qs.order_by('-have_stock', sort_parameter) |
|
|
|
self.products_qs = preordered_qs.order_by('-have_stock', sort_parameter) |
|
|
|
else: |
|
|
|
else: |
|
|
|
@ -169,7 +173,7 @@ class ProductView(CategoryBaseView, DetailView): |
|
|
|
self.category = self._get_full_category(kwargs['categories']) |
|
|
|
self.category = self._get_full_category(kwargs['categories']) |
|
|
|
retval = super(ProductView, self).get(request, args, kwargs) |
|
|
|
retval = super(ProductView, self).get(request, args, kwargs) |
|
|
|
ranee = request.session.get('ranee', []) |
|
|
|
ranee = request.session.get('ranee', []) |
|
|
|
#import pdb;pdb.set_trace() |
|
|
|
# import pdb;pdb.set_trace() |
|
|
|
if kwargs['slug'] not in ranee: |
|
|
|
if kwargs['slug'] not in ranee: |
|
|
|
ranee.append(kwargs['slug']) |
|
|
|
ranee.append(kwargs['slug']) |
|
|
|
request.session['ranee'] = ranee |
|
|
|
request.session['ranee'] = ranee |
|
|
|
@ -182,18 +186,19 @@ class ProductView(CategoryBaseView, DetailView): |
|
|
|
retval['form'] = ProductFeedbackForm(self.request.POST or None) |
|
|
|
retval['form'] = ProductFeedbackForm(self.request.POST or None) |
|
|
|
retval['updated'] = ProductsUpdate.objects.last() |
|
|
|
retval['updated'] = ProductsUpdate.objects.last() |
|
|
|
ranee = self.request.session.get('ranee', []) |
|
|
|
ranee = self.request.session.get('ranee', []) |
|
|
|
#import pdb;pdb.set_trace() |
|
|
|
# import pdb;pdb.set_trace() |
|
|
|
#ranee.pop(kwargs['object'].slug) |
|
|
|
# ranee.pop(kwargs['object'].slug) |
|
|
|
retval['ranee'] = [] |
|
|
|
retval['ranee'] = [] |
|
|
|
for i in ranee: |
|
|
|
for i in ranee: |
|
|
|
#import pdb; pdb.set_trace() |
|
|
|
# import pdb; pdb.set_trace() |
|
|
|
if kwargs and i != kwargs['object'].slug: |
|
|
|
if kwargs and i != kwargs['object'].slug: |
|
|
|
try: |
|
|
|
try: |
|
|
|
p = Product.objects.get(slug=i) |
|
|
|
p = Product.objects.get(slug=i) |
|
|
|
if p not in retval['ranee']: |
|
|
|
if p not in retval['ranee']: |
|
|
|
retval['ranee'].append(p) |
|
|
|
retval['ranee'].append(p) |
|
|
|
except: pass |
|
|
|
except: |
|
|
|
#import pdb;pdb.set_trace() |
|
|
|
pass |
|
|
|
|
|
|
|
# import pdb;pdb.set_trace() |
|
|
|
if retval['ranee']: |
|
|
|
if retval['ranee']: |
|
|
|
retval['ranee'] = retval['ranee'][::-1][:4] |
|
|
|
retval['ranee'] = retval['ranee'][::-1][:4] |
|
|
|
|
|
|
|
|
|
|
|
@ -223,7 +228,7 @@ class CartAddView(RedirectView): |
|
|
|
cart = Cart(self.request) |
|
|
|
cart = Cart(self.request) |
|
|
|
try: |
|
|
|
try: |
|
|
|
item_variant = ProductVariation.objects.get( |
|
|
|
item_variant = ProductVariation.objects.get( |
|
|
|
pk=self.request.GET.get('pk')) |
|
|
|
pk=self.request.GET.get('pk')) |
|
|
|
except ProductVariation.DoesNotExist: |
|
|
|
except ProductVariation.DoesNotExist: |
|
|
|
return redirect('/') |
|
|
|
return redirect('/') |
|
|
|
except: |
|
|
|
except: |
|
|
|
@ -290,10 +295,10 @@ class CartDetailView(TemplateView): |
|
|
|
order.city = request.POST['city'] |
|
|
|
order.city = request.POST['city'] |
|
|
|
order.deliv_type = request.POST['deliv_type'] |
|
|
|
order.deliv_type = request.POST['deliv_type'] |
|
|
|
order_amount = dict(a.get_amount( |
|
|
|
order_amount = dict(a.get_amount( |
|
|
|
order.city, |
|
|
|
order.city, |
|
|
|
len(cart.items), |
|
|
|
len(cart.items), |
|
|
|
cart.weight, |
|
|
|
cart.weight, |
|
|
|
order.deliv_type, |
|
|
|
order.deliv_type, |
|
|
|
)) |
|
|
|
)) |
|
|
|
order.amount = order_amount['AmountPlusFSAmount'] + cart.total |
|
|
|
order.amount = order_amount['AmountPlusFSAmount'] + cart.total |
|
|
|
order.address = request.POST['alemtat_address'] |
|
|
|
order.address = request.POST['alemtat_address'] |
|
|
|
@ -311,28 +316,28 @@ class CartDetailView(TemplateView): |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
profile = Profile.objects.get(phone=normalize_phone(order.phone)) |
|
|
|
profile = Profile.objects.get(phone=normalize_phone(order.phone)) |
|
|
|
#profile.set_password(settings.PROFILE_TEMP_PASSWORD) |
|
|
|
# profile.set_password(settings.PROFILE_TEMP_PASSWORD) |
|
|
|
#profile.save() |
|
|
|
# profile.save() |
|
|
|
send_email(profile, template='mail/order.jinja') |
|
|
|
send_email(profile, template='mail/order.jinja') |
|
|
|
except: |
|
|
|
except: |
|
|
|
from random import randint |
|
|
|
from random import randint |
|
|
|
import requests |
|
|
|
import requests |
|
|
|
password = randint(10000000, 99999999) |
|
|
|
password = randint(10000000, 99999999) |
|
|
|
profile = Profile.objects.create( |
|
|
|
profile = Profile.objects.create( |
|
|
|
phone=normalize_phone(order.phone), |
|
|
|
phone=normalize_phone(order.phone), |
|
|
|
email=order.email, |
|
|
|
email=order.email, |
|
|
|
first_name=order.first_name, |
|
|
|
first_name=order.first_name, |
|
|
|
last_name=order.last_name, |
|
|
|
last_name=order.last_name, |
|
|
|
) |
|
|
|
) |
|
|
|
profile.set_password(password) |
|
|
|
profile.set_password(password) |
|
|
|
profile.save() |
|
|
|
profile.save() |
|
|
|
|
|
|
|
|
|
|
|
phone = normalize_phone(order.phone) |
|
|
|
phone = normalize_phone(order.phone) |
|
|
|
params = dict( |
|
|
|
params = dict( |
|
|
|
login='Jango.kz', |
|
|
|
login='Jango.kz', |
|
|
|
psw='AcEMXtLGz042Fc1ZJUSl', |
|
|
|
psw='AcEMXtLGz042Fc1ZJUSl', |
|
|
|
phones='7{}'.format(phone), |
|
|
|
phones='7{}'.format(phone), |
|
|
|
mes='Batiskaf.kz - Vash parol: {}'.format(password) |
|
|
|
mes='Batiskaf.kz - Vash parol: {}'.format(password) |
|
|
|
) |
|
|
|
) |
|
|
|
requests.get('http://smsc.ru/sys/send.php', params=params) |
|
|
|
requests.get('http://smsc.ru/sys/send.php', params=params) |
|
|
|
|
|
|
|
|
|
|
|
@ -363,10 +368,10 @@ def get_order_amount(request): |
|
|
|
a = AlemTat() |
|
|
|
a = AlemTat() |
|
|
|
cart = Cart(request) |
|
|
|
cart = Cart(request) |
|
|
|
retval = dict(a.get_amount( |
|
|
|
retval = dict(a.get_amount( |
|
|
|
request.GET['city'], |
|
|
|
request.GET['city'], |
|
|
|
len(cart.items), |
|
|
|
len(cart.items), |
|
|
|
cart.weight, |
|
|
|
cart.weight, |
|
|
|
request.GET['deliv'], |
|
|
|
request.GET['deliv'], |
|
|
|
)) |
|
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
_retval = {k: _currency.get_price(v) for k, v in retval.items() if k != 'FS'} |
|
|
|
_retval = {k: _currency.get_price(v) for k, v in retval.items() if k != 'FS'} |
|
|
|
@ -375,12 +380,11 @@ def get_order_amount(request): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_kazpost_tarif(weight, to): |
|
|
|
def get_kazpost_tarif(weight, to): |
|
|
|
|
|
|
|
|
|
|
|
import requests |
|
|
|
import requests |
|
|
|
import re |
|
|
|
import re |
|
|
|
|
|
|
|
|
|
|
|
url="http://rates.kazpost.kz/postratesprod/postratesws.wsdl" |
|
|
|
url = "http://rates.kazpost.kz/postratesprod/postratesws.wsdl" |
|
|
|
#headers = {'content-type': 'application/soap+xml'} |
|
|
|
# headers = {'content-type': 'application/soap+xml'} |
|
|
|
headers = {'content-type': 'text/xml'} |
|
|
|
headers = {'content-type': 'text/xml'} |
|
|
|
body = """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pos="http://webservices.kazpost.kz/postratesws"> |
|
|
|
body = """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pos="http://webservices.kazpost.kz/postratesws"> |
|
|
|
<soapenv:Header/> |
|
|
|
<soapenv:Header/> |
|
|
|
@ -403,7 +407,7 @@ def get_kazpost_tarif(weight, to): |
|
|
|
</soapenv:Body> |
|
|
|
</soapenv:Body> |
|
|
|
</soapenv:Envelope>""" |
|
|
|
</soapenv:Envelope>""" |
|
|
|
|
|
|
|
|
|
|
|
body = body.format(weight*1000, to) |
|
|
|
body = body.format(weight * 1000, to) |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
response = requests.post(url, data=body, headers=headers) |
|
|
|
response = requests.post(url, data=body, headers=headers) |
|
|
|
@ -441,7 +445,7 @@ def order_kkb(request, order): |
|
|
|
c_appendix = dict(items=cart.items, deliv_price=order.amount - cart.total) |
|
|
|
c_appendix = dict(items=cart.items, deliv_price=order.amount - cart.total) |
|
|
|
render_appendix = render_to_string('kkb/appendix.xml', c_appendix) |
|
|
|
render_appendix = render_to_string('kkb/appendix.xml', c_appendix) |
|
|
|
appendix = base64.b64encode( |
|
|
|
appendix = base64.b64encode( |
|
|
|
bytes(render_appendix, 'utf-8') |
|
|
|
bytes(render_appendix, 'utf-8') |
|
|
|
).decode('utf-8') |
|
|
|
).decode('utf-8') |
|
|
|
|
|
|
|
|
|
|
|
c = dict(order=order, context=context, appendix=appendix) |
|
|
|
c = dict(order=order, context=context, appendix=appendix) |
|
|
|
@ -464,6 +468,58 @@ def kkb_result(request): |
|
|
|
return render(request, 'kkb_ok.jinja') |
|
|
|
return render(request, 'kkb_ok.jinja') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_dpd_cities(request, *args, **kwargs): |
|
|
|
|
|
|
|
import requests |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
url = "http://ws.dpd.ru/services/geography2?wsdl" |
|
|
|
|
|
|
|
headers = {'content-type': 'text/xml'} |
|
|
|
|
|
|
|
body = """<soapenv:Envelope |
|
|
|
|
|
|
|
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" |
|
|
|
|
|
|
|
xmlns:ns="http://dpd.ru/ws/geography/2015-05-20"> |
|
|
|
|
|
|
|
<soapenv:Header/> |
|
|
|
|
|
|
|
<soapenv:Body> |
|
|
|
|
|
|
|
<ns:getCitiesCashPay> |
|
|
|
|
|
|
|
<request> |
|
|
|
|
|
|
|
<auth> |
|
|
|
|
|
|
|
<clientNumber>{clientID}</clientNumber> |
|
|
|
|
|
|
|
<clientKey>{clientKey}</clientKey> |
|
|
|
|
|
|
|
</auth> |
|
|
|
|
|
|
|
<countryCode>KZ</countryCode> |
|
|
|
|
|
|
|
</request> |
|
|
|
|
|
|
|
</ns:getCitiesCashPay> |
|
|
|
|
|
|
|
</soapenv:Body> |
|
|
|
|
|
|
|
</soapenv:Envelope> |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
places = list() |
|
|
|
|
|
|
|
search = request.GET.get('search', '') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body = body.format(clientID=settings.DPD_ID, clientKey=settings.DPD_KEY) |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
response = requests.post(url, data=body, headers=headers) |
|
|
|
|
|
|
|
elements = ET.fromstring(response.content).findall(".//return") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if search: |
|
|
|
|
|
|
|
for el in elements: |
|
|
|
|
|
|
|
if search.lower() in el.find('.//cityName').text.lower(): |
|
|
|
|
|
|
|
add_items(el, places) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
for el in elements: |
|
|
|
|
|
|
|
add_items(el, places) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = json.dumps(places) |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
data = json.dumps({'msg': 'false'}) |
|
|
|
|
|
|
|
return HttpResponse(data, content_type='json') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_items(el, places): |
|
|
|
|
|
|
|
places.append({'id': el.find('.//cityId').text, |
|
|
|
|
|
|
|
'text': '{0} {1}'.format( |
|
|
|
|
|
|
|
el.find('.//abbreviation').text, |
|
|
|
|
|
|
|
el.find('.//cityName').text |
|
|
|
|
|
|
|
)}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductSitemap(Sitemap): |
|
|
|
class ProductSitemap(Sitemap): |
|
|
|
changefreq = "daily" |
|
|
|
changefreq = "daily" |
|
|
|
priority = 0.8 |
|
|
|
priority = 0.8 |
|
|
|
|