generated from Code-Institute-Org/gitpod-full-template
/
add_product.html
84 lines (78 loc) · 2.43 KB
/
add_product.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{% extends 'base.html' %}
{% load static %}
{% block page_header %}
<div class="container header-container">
<div class="row">
<div class="col"></div>
</div>
</div>
{% endblock %}
{% block content %}
<div class="overlay"></div>
<div class="container-fluid pt-5">
<div class="row py-3 text-center pt-5 justify-content-center">
<div class="col-12">
<span class="icon pt-3 pt-mt-5">
<i class="fas fa-cart-plus fa-3x py-5 mt-5"></i>
</span>
<h2 class="display-font text-center pt-3">Add Products</h2>
<p class="text-center body-font mx-5 my-3 px-4">Hi, <strong>{{ user.profile|upper }}! </strong></p>
<hr class="my-2">
<p class="body-font mx-5">Use this tool to add new products to Hue's online shop!</p>
</div>
</div>
<div class="container-fluid">
<div class="row d-flex justify-content-center">
<div class="col-md-8 justify-content-center">
<div class="card p-5 my-0 mx-auto bg-main text-light body-font">
<form method="POST" action="{% url 'add_product' %}" class="form mb-2"
enctype="multipart/form-data">
{% csrf_token %}
{% for field in form %}
{% if field.name == 'image' %}
{{ field }}
{% else %}
{{ field | as_crispy_field }}
{% endif %}
{% endfor %}
<div class="text-right">
<button>
<a class="btn btn-dark rounded-0" href="{% url 'shop' %}">Cancel</a>
</button>
<button class="btn btn-dark rounded-0" type="submit">Add Product</button>
</div>
</form>
</div>
<div class="col-md-2"></div>
</div>
</div>
</div>
{% endblock %}
{% block postloadjs %}
{{ block.super }}
<script type="text/javascript">
$('#new-image').change(function () {
var file = $('#new-image')[0].files[0];
$('#filename').text(`Image will be set to: ${file.name}`);
});
</script>
<script type="text/javascript">
function predict() {
const text = document.getElementById('artwork_description').value;
const url = `/predict/?text=${encodeURIComponent(text)}`;
fetch(url)
.then(response => response.json())
.then(data => {
const predictions = data.predictions;
const datalist = document.getElementById('title_suggestions');
datalist.innerHTML = '';
predictions.forEach(prediction => {
const option = document.createElement('option');
option.value = prediction;
datalist.appendChild(option);
});
})
.catch(error => console.error(error));
}
</script>
{% endblock %}