Exemple #1
0
def product_seeder(amount):

    games_names = ['DOOM', 'DIABLO', 'DOTA', 'GTA', 'Rust', 'Grad', 'Need For Speed', 'The legend of Zelda',
                   'Half-Life', 'BioShock', 'The Witcher', 'Portal', 'Tetris', 'Mario', 'Halo']

    movies_names = ['Hunters of the Forest', 'Girl in pink', 'Wolf and Bear forest friends', 'Some movie', 'King'
                    'Queen of the mexico', 'Green Land', 'Rome The Empire', 'Yakudza', 'Ice Cold', 'The Beast']

    music = ['AppleMusic subscribe']

    p_dict = {
        'Action': games_names,
        'MOVIE': movies_names,
        'MUSIC': music
    }

    for _ in range(amount):

        price = randint(0, 100)

        category = choice(list(p_dict.keys()))

        product_dict = {
            'title': choice(p_dict[category]),
            'description': lorem.sentence(),
            'price': price,
            'new_price': price // 2,
            'is_discount': choice([True, False]),
            'category': Category.objects(title=category).get(),

        }

        product = Product(**product_dict)
        product.save()
Exemple #2
0
    def post(self):

        if not request.json:

            data = json.loads(request.form['request'])

            if request.files:
                data['img'] = request.files['img'].read()

            if data.get('category'):
                category = data.pop('category')
                data['category'] = Category.objects(id=(category['id'])).get()

            obj = Product(**data)

        else:

            category = request.json.pop('category')
            request.json['category'] = Category.objects(
                id=(category['id'])).get()
            obj = Product(**request.json)

        obj.save()
        return ProductScheme().dump(obj)
Exemple #3
0
    def Process(self, section):

        if section == 'new':
            order = Order()
            storages = Storage.select()
            suppliers = Supplier.select()
            groups = Group.select()
            order.id = 0
            self.RenderFile(
                'purchase/order.htm', {
                    '_': config.i18n,
                    'order': order,
                    'storages': storages,
                    'suppliers': suppliers,
                    'group-list': groups
                })
        elif section == 'edit':
            order = Order.get(Order.id == self.IntReq('id'))

            storages = Storage.select()
            suppliers = Supplier.select()
            groups = Group.select()
            products = order.details

            for sup in suppliers:
                if sup == order.supplier:
                    sup.selected = True

            for stg in storages:
                if stg == order.storage:
                    stg.selected = True

            self.RenderFile(
                'purchase/order.htm', {
                    '_': config.i18n,
                    'order': order,
                    'storages': storages,
                    'suppliers': suppliers,
                    'group-list': groups,
                    'products': products
                })
        elif section == 'save':
            id = self.IntReq('id')
            storageId = self.IntReq('storageId')
            supplierId = self.IntReq('supplierId')

            try:
                order = Order.get(Order.id == id)
            except:
                order = Order()
                order.date = getDate()
                order.time = getTime()
                order.verified = False

            supplier = Supplier.get(Supplier.id == supplierId)
            storage = Storage.get(Storage.id == storageId)

            order.supplier = supplier
            order.storage = storage
            order.user = self.authentication.SessionObject.user
            order.save()

            form = self.getForm()
            row_ids = []
            for key in form.keys():
                if key[0] == 'g':
                    id = self.ToInt(key[(key.find('[') + 1):key.find(']')])
                    row_ids.append(id)
            row_ids.sort()
            keep_rows = []

            pids = []
            # order.clearDetails()

            for row_id in row_ids:
                x = str(row_id)
                group_id = self.IntReq('g[' + x + ']')
                product_id = self.IntReq('i[' + x + ']')

                group = Group.get(Group.id == group_id)
                p = Product()

                if product_id > 0:
                    p = Product.get(Product.id == product_id)

                p.order = order
                p.group = group
                p.name = self.StringReq('n[' + x + ']')
                p.purchase = self.FloatReq('p[' + x + ']')
                p.sale = self.FloatReq('s[' + x + ']')
                p.quantity = self.FloatReq('q[' + x + ']')
                p.save()
                pids.append(p.id)
            order.clearDetails(pids)
            self.RenderJSON({'Id': order.id})
        elif section == 'manage':
            orders = Order.select()
            self.RenderFile('purchase/manage.htm', {
                '_': config.i18n,
                'purchases': orders
            })