示例#1
0
    def hydrate(self, bundle):
        """
        Prepare the fabric to be saved to the database
        """
        bundle.obj.description = "Pattern:{0}, Col: {1}".format(
            bundle.data['pattern'], bundle.data['color'])
        bundle.obj.type = "Fabric"
        bundle.obj.units = 'm'

        if "cost" in bundle.data:
            if float(bundle.data['cost']) > 0:
                try:
                    try:
                        p = Product.objects.get(
                            supply=bundle.obj,
                            supplier=Supplier.objects.get(
                                pk=bundle.data['supplier']['id']))
                    except Product.DoesNotExist:
                        p = Product()
                        p.supply = bundle.obj
                        p.supplier = Supplier.objects.get(
                            pk=bundle.data['supplier']['id'])
                        p.cost = bundle.data['cost']
                    p.save()
                except KeyError:
                    pass

        return bundle
示例#2
0
 def hydrate(self, bundle):
     """
     Prepare the fabric to be saved to the database
     """
     bundle.obj.description = "Pattern:{0}, Col: {1}".format(bundle.data['pattern'], bundle.data['color'])
     bundle.obj.type = "Fabric"
     bundle.obj.units = 'm'
     
     if "cost" in bundle.data:
         if float(bundle.data['cost']) > 0:
             try:
                 try: 
                     p = Product.objects.get(supply=bundle.obj,
                                             supplier=Supplier.objects.get(pk=bundle.data['supplier']['id']))
                 except Product.DoesNotExist:
                     p = Product()
                     p.supply = bundle.obj
                     p.supplier = Supplier.objects.get(pk=bundle.data['supplier']['id'])
                     p.cost = bundle.data['cost']
                 p.save()
             except KeyError:
                 pass
     
     return bundle
示例#3
0
        fabric.save()
        
        filename = "{0} Col: {1}".format(fabric.pattern, fabric.color)
        fabric.description = filename
        fabric.save()
        
        print fabric.id, fabric.description
        
        try:
            product = Product.objects.get(supply=fabric, supplier=supplier)
        except Product.DoesNotExist:
            product = Product(supply=fabric, supplier=supplier)
            
        product.purchasing_units = 'yd'
        try:
            product.cost = Decimal(fabric.grade) * Decimal('1.10')
        except Exception:
            product.cost = 0
            
        product.save()
        
        if 'image' in f:
            f['image'].save(filename + ".jpg")
            image = S3Object.create(filename + ".jpg", 
                                    "supply/image/{0}-{1}.jpg".format(fabric.pattern, fabric.color),
                                    'media.dellarobbiathailand.com')
            fabric.image = image
            
        fabric.save()
        
 
示例#4
0
        fabric.save()

        filename = "{0} Col: {1}".format(fabric.pattern, fabric.color)
        fabric.description = filename
        fabric.save()

        print fabric.id, fabric.description

        try:
            product = Product.objects.get(supply=fabric, supplier=supplier)
        except Product.DoesNotExist:
            product = Product(supply=fabric, supplier=supplier)

        product.purchasing_units = 'yd'
        try:
            product.cost = Decimal(fabric.grade) * Decimal('1.10')
        except Exception:
            product.cost = 0

        product.save()

        if 'image' in f:
            f['image'].save(filename + ".jpg")
            image = S3Object.create(
                filename + ".jpg",
                "supply/image/{0}-{1}.jpg".format(fabric.pattern,
                                                  fabric.color),
                'media.dellarobbiathailand.com')
            fabric.image = image

        fabric.save()
示例#5
0
def work():
    data = []
    review = []
    supplier = Supplier.objects.get(name__icontains="blue international")
    with open("/Users/Charlie/Sites/employee/backend/blue-inter.csv",
              'r') as f:
        reader = csv.reader(f)
        for row in reader:
            data.append({
                'reference': row[0],
                'description': row[1],
                'cost': row[2],
                'units': row[3]
            })

    for index, d in enumerate(data):
        for key in d.keys():
            try:
                d[key] = d[key].encode('utf-8')
            except UnicodeDecodeError as e:
                pass

            if key == "cost":
                try:
                    d[key] = Decimal(d[key].replace(',', ''))
                except InvalidOperation as e:
                    review.append(data.pop(index))

            if key == "units":
                if not d[key]:
                    review.append(data.pop(index))

    for index, d in enumerate(data):
        try:
            try:
                supply = Supply.objects.get(description=d['description'])
            except Supply.DoesNotExist:
                supply = Supply()

            supply.description = d['description']
            supply.units = d['units']
            supply.full_clean()
            supply.save()

            try:
                product = Product.objects.get(supply=supply)
            except Product.DoesNotExist:
                product = Product(supply=supply, supplier=supplier)

            product.supplier = supplier
            product.supply = supply
            product.reference = d['reference']
            product.cost = d['cost']
            product.purchasing_units = d['units']
            product.full_clean()
            product.save()

        except ValidationError as e:
            print e
            review.append(data.pop(index))

        assert Supply.objects.filter(description=d['description']).count() == 1

    with open('blue-inter-review.csv', 'w') as f:
        fieldnames = ['reference', 'description', 'cost', 'units']
        writer = csv.DictWriter(f)
        writer.write_header()
        for d in review:
            writer.writerow(d)

    assert supplier.supplies.all().count() == len(data)
示例#6
0
def work():
    data = []
    review = []
    supplier = Supplier.objects.get(name__icontains="blue international")
    with open("/Users/Charlie/Sites/employee/backend/blue-inter.csv", 'r') as f:
        reader = csv.reader(f)
        for row in reader:
            data.append({'reference': row[0],
                         'description': row[1],
                         'cost': row[2],
                         'units': row[3]})
                             
    for index, d in enumerate(data):
        for key in d.keys():
                try:
                    d[key] = d[key].encode('utf-8')
                except UnicodeDecodeError as e:
                    pass
                    
                if key == "cost":
                    try:
                        d[key] = Decimal(d[key].replace(',', ''))
                    except InvalidOperation as e:
                        review.append(data.pop(index))
                        
                if key == "units":
                    if not d[key]:
                        review.append(data.pop(index))

    for index, d in enumerate(data):
        try:
            try:
                supply = Supply.objects.get(description=d['description'])
            except Supply.DoesNotExist:
                supply = Supply()
        
            supply.description = d['description']
            supply.units = d['units']
            supply.full_clean()
            supply.save()
        
        
            try:
                product = Product.objects.get(supply=supply)
            except Product.DoesNotExist:
                product = Product(supply=supply, supplier=supplier)
            
            product.supplier = supplier
            product.supply = supply
            product.reference = d['reference']
            product.cost = d['cost']
            product.purchasing_units = d['units']
            product.full_clean()
            product.save()
            
        except ValidationError as e:
            print e
            review.append(data.pop(index))
            
        assert Supply.objects.filter(description=d['description']).count() == 1
        
    with open('blue-inter-review.csv', 'w') as f:
        fieldnames = ['reference', 'description', 'cost', 'units']
        writer = csv.DictWriter(f)
        writer.write_header()
        for d in review:
            writer.writerow(d)
        
    assert supplier.supplies.all().count() == len(data)