def schedule_get_products_from_catalogue(request): clock_time = api.send_request('scheduler', 'clock/time') time = datetime.strptime(clock_time, '"%d/%m/%Y-%H:%M:%S"') time = time + timedelta(seconds=80) time_str = time.strftime('%d/%m/%Y-%H:%M:%S') body = { "target_url": 'get-products', "target_app": 'gestion-commerciale', "time": time_str, "recurrence": "minute", "data": '{}', "source_app": "gestion-commerciale", "name": "test" } r = schedule_task(body) return render(request, 'index.html', {})
def get_product_fom_catalogue(request): Product.objects.all().delete() data = api.send_request('catalogue-produit', 'api/data') products = json.loads(data)['produits'] for product in products: new_product = Product(**product) new_product.save() nb_products = len(products) print(str(nb_products) + " products were saved") if nb_products > 0: log = Log() log.name = "last_product_update" log.code = 200 log.text = str(nb_products) + " products were saved" log.time = datetime.now() log.save() if request.method == "GET": return redirect(display_products) else: return HttpResponse()
def refresh(request): clock_time = api.send_request('scheduler', 'clock/time') time = datetime.strptime(clock_time, '"%d/%m/%Y-%H:%M:%S"') time = time + timedelta(minutes=10) # Refreshes Customers schedule_task("gestion-promotion", "admin/crm/loadcrm", time, "minute", {}, "gestion-promotion", "loadcrm") # Refreshes Products schedule_task("gestion-promotion", "admin/product/loadproduct", time, "minute", {}, "gestion-promotion", "loadproduct") # Refreshes Promotions for Ecommerce everydays schedule_task("gestion-promotion", "promo/ecommerce/calc", time, "day", {}, "gestion-promotion", "Calc ecommerce promos") # Refreshes Promotions for Magasin everydays schedule_task("gestion-promotion", "promo/magasin/calc", time, "day", {}, "gestion-promotion", "Calc magasin promos") return render(request, 'home.html')
def promo(request): res = api.send_request('gestion-promotion', 'api/v1/promo') return HttpResponse(res)
def info_gestion_commerciale(request): context = api.send_request('gestioncommerciale', 'api/info') return render(request, 'info_gestion_commerciale.html', context)
def loadproduct(request): if request.method == 'POST' or request.method == 'GET': products = api.send_request('catalogue-produit', 'api/get-all') result_expected = serializers.serialize("json", Products.objects.all()) prod, promo = json.dumps(products, sort_keys=True), json.dumps(result_expected, sort_keys=True) if prod != promo: Products.objects.all().delete() print(str(products)) p = json.loads(products) for c in p['produits']: record = Products(id=c['id'], codeProduit=c['codeProduit'], familleProduit=c['familleProduit'], descriptionProduit=c['descriptionProduit'], quantiteMin=c['quantiteMin'], packaging=c['packaging'], prix=c['prix']) record.save() if request.method == 'POST' or request.method == 'GET': products = api.send_request('catalogue-produit', 'api/get-ecommerce') result_expected = serializers.serialize("json", ProductsEco.objects.all()) prod, promo = json.dumps(products, sort_keys=True), json.dumps(result_expected, sort_keys=True) if prod != promo: ProductsEco.objects.all().delete() p = json.loads(products) for c in p['produits']: record = ProductsEco( id=c['id'], codeProduit=c['codeProduit'], familleProduit=c['familleProduit'], descriptionProduit=c['descriptionProduit'], quantiteMin=c['quantiteMin'], packaging=c['packaging'], prix=c['prix']) record.save() if request.method == 'POST' or request.method == 'GET': products = api.send_request('catalogue-produit', 'api/get-magasin') result_expected = serializers.serialize("json", ProductsMag.objects.all()) prod, promo = json.dumps(products, sort_keys=True), json.dumps(result_expected, sort_keys=True) if prod != promo: ProductsMag.objects.all().delete() p = json.loads(products) for c in p['produits']: record = ProductsMag( id=c['id'], codeProduit=c['codeProduit'], familleProduit=c['familleProduit'], descriptionProduit=c['descriptionProduit'], quantiteMin=c['quantiteMin'], packaging=c['packaging'], prix=c['prix']) record.save() return render(request, 'home.html')
def index(request): time = api.send_request('scheduler', 'clock/time') return HttpResponse("L'heure de la clock est %r" % time)
def displayForm(request): info = api.send_request("gestion-paiement", "info") print(info) name = forms.TextInput(attrs={'size': 10, 'title': 'Your name'}) return render(request, 'form.html')