complex_status
This commit is contained in:
parent
a9fdd7bef9
commit
5c4a96afcc
@ -25,7 +25,7 @@ from alkatorapi.views import (
|
|||||||
login_status, change_racer,
|
login_status, change_racer,
|
||||||
products, cart_add, cart, cart_delete,
|
products, cart_add, cart, cart_delete,
|
||||||
cart_decrease, cart_buy, select_delivery,
|
cart_decrease, cart_buy, select_delivery,
|
||||||
delivery,
|
delivery, complex_status
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@ -50,4 +50,5 @@ urlpatterns = [
|
|||||||
path('api/cart/buy', cart_buy),
|
path('api/cart/buy', cart_buy),
|
||||||
path('api/cart/select_delivery', select_delivery),
|
path('api/cart/select_delivery', select_delivery),
|
||||||
path('api/cart/delivery', delivery),
|
path('api/cart/delivery', delivery),
|
||||||
|
path('api/complex_status', complex_status),
|
||||||
]
|
]
|
||||||
|
@ -90,6 +90,7 @@ class CartProduct(models.Model):
|
|||||||
quantity = models.IntegerField()
|
quantity = models.IntegerField()
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
super(self).clean()
|
||||||
data = self.cleaned_data
|
data = self.cleaned_data
|
||||||
if data['quantity'] <= 0:
|
if data['quantity'] <= 0:
|
||||||
raise ValidationError("Počet předmětů v košíku musí být kladný!")
|
raise ValidationError("Počet předmětů v košíku musí být kladný!")
|
||||||
@ -136,6 +137,7 @@ class InvoiceProduct(models.Model):
|
|||||||
price = models.IntegerField(default=1)
|
price = models.IntegerField(default=1)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
super(self).clean()
|
||||||
data = self.cleaned_data
|
data = self.cleaned_data
|
||||||
if data['quantity'] <= 0:
|
if data['quantity'] <= 0:
|
||||||
raise ValidationError("Počet předmětů ve faktuře musí být kladný!")
|
raise ValidationError("Počet předmětů ve faktuře musí být kladný!")
|
||||||
|
@ -395,6 +395,17 @@ def delivery(request):
|
|||||||
return HttpResponse("undefined", status=200, content_type='application/json')
|
return HttpResponse("undefined", status=200, content_type='application/json')
|
||||||
|
|
||||||
|
|
||||||
|
def complex_status(request):
|
||||||
|
return HttpResponse(json.dumps({
|
||||||
|
"products": products(request).content,
|
||||||
|
"cart": cart(request).content,
|
||||||
|
"results": results(request).content,
|
||||||
|
"delivery": delivery(request).content,
|
||||||
|
"photos": photos(request).content,
|
||||||
|
"login_status": login_status(request).content,
|
||||||
|
}))
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def cart_buy(request):
|
def cart_buy(request):
|
||||||
|
@ -35,27 +35,7 @@ class Main extends Component {
|
|||||||
cart: [],
|
cart: [],
|
||||||
delivery: undefined,
|
delivery: undefined,
|
||||||
};
|
};
|
||||||
fetch(addr_prefix + "/api/results").then(resp => resp.json()).then(json => {
|
fetch(addr_prefix + "/api/complex_status").then(resp => resp.json()).then(json => this.setState(json));
|
||||||
this.setState({results: json})
|
|
||||||
})
|
|
||||||
fetch(addr_prefix + "/api/photos").then(resp => resp.json()).then(json => {
|
|
||||||
this.setState({photos: json})
|
|
||||||
})
|
|
||||||
fetch(addr_prefix + "/api/products").then(resp => resp.json()).then(json => {
|
|
||||||
this.setState({products: json})
|
|
||||||
})
|
|
||||||
fetch(addr_prefix + "/api/cart").then(resp => resp.json()).then(json => {
|
|
||||||
this.setState({cart: json})
|
|
||||||
})
|
|
||||||
fetch(addr_prefix + "/api/login_status").then(resp => resp.json()).then(json => {
|
|
||||||
this.setState({login_status: json})
|
|
||||||
})
|
|
||||||
fetch(addr_prefix + "/api/cart/delivery").then(resp => resp.json()).then(json => {
|
|
||||||
this.setState({
|
|
||||||
cart: [...this.state.cart, {"name": "Doprava na " + json, "id": 2, "price": delivery_cost, "locked": true, "quantity": 1}],
|
|
||||||
delivery: json,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
if(window.location.search){
|
if(window.location.search){
|
||||||
let searchParams = new URLSearchParams(window.location.search);
|
let searchParams = new URLSearchParams(window.location.search);
|
||||||
for(const [key, value] of searchParams){
|
for(const [key, value] of searchParams){
|
||||||
@ -150,7 +130,7 @@ class Main extends Component {
|
|||||||
}
|
}
|
||||||
onSubmit(event){
|
onSubmit(event){
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let form = document.getElementById("form");
|
let form = event.target;
|
||||||
let api_endpoint = form.action;
|
let api_endpoint = form.action;
|
||||||
let formData = new FormData(form);
|
let formData = new FormData(form);
|
||||||
if(this.state.progress){
|
if(this.state.progress){
|
||||||
@ -204,7 +184,7 @@ class Main extends Component {
|
|||||||
};
|
};
|
||||||
selectDeliveryCallback(point){
|
selectDeliveryCallback(point){
|
||||||
if(point){
|
if(point){
|
||||||
fetch(addr_prefix + '/api/cart/select_delivery?delivery=' + point.name).then(resp => resp.json()).then(json => {
|
fetch(addr_prefix + '/api/cart/select_delivery?delivery=' + encodeURIComponent(point.name)).then(resp => resp.json()).then(json => {
|
||||||
if(json.status == "failed"){
|
if(json.status == "failed"){
|
||||||
this.setState({
|
this.setState({
|
||||||
status_text: json.reason,
|
status_text: json.reason,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user