def index(request): base_sql = ''' {select} FROM `merchandise` JOIN `store` JOIN `address` JOIN `book` JOIN `book_category_detail` JOIN `book_category` JOIN `merchandise_image` JOIN `image` JOIN `merchandise_portfolio` JOIN `merchandise_condition` ON `merchandise`.`id_user` = `store`.`id_user` AND `merchandise`.`id_address` = `address`.`id` AND `merchandise`.`id` = `book`.`id` AND `book`.`id` = `book_category_detail`.`id_book` AND `book_category_detail`.`id_category` = `book_category`.`id` AND `merchandise_image`.`id_merchandise` = `merchandise`.`id` AND `merchandise_image`.`id_image` = `image`.`id` AND `merchandise`.`id_portfolio` = `merchandise_portfolio`.`id` AND `merchandise`.`id_condition` = `merchandise_condition`.`id` {where} {group} {order}; ''' products_select_clause = ''' SELECT `merchandise`.*, `image`.`url`, `book`.`name`, `book`.`publisher`, `book`.`publication_date`, `book`.`width`, `book`.`height`, `book`.`length`, `book`.`pages_num`, `address`.`city`, (SELECT `tb_cat`.`name` FROM `book_category` `tb_cat` JOIN `book_category_detail` `tb_det` ON `tb_cat`.`id` = `tb_det`.`id_category` WHERE `tb_det`.`id_book` = `book`.`id` ORDER BY `tb_cat`.`id` DESC LIMIT 1) AS `category`, (`merchandise`.`total_star`/`merchandise`.`times_rated`) AS `rate_point` ''' sqlutils = SQLUtils() sqlutils.add_where(Merchandise.check_book_raw_query()) sqlutils.add_where(Merchandise.check_selling_raw_query()) sqlutils.add_where(Store.check_opening_raw_query()) sqlutils.add_order(SORT_SQL.get('hotest', None)) hotest_merchandises = Merchandise.objects.raw( base_sql.format(select=products_select_clause, where=sqlutils.get_where_clause(), group=' GROUP BY `merchandise`.`id` ', order=sqlutils.get_order_clause()), sqlutils.get_params())[:10] sqlutils = SQLUtils() sqlutils.add_where(Merchandise.check_book_raw_query()) sqlutils.add_where(Merchandise.check_selling_raw_query()) sqlutils.add_where(Store.check_opening_raw_query()) sqlutils.add_order(SORT_SQL.get('newest', None)) newest_merchandises = Merchandise.objects.raw( base_sql.format(select=products_select_clause, where=sqlutils.get_where_clause(), group=' GROUP BY `merchandise`.`id` ', order=sqlutils.get_order_clause()), sqlutils.get_params())[:10] return render( request, 'home/index.html', { 'hotest_merchandises': hotest_merchandises, 'newest_merchandises': newest_merchandises })
def post(cls): """ Creates a new store Endpoint: /store/ Example Post Body: { "name": "Electronics Store", "tagline": "A really good electronics store", "app_id": "my_electronics_app", "app_secret": "my_electronics_secret" } Example Response: { "result": "ok", "store": { "created_at": "Sat, 05 Jan 2019 21:11:30 GMT", "deleted_at": null, "links": [ { "href": "/store/241787390524523237447764623791517213747", "rel": "self" } ], "name": "Electronics Store", "store_id": "241787390524523237447764623791517213747", "tagline": "A really good electronics store", "updated_at": "Sat, 05 Jan 2019 21:11:30 GMT" } } """ store_json = request.json error = best_match(Draft4Validator(schema).iter_errors(store_json)) if error: return jsonify({"error": error.message}), 400 store = Store.objects.filter(app_id=store_json.get("app_id")).first() if store: return jsonify({"error": "APP_ID_ALREADY_EXISTS"}), 400 if store_json.get("credit_order_preference"): if store_json.get("credit_order_preference").lower() not in [ "credit", "gift-card" ]: return jsonify({"error": CREDIT_ORDER_PREFERENCE_ERROR}), 400 store = Store(name=store_json.get("name"), tagline=store_json.get("tagline"), app_id=store_json.get("app_id"), app_secret=store_json.get("app_secret")).save() if store_json.get("credit_order_preference"): store.credit_order_preference = store_json.get( "credit_order_preference") store.save() response = {"result": "ok", "store": store_obj(store)} return jsonify(response), 201
def createLocalComercial(self, addressNumber2): building = Building(real_estate=self, propertyType=Building.TYPE_LOCAL_COMERCIAL) building.save() store = Store(building=building, addressNumber2=addressNumber2) store.save() self.buildings.add(building) self.save() return store
def clean(self): super(StoreModelForm, self).clean() if len(self.cleaned_data) != 2: raise forms.ValidationError(_("Correct the form below")) try: store = Store(**self.cleaned_data) store.save() except Exception: raise forms.ValidationError(_("Correct the form below")) return self.cleaned_data
def batch_create03(): """批量创建店铺表测试数据(方法三)""" store_list = list() for i in range(1, 501): store_dict = dict( name=f'test_store_{i}', manager_name=f'test_manager_{i}', manager_id=i, center=f'test_center_{i}', center_id=i, platform=f'test_platform_{i}', market=f'test.{i}.com', market_id=i, status=1, last_download_time=datetime.now(), ) # print(f'新建数据:{store_dict}') store_list.append(Store(**store_dict)) # batch_size 表示每次批量处理的数量 # ignore_conflicts=True 表示忽略批量创建时的冲突 Store.objects.bulk_create(store_list, batch_size=100, ignore_conflicts=True) return
def ProductsListView(request, category_name): p_list = ProductVariant.objects.filter( product__category__sku=category_name, publish=True) if (p_list is None): p_list = Product.objects.filter( category__sku=category_name, publish=True) single = get_object_or_404(Category, sku=category_name) title = single.name description = clean(single.description, strip=True) description = description.encode('utf-8') description = description.decode('utf-8') if (len(p_list) <= 1): return redirect( 'product', category_name=single.sku, product_name=p_list[0].product.sku, variant_name=p_list[0].sku) previewImage = Store.get_solo().image.url previewImage = str( ProductImages.objects.filter(product__sku=p_list[0].sku).first()) template_name = "products__list.html" context = { 'p_list': p_list, 'single': single, 'title': title, 'description': description, 'previewImage': previewImage } return render(request, template_name, context)
def test_book_hsh_its_unique(self): book = Store.objects.create(name='Book', pages=1) other_book = Store() other_book.name = 'Other Book' other_book.hsh = book.hsh other_book.pages = 1 with self.assertRaises(IntegrityError): other_book.save()
def store_add(request): if request.method == 'GET': return render(request,'store/store_add.html',{}) elif request.method == 'POST': store_num = Store.objects.filter(myuser=request.user,status__in=[0, 1]) storename = request.POST['storename'].strip() storeintro = request.POST['storeintro'].strip() cover = request.FILES.get('cover') if len(store_num) >= 2: return render(request, 'store/store_add.html', {'error_code': '0', 'error_msg': '每个账户最多有两家店铺'}) if len(storename) >= 12: return render(request, 'store/store_add.html', {'error_code': '-1', 'error_msg': '店铺名称不能超过12个字符'}) if len(storename) >= 20: return render(request, 'store/store_add.html', {'error_code': '-2', 'error_msg': '店铺简介不能超过40个字符'}) myuser = request.user if cover == None: store = Store(name =storename,intro=storeintro,myuser=myuser) else: store = Store(name=storename, intro=storeintro, myuser=myuser,cover=cover) store.save() return redirect(reverse('store:store_list'),{'error_code':1,'error_msg':'开店成功'})
def pop_data(request): store = Store() store.name = 'FPK' store.cum_rating = 4.6 store.save() ctr = 1 l = len(title) print(l) for i in range(l): book = Book() book.name = title[i] book.author = author[i] book.rating = rating[i] book.sale = reviews[i] book.store = store book.image = image_url[i] book.price = price[i] book.url = url[i] book.description = description[i] book.save() print(ctr) ctr = ctr + 1 return 0
def create_or_get_store(request): password, store_name, username = request.POST["password"], request.POST["store_name"], request.POST["user_name"] try: user_obj = User.objects.create_user(username=username, password=password, is_staff=1) except IntegrityError: print "User already registered" user_obj = User.objects.filter(username=username)[0] print user_obj.id perms = ( "Can add store", "Can change store", "Can delete store", "Can add products", "Can change products", "Can delete products", ) for perm in perms: permission_obj = Permission.objects.get(name=perm) user_obj.user_permissions.add(permission_obj) user_obj = authenticate(username=username, password=password) print "authenticated user" + str(user_obj) login(request, user_obj) if not check_store_created(store_name, user_obj.id): from store.models import Store bucket_id = str(uuid.uuid4()) store_obj = Store( user=user_obj, name=store_name, bucket_id=bucket_id, created_date=datetime.datetime.now(), description="Your Description here", ) store_obj.save() create_oss_bucket(bucket_id) else: store_obj = Store.objects.get(name=store_name, user_id=user_id) return store_obj.id
def post(self): store_json = request.json error = best_match(Draft4Validator(schema).iter_errors(store_json)) if error: return jsonify({"error": error.message}), 400 else: store = Store(external_id=str(uuid.uuid4()), neighborhood=store_json.get('neighborhood'), street_address=store_json.get('street_address'), city=store_json.get('city'), state=store_json.get('state'), zip=store_json.get('zip'), phone=store_json.get('phone')).save() response = {"result": "ok", "store": store_obj(store)} return jsonify(response), 201
def HomeView(request): p_list = "" single = "" title = "vov" description = "Somos productores de accesorios únicos para hombres y mujeres que buscan utilidad y buen diseño, lo necesario para acompañar su rutina diaria." previewImage = Store.get_solo().image.url template_name = "home.html" context = { 'p_list': p_list, 'single': single, 'title': title, 'description': description, 'previewImage': previewImage } return render(request, template_name, context)
def ColaboracionesSingleView(request, category_name, product_name): single = get_object_or_404(Product, sku=product_name) p_list = ProductVariant.objects.filter( product__sku=product_name, publish=True) title = single.name description = strip_tags(single.description) previewImage = Store.get_solo().image.url template_name = "colabs__single.html" context = { 'p_list': p_list, 'single': single, 'title': title, 'description': description, 'previewImage': previewImage } return render(request, template_name, context)
def ColaboracionesView(request): p_list = Product.objects.filter( category__sku='colaboraciones', publish=True) single = get_object_or_404(Category, sku='colaboraciones') title = single.name description = strip_tags(single.description) previewImage = Store.get_solo().image.url template_name = "colabs__list.html" context = { 'p_list': p_list, 'single': single, 'title': title, 'description': description, 'previewImage': previewImage } return render(request, template_name, context)
def CategoryListView(request): p_list = Category.objects.order_by('order').filter(publish=True) single = "" footer = ProductImages.objects.order_by('?').first() title = "Catalog" description = "Somos productores de accesorios únicos para hombres y mujeres que buscan utilidad y buen diseño, lo necesario para acompañar su rutina diaria." previewImage = Store.get_solo().image.url template_name = "category__list.html" context = { 'p_list': p_list, 'single': single, 'title': title, 'description': description, 'previewImage': previewImage } return render(request, template_name, context)
def PressSingleView(request, press_name): p_list = get_object_or_404(Press, slug=press_name) p_list = p_list.gallery videos = get_object_or_404(Press, slug=press_name) videos = videos.videos single = get_object_or_404(Press, slug=press_name) footer = ProductImages.objects.order_by('?').first() title = "vov - prensa" description = "Somos productores de accesorios únicos para hombres y mujeres que buscan utilidad y buen diseño, lo necesario para acompañar su rutina diaria." previewImage = Store.get_solo().image.url template_name = "press__single.html" context = { 'p_list': p_list, 'single': single, 'title': title, 'description': description, 'previewImage': previewImage, 'videos': videos } return render(request, template_name, context)
def storeSignup(request, a_id): ac = Account.objects.get(id=a_id) s_name = request.POST['name'] s_latitude = request.POST['lat'] s_longitude = request.POST['lng'] s_address = request.POST['addr'] s_type = request.POST['type'] try: s = Store.objects.get(s_name=s_name, s_latitude=s_latitude, s_type=s_type, s_longitude=s_longitude) except ObjectDoesNotExist: new_s = Store(s_name=s_name, s_latitude=s_latitude, s_longitude=s_longitude, s_address=s_address, s_type=s_type) new_s.save() ac.a_store = new_s new_s.s_account = ac new_s.save() ac.save() return HttpResponseRedirect( reverse('store:storemain', args=(new_s.id, ))) if s.s_account is None: s.s_account = ac ac.a_store = s s.save() ac.save() return HttpResponseRedirect(reverse('store:storemain', args=(s.id, ))) return render(request, 'storeSearch.html', { 'a': ac, 'error': '이미 등록된 병원입니다' })
def get_merchandise_sqlutils(self): sqlutils = SQLUtils() if self.kwargs.get('is_book'): sqlutils.add_where(Merchandise.check_book_raw_query()) if self.kwargs.get('merchandise_status'): sqlutils.add_where( Merchandise.STATUS_RAW_QUERY.get( self.kwargs.get('merchandise_status'))) if self.kwargs.get('is_opening_store'): sqlutils.add_where(Store.check_opening_raw_query()) ### Handle url queries if self.kwargs.get('owner'): sqlutils.add_where('`merchandise`.`id_user` = %s', self.kwargs.get('owner')) if self.kwargs.get('category'): sqlutils.add_where('`book_category`.`url_name` = %s', self.kwargs.get('category')) if self.kwargs.get('author'): sqlutils.add_where('`book`.`author` = %s', self.kwargs.get('author')) if self.kwargs.get('location'): sqlutils.add_where('`address`.`city` = %s', self.kwargs.get('location')) if self.kwargs.get('condition'): sqlutils.add_where('`merchandise_condition`.`code` = %s', self.kwargs.get('condition')) if self.kwargs.get('low_price'): sqlutils.add_where('`merchandise`.`price` >= %s', self.kwargs.get('low_price')) if self.kwargs.get('high_price'): sqlutils.add_where('`merchandise`.`price` <= %s', self.kwargs.get('high_price')) if self.kwargs.get('search_product'): sqlutils.add_where('`book`.`name` LIKE %s', '%' + self.kwargs.get('search_product') + '%') sqlutils.add_order( SORT_SQL.get(self.kwargs.get('sort'), SORT_SQL.get('newest'))) return sqlutils
def storeSignupDefault(request, a_id): a = Account.objects.get(id=a_id) if request.method == 'POST': s_name = request.POST['name'] s_address = request.POST['address'] s_latitude = request.POST['latitude'] s_longitude = request.POST['longitude'] s_type = request.POST['type'] new_s = Store(s_name=s_name, s_address=s_address, s_latitude=s_latitude, s_longitude=s_longitude, s_type=s_type) new_s.save() new_s.s_account = a a.a_store = new_s new_s.save() a.save() return HttpResponseRedirect( reverse('store:storemain', args=(new_s.id, ))) return render(request, 'storeSignupDefault.html', {'a': a})
if __name__ == ("__main__"): count = 1 info = [] instances = [] pharms = pharm_list() total = int(pharms['response']['body']['totalCount']) print(total) for temp in pharms['response']['body']['items']['item']: print(count) h_name = temp['yadmNm'] h_lat = temp['YPos'] h_lng = temp['XPos'] h_addr = temp['addr'] h_type = '약국' tuple = (h_name, h_lat, h_lng, h_addr, h_type) info.append(tuple) count += 1 for (h_name, h_lat, h_lng, h_addr, h_type) in info: instances.append( Store(s_name=h_name, s_latitude=h_lat, s_longitude=h_lng, s_address=h_addr, s_type=h_type)) Store.objects.bulk_create(instances) print('success')
def add_or_update_store_in_db(store_dict, region, retailer): store_name = store_dict['name'] results = retailer.stores.filter(name=store_name) if len(results) > 0: # Update existing store store = results[0] else: # Create new store store = Store() store.retailer = retailer store.region = region store.name = store_name store.display_name = store_dict["display_name"] store.latitude = None if 'latitude' not in store_dict else store_dict["latitude"] store.longitude = None if 'longitude' not in store_dict else store_dict["longitude"] store.tel = None if 'tel' not in store_dict else store_dict["tel"] store.address = None if 'address' not in store_dict else store_dict["address"] store.working_hours = None if 'working_hours' not in store_dict else store_dict["working_hours"] store.active = True store.save() lasoo_id = store_dict['lasoo_id'] props = [] prop = StoreProperty() prop.name = make_internal_property_name('lasoo_id') prop.value = lasoo_id props.append(prop) if 'lasoo_url' in store_dict: lasoo_url = store_dict['lasoo_url'] prop = StoreProperty() prop.name = make_internal_property_name('lasoo_url') prop.value = lasoo_url props.append(prop) __update_store_props_in_db(store, props) return store
def storeResult(request, p_id): p = Patient.objects.get(id=p_id) s_name = request.POST['name'] s_type = request.POST['type'] p_latitude = float(p.p_latitude) p_longitude = float(p.p_longitude) resultss = [] finalss = [] if (p_latitude == 37.5585146 and p_longitude == 127.0331892) or (s_type == '일반상점'): resultss = Store.objects.filter(s_name__contains=s_name, s_type=s_type) elif s_type == '약국': pharms = pharm_list(name=s_name, radius=100, lat=p_latitude, lng=p_longitude) if pharms['response']['body']['totalCount'] == 0: resultss = None elif pharms['response']['body']['totalCount'] == 1: temp = pharms['response']['body']['items']['item'] s_name = temp['yadmNm'] s_addr = temp['addr'] s_lat = temp['YPos'] s_lng = temp['XPos'] s_type = '약국' try: new_s = Store.objects.get(s_name=s_name, s_address=s_addr) except ObjectDoesNotExist: new_s = Store(s_name=s_name, s_address=s_addr, s_latitude=s_lat, s_longitude=s_lng, s_type=s_type) new_s.save() resultss.append(new_s) else: for temp in pharms['response']['body']['items']['item']: s_name = temp['yadmNm'] s_addr = temp['addr'] s_lat = temp['YPos'] s_lng = temp['XPos'] s_type = '약국' try: new_s = Store.objects.get(s_name=s_name, s_address=s_addr) except ObjectDoesNotExist: new_s = Store(s_name=s_name, s_address=s_addr, s_latitude=s_lat, s_longitude=s_lng, s_type=s_type) new_s.save() resultss.append(new_s) for temp_s in resultss: temp_lat = float(temp_s.s_latitude) temp_lon = float(temp_s.s_longitude) if haversine(float(p_latitude), float(p_longitude), temp_lat, temp_lon) < 1: finalss.append(temp_s) return render(request, 'storeResult.html', {'ss': finalss, 'p': p})
def get_products(request): base_sql = ''' {select} FROM `merchandise` JOIN `store` JOIN `address` JOIN `book` JOIN `book_category_detail` JOIN `book_category` JOIN `merchandise_image` JOIN `image` JOIN `merchandise_portfolio` JOIN `merchandise_condition` ON `merchandise`.`id_user` = `store`.`id_user` AND `merchandise`.`id_address` = `address`.`id` AND `merchandise`.`id` = `book`.`id` AND `book`.`id` = `book_category_detail`.`id_book` AND `book_category_detail`.`id_category` = `book_category`.`id` AND `merchandise_image`.`id_merchandise` = `merchandise`.`id` AND `merchandise_image`.`id_image` = `image`.`id` AND `merchandise`.`id_portfolio` = `merchandise_portfolio`.`id` AND `merchandise`.`id_condition` = `merchandise_condition`.`id` {where} {group} {order}; ''' sqlutils = SQLUtils() sqlutils.add_where(Merchandise.check_selling_raw_query()) sqlutils.add_where(Store.check_opening_raw_query()) sqlutils.add_order( SORT_SQL.get(request.GET.get('sort'), SORT_SQL.get('newest'))) ### Handle url queries if request.GET.get('location'): sqlutils.add_where('`address`.`city` = %s', request.GET.get('location')) if request.GET.get('condition'): sqlutils.add_where('`merchandise_condition`.`code` = %s', request.GET.get('condition')) if request.GET.get('low_price'): sqlutils.add_where('`merchandise`.`price` >= %s', request.GET.get('low_price')) if request.GET.get('high_price'): sqlutils.add_where('`merchandise`.`price` <= %s', request.GET.get('high_price')) if request.GET.get('q'): sqlutils.add_where( '( `book`.`name` LIKE %s OR `book`.`author` LIKE %s )', [ '%' + request.GET.get('q') + '%', '%' + request.GET.get('q') + '%' ]) ## Get cities cities_select_clause = 'SELECT `address`.`city` as `id`, COUNT(DISTINCT `merchandise`.`id`) AS `num_products`' cities = Merchandise.objects.raw( base_sql.format(select=cities_select_clause, where=sqlutils.get_where_clause(), group=' GROUP BY `address`.`city` ', order=' ORDER BY `num_products` DESC '), sqlutils.get_params()) ## Get conditions conditions_select_clause = 'SELECT `merchandise_condition`.*, COUNT(DISTINCT `merchandise`.`id`) AS `num_products`' conditions = Merchandise.objects.raw( base_sql.format(select=conditions_select_clause, where=sqlutils.get_where_clause(), group=' GROUP BY `merchandise_condition`.`id` ', order=' ORDER BY `num_products` DESC '), sqlutils.get_params()) ## Get books and paging products_select_clause = ''' SELECT `merchandise`.*, `image`.`url`, `book`.`name`, `book`.`publisher`, `book`.`publication_date`, `book`.`width`, `book`.`height`, `book`.`length`, `book`.`pages_num`, `address`.`city`, (SELECT `tb_cat`.`name` FROM `book_category` `tb_cat` JOIN `book_category_detail` `tb_det` ON `tb_cat`.`id` = `tb_det`.`id_category` WHERE `tb_det`.`id_book` = `book`.`id` ORDER BY `tb_cat`.`id` DESC LIMIT 1) AS `category`, (`merchandise`.`total_star`/`merchandise`.`times_rated`) AS `rate_point` ''' merchandises = Merchandise.objects.raw( base_sql.format(select=products_select_clause, where=sqlutils.get_where_clause(), group=' GROUP BY `merchandise`.`id` ', order=sqlutils.get_order_clause()), sqlutils.get_params()) print(merchandises) paginator = Paginator(merchandises, 9) page_number = request.GET.get('page') pager = paginator.get_page(page_number) page_navigator = [] for i in range(max(1, pager.number - 2), pager.number): page_navigator.append(i) page_navigator.append(pager.number) for i in range(pager.number + 1, min(pager.number + 2, pager.paginator.num_pages) + 1): page_navigator.append(i) return render( request, 'search/products.html', { 'pager': pager, 'page_navigator': page_navigator, 'cities': cities, 'conditions': conditions })
def add_or_update_store_in_db(store_dict, region, retailer): store_name = store_dict['name'] results = retailer.stores.filter(name=store_name) if len(results) > 0: # Update existing store store = results[0] else: # Create new store store = Store() store.retailer = retailer store.region = region store.name = store_name store.display_name = store_dict["display_name"] store.latitude = None if 'latitude' not in store_dict else store_dict[ "latitude"] store.longitude = None if 'longitude' not in store_dict else store_dict[ "longitude"] store.tel = None if 'tel' not in store_dict else store_dict["tel"] store.address = None if 'address' not in store_dict else store_dict[ "address"] store.working_hours = None if 'working_hours' not in store_dict else store_dict[ "working_hours"] store.active = True store.save() lasoo_id = store_dict['lasoo_id'] props = [] prop = StoreProperty() prop.name = make_internal_property_name('lasoo_id') prop.value = lasoo_id props.append(prop) if 'lasoo_url' in store_dict: lasoo_url = store_dict['lasoo_url'] prop = StoreProperty() prop.name = make_internal_property_name('lasoo_url') prop.value = lasoo_url props.append(prop) __update_store_props_in_db(store, props) return store
def parse_store_from_location(self, response, retailer, location): store_name = retailer.display_name lat, lng, address = None, None, None # no physical store, website only if ('lat' in location and len(location['lat']) > 0) \ and ('lng' in location and len(location['lng']) > 0): lat = float(location['lat']) lng = float(location['lng']) if 'physical_address_plain_text' in location: address_value = str.strip(location['physical_address_plain_text']) if len(address_value) > 0: address_value = address_value.replace( '\u00a0', ', ') if address_value is not None else None if len(address_value) > 512: self.log( 'Product {0}: Store address is too long ({1}).'.format( response.url, address)) address = address_value[:512] website, tel = None, None for contact_elem in response.xpath('//div[@class="supplier-info"]/a'): if len(contact_elem.xpath( './i[contains(@class, "fa-globe")]')) > 0: website = extract_first_value_with_xpath( contact_elem, './@href') elif len(contact_elem.xpath( './i[contains(@class, "fa-phone")]')) > 0: tel = extract_first_value_with_xpath(contact_elem, './text()') try: store = retailer.stores.get(name=store_name, latitude=lat, longitude=lng) except Store.DoesNotExist: store = Store() store.region = response.meta['region'] store.retailer = retailer store.name = store_name store.latitude = lat store.longitude = lng store.address = address store.website = website store.tel = tel store.working_hours = location['public_opening_hours'] store.save() return store