Implement first part of the form

This commit is contained in:
Nico Schottelius 2022-01-16 00:31:59 +01:00
parent 1e69722f4b
commit e910556952
5 changed files with 40 additions and 38 deletions

View file

@ -47,9 +47,10 @@ machine. Use `kubectl get nodes` to verify minikube is up and running.
* Link to ProductOrderForm [done]
* Find suitable timeframes for a product [done]
* Continue to resources / add resources
* Need to list resources
* Need to create manytomany relations for each resource resolutling
in ResourceOrders
* Need to list resources [done]
* Need to create manytomany relations for each resource resoluting
in ResourceOrders1
* Need to pass in the price for the selected timeframe
* On submit
* List of
* resources + values

View file

@ -1,16 +1,11 @@
<h1>{{ object.name }}</h1>
<form method="post" >
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Buy">
</form>
(description to be added here)
<ul>
{% for tf in timeframes %}
<li><a href="{% url 'product-order-tf' object.slug tf.slug %}">{{ tf }}</a>
<li><a href="{% url 'product-order-tf' object.slug tf.slug %}">Buy
{{ object.name }}
for {{ tf }}</a>
{% endfor %}
</ul>
HERE we show a link to <a href="{{ productorder }}">order</a>.

View file

@ -1,16 +1,5 @@
<h1>Select Product</h1>
<h2>Product Order</h2>
<ul>
{% for product in object_list %}
{% if product.slug %}
<li>
<a href="{{ product.get_absolute_url }}">{{ product.name }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
<h2>Product List</h2>
<ul>
{% for product in object_list %}

View file

@ -1,23 +1,31 @@
Ordering a {{ product }} instance for {{ timeframe }}
we are here?!
<h2>Ordering a {{ product }} instance for {{ timeframe }}</h2>
TODO: catch invalid timeframe
<form method="post" >
{% csrf_token %}
{{ form.as_p }}
{% for res in product.resources.all %}
<li>
{% if res.minimum_units and res.maximum_units %}
<input type="range" id="{{res.slug}}" name="{{res.slug}}"
min="{{ res.minimum_units }}" max="{{ res.maximum_units
}}">
{% else %}
<input type="text" id="{{res.slug}}" name="{{res.slug}}">
<div class="form-group">
<label for="product">Product</label>
<input type="text" class="form-control"
id="product" value={{product.slug}} readonly>
</div>
<div class="form-group">
<label for="timeframe">Timeframe</label>
<input type="text" class="form-control"
id="timeframe" value="{{timeframe.slug}}" readonly>
</div>
{% endif %}
</li>
{% for res,price,currency in res_price %}
<div class="form-group">
<label for="{{res.slug}}">{{res.name}} {{res.unit}}
{{ price }}{{ currency.short_name }}/unit/{{ timeframe}}
{% if res.minimum_units %} (Min: {{res.minimum_units}}) {%endif%}
{% if res.maximum_units %} (Max: {{res.maximum_units}}) {%endif%}
</label>
<input type="text" class="form-control"
id="{{res.slug}}">
</div>
{% endfor %}
<input type="submit" value="Next">
<button type="submit" class="btn btn-primary">Submit</button>
</form>

View file

@ -17,6 +17,15 @@ class ProductOrderView(CreateView):
context = super().get_context_data(**kwargs)
context['product'] = get_object_or_404(Product, slug=self.kwargs['product'])
context['timeframe'] = get_object_or_404(TimeFrame, slug=self.kwargs['timeframe'])
res_price = []
for res in context['product'].resources.all():
price = res.price_per_time.filter(timeframe=context['timeframe'])[0].price
currency = res.price_per_time.filter(timeframe=context['timeframe'])[0].currency
res_price.append((res, price, currency))
context['res_price'] = res_price
print(context)
print(self.kwargs)
return context