Commit 7cb53f8a authored by Willard's avatar Willard

Style dish info, make edit and new dish use the same template

parent c46a32aa
......@@ -24,7 +24,7 @@ class NewDishView(FormView):
db.session.commit()
return redirect(url_for('view_stall', stall_id=self.stall.id))
def render_get(self, stall_id):
return render_template('newdish.html', form=self.get_form(), stall=self.stall)
return render_template('dishinfo.html', form=self.get_form(), stall=self.stall, title='New Dish', form_action=url_for('stalls', stall_id=stall_id), submit_label='Add')
def get_form(self):
form = DishRegisterForm()
form.dish_type.choices = [(dish_type.id, dish_type.name) for dish_type in DishType.query.all()]
......@@ -56,7 +56,9 @@ class EditDishView(FormView):
form.name.data = self.dish.name
form.description.data = self.dish.description
form.price.data = self.dish.price
return render_template('editdish.html', form=form, stall=self.stall, dish=self.dish)
return render_template('dishinfo.html', form=form, stall=self.stall, dish=self.dish,
title='Edit Info', form_action=url_for('edit_dish', stall_id=self.stall.id, dish_id=self.dish.id),
image_preview=url_for('static', filename='uploads/'+self.dish.image_path), submit_label='Edit')
def get_form(self):
form = DishRegisterForm()
form.dish_type.choices = [(dish_type.id, dish_type.name) for dish_type in DishType.query.all()]
......
{% extends "base.html" %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1>Dish Info</h1>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<form action="{{ form_action }}" enctype="multipart/form-data" method="POST">
{{ form.csrf_token }}
<div class="form-group form-group-lg col-sm-8">
{{ form.name(class_="form-control") }}
</div>
<div class="form-group form-group-lg col-sm-12">
<span style="display: flex;">
<img id="image-preview" src="{{ image_preview }}" width="160px" height="160px">
{{ form.image(id="image-upload") }}
</span>
</div>
<div class="form-group form-group-lg col-sm-12">
{{ form.description(class_="form-control", rows=16) }}
</div>
<div class="form-group form-group-lg col-sm-12">
{{ form.price(class_="form-control", type="number") }}
</div>
<div class="form-group form-group-lg col-sm-12">
{{ form.dish_type.label(class_="col-sm-6 control-label") }} {{ form.dish_type(class_="form-control") }}
</div>
<div class="form-group form-group-lg">
<div class="col-sm-6">
<button class="btn btn-primary btn-block btn-lg" type="submit">{{ submit_label }}</button>
</div>
<div class="col-sm-6">
<a class="btn btn-default btn-block btn-lg" href="{{ url_for('view_stall', stall_id=stall.id) }}">Back</a>
</div>
</div>
</form>
</div>
</div>
<script>
document.getElementById("image-upload").onchange = function() {
var reader = new FileReader();
reader.onload = function(e) {
document.getElementById("image-preview").src = e.target.result;
};
reader.readAsDataURL(this.files[0])
}
</script>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %} {% block title %}Edit Dish Info{% endblock %} {% block content %}
<h1>Dish Info</h1>
<div id="form">
<form action="{{ url_for('edit_dish', stall_id=stall.id, dish_id=dish.id) }}" enctype="multipart/form-data" method="POST">
{{ form.csrf_token }}
<div class="form-input">
<div class="input-row">
{{ form.name.label(class_="field-label") }} {{ form.name(class_="text-field") }}
</div>
<div class="input-row">
<span style="display: flex;">
<img id="image-preview" src="{{url_for('static', filename='uploads/'+dish.image_path)}}" width="160px" height="160px">
{{ form.image(id="image-upload") }}
</span>
</div>
<div class="input-row">
{{ form.description.label(class_="field-label") }} {{ form.description(class_="text-area", rows=6, cols=32) }}
</div>
<div class="input-row">
{{ form.price.label(class_="field-label") }} {{ form.price(class_="text-field", type="number", style="width: 5em;") }}
</div>
<div class="input-row">
{{ form.dish_type.label(class_="field-label") }} {{ form.dish_type(class_="text-field") }}
</div>
</div>
<div class="dashboard-row">
<button type="submit">Apply</button>
<a href="{{ url_for('view_stall', stall_id=stall.id) }}"><button type="button" class="link-button">Back</button></a>
</div>
</form>
</div>
<script>
document.getElementById("image-upload").onchange = function() {
var reader = new FileReader();
reader.onload = function(e) {
document.getElementById("image-preview").src = e.target.result;
};
reader.readAsDataURL(this.files[0])
}
</script>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %} {% block title %}Add Food Item{% endblock %} {% block content %}
<h1>Dish Info</h1>
<form action="{{ url_for('new_dish', stall_id=stall.id) }}" enctype="multipart/form-data" method="POST">
{{ form.csrf_token }}
<div id="form">
<div class="form-input">
<div class="input-row">
{{ form.name.label(class_="field-label") }} {{ form.name(class_="text-field") }}
</div>
<div class="input-row">
<span style="display: flex;">
<img id="image-preview" width="160px" height="160px">
{{ form.image(id="image-upload") }}
</span>
</div>
<div class="input-row">
{{ form.description.label(class_="field-label") }} {{ form.description(class_="text-area", rows=6, cols=32) }}
</div>
<div class="input-row">
{{ form.price.label(class_="field-label") }} {{ form.price(class_="text-field", type="number", style="width: 5em;") }}
</div>
<div class="input-row">
{{ form.dish_type.label(class_="field-label") }} {{ form.dish_type(class_="text-field") }}
</div>
</div>
<div class="dashboard-row">
<button type="submit">Add</button>
<a href="{{ url_for('stalls', stall_id=stall.id) }}"><button type="button" class="link-button">Back</button></a>
</div>
</div>
</form>
<script>
document.getElementById("image-upload").onchange = function() {
var reader = new FileReader();
reader.onload = function(e) {
document.getElementById("image-preview").src = e.target.result;
};
reader.readAsDataURL(this.files[0])
}
</script>
{% endblock %}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment