Beispiel #1
0
class ProviderDetail(generics.RetrieveUpdateDestroyAPIView):
    """
    Retrieve, update or delete a specific provider instance.
    """
    queryset = Provider.objects()
    serializer_class = ProviderSerializer

    def get(self, request, *args, **kwargs):
        return self.retrieve(request, *args, **kwargs)

    def put(self, request, *args, **kwargs):
        return self.update(request, *args, **kwargs)

    def delete(self, request, *args, **kwargs):
        return self.destroy(request, *args, **kwargs)
Beispiel #2
0
def create_provider(firstname, lastname, job_title, affiliation):
    firstclean = firstname.replace("'","")
    lastclean = lastname.replace("'","")
    prov = Provider()
    prov.job_title = job_title
    prov.affiliation = affiliation    
    prov.user = create_user(username=firstclean.lower() + "_" + lastclean.lower(), password='******', firstname=firstname, lastname = lastname)
    prov.save()
    transaction.commit()
    return prov
Beispiel #3
0
    def handle(self, *args, **kwargs):
        #start_time = time.time()

        with open('outoutfile.json') as json_file:
            data = json.load(json_file)
            #print(data)
            i = 0
            for product in data:
                print(i)
                #print(product)
                title = product['title']
                description = product['description']
                category = product['category']
                try:
                    categoryObj = Category.objects.get(title=category)
                except:
                    categoryObj = Category(title=category, catalog_rep='A')
                    categoryObj.save()
                #dbProduct = Product(name= title,content=(description or ''), category=categoryObj)
                dbProductList = Product.objects.filter(name=title,
                                                       category=categoryObj)
                dbProduct = dbProductList.first()
                if dbProduct == None:
                    dbProduct = Product(category=categoryObj,
                                        name=title,
                                        content=(description or ''),
                                        buy_cost=0)
                    print('creating new product ', dbProduct.name,
                          'description: ', dbProduct.content)
                else:
                    dbProduct.content = description or ''
                    print('updating product ', dbProduct.name, 'description: ',
                          dbProduct.content)

                #print(dbProduct.name)
                #print(dbProduct.content)
                #print(dbProduct.category)
                dbProduct.save()

                if 'image1' in product:
                    dbImage1 = ProductImage(product=dbProduct)
                    with open(product['image1'], 'rb') as f:
                        image_data = File(f)
                        dbImage1.image.save(product['image1'], image_data,
                                            True)
                    dbImage1.save()

                if 'image2' in product:
                    dbImage1 = ProductImage(product=dbProduct)
                    with open(product['image2'], 'rb') as f:
                        image_data = File(f)
                        dbImage1.image.save(product['image2'], image_data,
                                            True)
                    dbImage1.save()

                colors = []
                if 'צבע' in product:
                    colors = product['צבע']
                else:
                    colors = ['no color']

                sizes = []
                if 'גודל' in product:
                    sizes = product['גודל']
                else:
                    sizes = ['one size']
                import itertools
                productStuckList = list(itertools.product(colors, sizes))
                #print(productStuckList)

                from provider.models import Provider

                try:
                    defultProvider = Provider.objects.all()[0]
                except:
                    defultProvider = Provider(name='defult provider')
                    defultProvider.save()

                from packingType.models import PackingType
                try:
                    defultPackingType = PackingType.objects.all()[0]
                except:
                    defultPackingType = PackingType(name='defult packing')
                    defultPackingType.save()

                for stock in productStuckList:
                    from stock.models import Stock

                    from productSize.models import ProductSize
                    dbProductSize = None
                    try:
                        dbProductSize = ProductSize.objects.get(size=stock[1])
                    except:
                        dbProductSize = ProductSize(size=stock[1])
                        dbProductSize.save()

                    from productColor.models import ProductColor
                    dbProductColor = None
                    try:
                        dbProductColor = ProductColor.objects.get(
                            name=stock[0])
                    except:
                        dbProductColor = ProductColor(name=stock[0])
                        dbProductColor.save()

                    stock, created = Stock.objects.update_or_create(
                        provider=defultProvider,
                        productSize=dbProductSize,
                        productColor=dbProductColor,
                        product=dbProduct,
                        packingType=defultPackingType)
                    print(created, stock.product, stock.productSize,
                          stock.productColor)
                    stock.save()

                i += 1

        #end_time = time.time()
        #print('imported in ' + (end_time - start_time) + ' seconds' )

        pass
Beispiel #4
0
    def setUp(self):

       u = get_user_model()()
       u.id = 1
       u.username = '******'
       u.first_name = 'test'
       u.last_name = 'test'
       u.email = '*****@*****.**'
       u.set_password('test') 
       u.save()

       p = Provider()
       p.id = 1
       p.user = u
       p.name = "test"  
       p.email = "*****@*****.**" 
       p.phone = 12312312
       p.currency = "USD"
       p.language = "DE"
       p.save()

       u = get_user_model()()
       u.id = 2
       u.username = '******'
       u.first_name = 'test2'
       u.last_name = 'test2'
       u.email = '*****@*****.**'
       u.set_password('test') 
       u.save()

       p = Provider()
       p.id = 2
       p.user = u
       p.name = "test2"  
       p.email = "*****@*****.**" 
       p.phone = 123123212
       p.currency = "USD"
       p.language = "EN"
       p.save()

       self.url = reverse("area:area-list")
Beispiel #5
0
    def setUp(self):

       u = get_user_model()()
       u.id = 1
       u.username = '******'
       u.first_name = 'test'
       u.last_name = 'test'
       u.email = 'test'
       u.set_password('test') 
       u.save()

       p = Provider()
       p.id = 1
       p.user = u
       p.name = "test"  
       p.email = "*****@*****.**" 
       p.phone = 12312312
       p.currency = "USD"
       p.language = "DE"
       p.save()

       a = Area()
       a.id = 1
       a.name = "test"
       a.price = 10.20
       a.provider = p
       a.poly = '{ "type": "Polygon", "coordinates": [ [ [0, 0], [10, 50], [10, 0], [0, 0] ] ] }'
       a.save()

       u = get_user_model()()
       u.id = 2
       u.username = '******'
       u.first_name = 'test2'
       u.last_name = 'test2'
       u.email = '*****@*****.**'
       u.set_password('test') 
       u.save()

       p = Provider()
       p.id = 2
       p.user = u
       p.name = "test2"  
       p.email = "*****@*****.**" 
       p.phone = 123123212
       p.currency = "USD"
       p.language = "EN"
       p.save()

       a = Area()
       a.id = 2
       a.name = "test2"
       a.price = 10.20
       a.provider = p
       a.poly = '{ "type": "Polygon", "coordinates": [ [ [0, 0], [10, 50], [10, 0], [0, 0] ] ] }'
       a.save()

       self.url = reverse("area:area-detail",kwargs={"pk":1})