Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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':'开店成功'})
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
 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()
Exemplo n.º 6
0
 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
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
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': '이미 등록된 병원입니다'
    })
Exemplo n.º 10
0
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
Exemplo n.º 11
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
Exemplo n.º 12
0
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})
Exemplo n.º 13
0
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})