Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS123-Canteeneo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Willard Torres
CS123-Canteeneo
Commits
3327c176
Commit
3327c176
authored
Nov 15, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add dish type to forms and models
parent
25e5399e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
2 deletions
+21
-2
dish_views.py
canteeneo/dish_views.py
+4
-2
forms.py
canteeneo/forms.py
+1
-0
models.py
canteeneo/models.py
+10
-0
editdish.html
canteeneo/templates/editdish.html
+3
-0
newdish.html
canteeneo/templates/newdish.html
+3
-0
No files found.
canteeneo/dish_views.py
View file @
3327c176
import
os.path
import
os.path
from
canteeneo
import
app
,
db
from
canteeneo
import
app
,
db
from
canteeneo.models
import
Stall
,
Dish
from
canteeneo.models
import
Stall
,
Dish
,
DishType
from
canteeneo.forms
import
DishRegisterForm
from
canteeneo.forms
import
DishRegisterForm
from
canteeneo.views
import
flash_form_errors
,
stall_validate
,
dish_validate
,
FormView
from
canteeneo.views
import
flash_form_errors
,
stall_validate
,
dish_validate
,
FormView
...
@@ -26,7 +26,9 @@ class NewDishView(FormView):
...
@@ -26,7 +26,9 @@ class NewDishView(FormView):
def
render_get
(
self
,
stall_id
):
def
render_get
(
self
,
stall_id
):
return
render_template
(
'newdish.html'
,
form
=
self
.
get_form
(),
stall
=
self
.
stall
)
return
render_template
(
'newdish.html'
,
form
=
self
.
get_form
(),
stall
=
self
.
stall
)
def
get_form
(
self
):
def
get_form
(
self
):
return
DishRegisterForm
()
form
=
DishRegisterForm
()
form
.
dish_type
.
choices
=
[(
dish_type
.
id
,
dish_type
.
name
)
for
dish_type
in
DishType
.
query
.
all
()]
return
form
class
DishView
(
View
):
class
DishView
(
View
):
decorators
=
[
login_required
,
dish_validate
]
decorators
=
[
login_required
,
dish_validate
]
...
...
canteeneo/forms.py
View file @
3327c176
...
@@ -68,6 +68,7 @@ class DishRegisterForm(FlaskForm):
...
@@ -68,6 +68,7 @@ class DishRegisterForm(FlaskForm):
description
=
TextAreaField
(
'Description'
,
[
DataRequired
()])
description
=
TextAreaField
(
'Description'
,
[
DataRequired
()])
image
=
FileField
(
'Image'
)
image
=
FileField
(
'Image'
)
price
=
DecimalField
(
'Price'
,
[
DataRequired
()])
price
=
DecimalField
(
'Price'
,
[
DataRequired
()])
dish_type
=
SelectField
(
'Type'
,
coerce
=
int
)
def
validate
(
self
,
editing
=
False
):
def
validate
(
self
,
editing
=
False
):
if
not
FlaskForm
.
validate
(
self
):
if
not
FlaskForm
.
validate
(
self
):
...
...
canteeneo/models.py
View file @
3327c176
...
@@ -33,6 +33,7 @@ class Dish(db.Model):
...
@@ -33,6 +33,7 @@ class Dish(db.Model):
description
=
db
.
Column
(
db
.
Text
)
description
=
db
.
Column
(
db
.
Text
)
price
=
db
.
Column
(
db
.
Float
)
price
=
db
.
Column
(
db
.
Float
)
stall_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'stall.id'
))
stall_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'stall.id'
))
type_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'dish_type.id'
))
image_path
=
db
.
Column
(
db
.
String
(
160
),
unique
=
True
)
image_path
=
db
.
Column
(
db
.
String
(
160
),
unique
=
True
)
favorites
=
db
.
relationship
(
'User'
,
secondary
=
dish_favorites
,
backref
=
db
.
backref
(
'dish'
,
lazy
=
'dynamic'
))
favorites
=
db
.
relationship
(
'User'
,
secondary
=
dish_favorites
,
backref
=
db
.
backref
(
'dish'
,
lazy
=
'dynamic'
))
reviews
=
db
.
relationship
(
'DishReview'
,
backref
=
'dish'
,
lazy
=
'dynamic'
)
reviews
=
db
.
relationship
(
'DishReview'
,
backref
=
'dish'
,
lazy
=
'dynamic'
)
...
@@ -44,6 +45,14 @@ class Dish(db.Model):
...
@@ -44,6 +45,14 @@ class Dish(db.Model):
self
.
stall_id
=
stall_id
self
.
stall_id
=
stall_id
self
.
image_path
=
image_path
self
.
image_path
=
image_path
class
DishType
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
name
=
db
.
Column
(
db
.
String
(
80
))
dishes
=
db
.
relationship
(
'Dish'
,
backref
=
'type'
,
lazy
=
'dynamic'
)
def
__init__
(
self
,
name
):
self
.
name
=
name
class
Owner
(
db
.
Model
):
class
Owner
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
name
=
db
.
Column
(
db
.
String
(
80
))
name
=
db
.
Column
(
db
.
String
(
80
))
...
@@ -80,6 +89,7 @@ class Owner(db.Model):
...
@@ -80,6 +89,7 @@ class Owner(db.Model):
class
Location
(
db
.
Model
):
class
Location
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
name
=
db
.
Column
(
db
.
String
(
80
))
name
=
db
.
Column
(
db
.
String
(
80
))
stalls
=
db
.
relationship
(
'Stall'
,
backref
=
'location'
,
lazy
=
'dynamic'
)
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
name
=
name
...
...
canteeneo/templates/editdish.html
View file @
3327c176
...
@@ -19,6 +19,9 @@
...
@@ -19,6 +19,9 @@
<div
class=
"input-row"
>
<div
class=
"input-row"
>
{{ form.price.label(class_="field-label") }} {{ form.price(class_="text-field", type="number", style="width: 5em;") }}
{{ form.price.label(class_="field-label") }} {{ form.price(class_="text-field", type="number", style="width: 5em;") }}
</div>
</div>
<div
class=
"input-row"
>
{{ form.dish_type.label(class_="field-label") }} {{ form.dish_type(class_="text-field") }}
</div>
</div>
</div>
<div
class=
"dashboard-row"
>
<div
class=
"dashboard-row"
>
<button
type=
"submit"
>
Apply
</button>
<button
type=
"submit"
>
Apply
</button>
...
...
canteeneo/templates/newdish.html
View file @
3327c176
...
@@ -19,6 +19,9 @@
...
@@ -19,6 +19,9 @@
<div
class=
"input-row"
>
<div
class=
"input-row"
>
{{ form.price.label(class_="field-label") }} {{ form.price(class_="text-field", type="number", style="width: 5em;") }}
{{ form.price.label(class_="field-label") }} {{ form.price(class_="text-field", type="number", style="width: 5em;") }}
</div>
</div>
<div
class=
"input-row"
>
{{ form.dish_type.label(class_="field-label") }} {{ form.dish_type(class_="text-field") }}
</div>
</div>
</div>
<div
class=
"dashboard-row"
>
<div
class=
"dashboard-row"
>
<button
type=
"submit"
>
Add
</button>
<button
type=
"submit"
>
Add
</button>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment