|
|
|
|
@ -1,4 +1,6 @@ |
|
|
|
|
import base64 |
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
from django.contrib.auth import authenticate, login |
|
|
|
|
from django.core.mail import mail_managers, mail_admins |
|
|
|
|
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage |
|
|
|
|
@ -19,6 +21,8 @@ from django.http import JsonResponse |
|
|
|
|
from datetime import datetime |
|
|
|
|
from django.conf import settings |
|
|
|
|
from django.contrib.sitemaps import Sitemap |
|
|
|
|
import xml.etree.ElementTree as ET |
|
|
|
|
from django.http import HttpResponse |
|
|
|
|
import kkb |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -105,14 +109,14 @@ class CategoryView(CategoryBaseView, TemplateView): |
|
|
|
|
|
|
|
|
|
if self.is_search: |
|
|
|
|
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') |
|
|
|
|
brands_pks = [item.brand.pk for item in self.products_qs] |
|
|
|
|
retval['brands'] = Brand.objects.filter(pk__in=brands_pks).order_by( |
|
|
|
|
'title') # list(set(map(lambda item: item.brand, self.products_qs))) |
|
|
|
|
|
|
|
|
|
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') |
|
|
|
|
brands_pks = [item.brand.pk for item in self.products_qs] |
|
|
|
|
retval['brands'] = Brand.objects.filter(pk__in=brands_pks).order_by('title') |
|
|
|
|
@ -169,7 +173,7 @@ class ProductView(CategoryBaseView, DetailView): |
|
|
|
|
self.category = self._get_full_category(kwargs['categories']) |
|
|
|
|
retval = super(ProductView, self).get(request, args, kwargs) |
|
|
|
|
ranee = request.session.get('ranee', []) |
|
|
|
|
#import pdb;pdb.set_trace() |
|
|
|
|
# import pdb;pdb.set_trace() |
|
|
|
|
if kwargs['slug'] not in ranee: |
|
|
|
|
ranee.append(kwargs['slug']) |
|
|
|
|
request.session['ranee'] = ranee |
|
|
|
|
@ -182,18 +186,19 @@ class ProductView(CategoryBaseView, DetailView): |
|
|
|
|
retval['form'] = ProductFeedbackForm(self.request.POST or None) |
|
|
|
|
retval['updated'] = ProductsUpdate.objects.last() |
|
|
|
|
ranee = self.request.session.get('ranee', []) |
|
|
|
|
#import pdb;pdb.set_trace() |
|
|
|
|
#ranee.pop(kwargs['object'].slug) |
|
|
|
|
# import pdb;pdb.set_trace() |
|
|
|
|
# ranee.pop(kwargs['object'].slug) |
|
|
|
|
retval['ranee'] = [] |
|
|
|
|
for i in ranee: |
|
|
|
|
#import pdb; pdb.set_trace() |
|
|
|
|
# import pdb; pdb.set_trace() |
|
|
|
|
if kwargs and i != kwargs['object'].slug: |
|
|
|
|
try: |
|
|
|
|
p = Product.objects.get(slug=i) |
|
|
|
|
if p not in retval['ranee']: |
|
|
|
|
retval['ranee'].append(p) |
|
|
|
|
except: pass |
|
|
|
|
#import pdb;pdb.set_trace() |
|
|
|
|
except: |
|
|
|
|
pass |
|
|
|
|
# import pdb;pdb.set_trace() |
|
|
|
|
if retval['ranee']: |
|
|
|
|
retval['ranee'] = retval['ranee'][::-1][:4] |
|
|
|
|
|
|
|
|
|
@ -311,8 +316,8 @@ class CartDetailView(TemplateView): |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
profile = Profile.objects.get(phone=normalize_phone(order.phone)) |
|
|
|
|
#profile.set_password(settings.PROFILE_TEMP_PASSWORD) |
|
|
|
|
#profile.save() |
|
|
|
|
# profile.set_password(settings.PROFILE_TEMP_PASSWORD) |
|
|
|
|
# profile.save() |
|
|
|
|
send_email(profile, template='mail/order.jinja') |
|
|
|
|
except: |
|
|
|
|
from random import randint |
|
|
|
|
@ -375,12 +380,11 @@ def get_order_amount(request): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_kazpost_tarif(weight, to): |
|
|
|
|
|
|
|
|
|
import requests |
|
|
|
|
import re |
|
|
|
|
|
|
|
|
|
url="http://rates.kazpost.kz/postratesprod/postratesws.wsdl" |
|
|
|
|
#headers = {'content-type': 'application/soap+xml'} |
|
|
|
|
url = "http://rates.kazpost.kz/postratesprod/postratesws.wsdl" |
|
|
|
|
# headers = {'content-type': 'application/soap+xml'} |
|
|
|
|
headers = {'content-type': 'text/xml'} |
|
|
|
|
body = """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pos="http://webservices.kazpost.kz/postratesws"> |
|
|
|
|
<soapenv:Header/> |
|
|
|
|
@ -403,7 +407,7 @@ def get_kazpost_tarif(weight, to): |
|
|
|
|
</soapenv:Body> |
|
|
|
|
</soapenv:Envelope>""" |
|
|
|
|
|
|
|
|
|
body = body.format(weight*1000, to) |
|
|
|
|
body = body.format(weight * 1000, to) |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
response = requests.post(url, data=body, headers=headers) |
|
|
|
|
@ -464,6 +468,58 @@ def kkb_result(request): |
|
|
|
|
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): |
|
|
|
|
changefreq = "daily" |
|
|
|
|
priority = 0.8 |
|
|
|
|
|