Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
Hunger Buster - Breadcrumbs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julia Santos
Hunger Buster - Breadcrumbs
Commits
66990953
Commit
66990953
authored
Mar 17, 2021
by
Julia Santos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added image validation
parent
5635366c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
1 deletion
+11
-1
forms.py
Breadcrumbs/forms.py
+2
-1
views.py
Breadcrumbs/views.py
+9
-0
carrot_skXk6Hw.png
media/upload/carrot_skXk6Hw.png
+0
-0
milk_eciWSYY.png
media/upload/milk_eciWSYY.png
+0
-0
No files found.
Breadcrumbs/forms.py
View file @
66990953
from
django
import
forms
from
django
import
forms
from
django.core.validators
import
FileExtensionValidator
class
LoginForm
(
forms
.
Form
):
class
LoginForm
(
forms
.
Form
):
user
=
forms
.
CharField
(
label
=
'username'
,
max_length
=
100
)
user
=
forms
.
CharField
(
label
=
'username'
,
max_length
=
100
)
...
@@ -9,4 +10,4 @@ class ProductTypeForm(forms.Form):
...
@@ -9,4 +10,4 @@ class ProductTypeForm(forms.Form):
Product_Category
=
forms
.
CharField
(
max_length
=
255
)
Product_Category
=
forms
.
CharField
(
max_length
=
255
)
Product_Description
=
forms
.
CharField
(
max_length
=
255
,
required
=
False
)
Product_Description
=
forms
.
CharField
(
max_length
=
255
,
required
=
False
)
To_Buy
=
forms
.
BooleanField
(
initial
=
False
,
required
=
False
)
To_Buy
=
forms
.
BooleanField
(
initial
=
False
,
required
=
False
)
Icon
=
forms
.
ImageField
()
Icon
=
forms
.
ImageField
(
validators
=
[
FileExtensionValidator
(
[
'png'
,
'jpg'
]
)
])
\ No newline at end of file
\ No newline at end of file
Breadcrumbs/views.py
View file @
66990953
...
@@ -3,6 +3,7 @@ from django.db.models import Q
...
@@ -3,6 +3,7 @@ from django.db.models import Q
from
.forms
import
LoginForm
,
ProductTypeForm
from
.forms
import
LoginForm
,
ProductTypeForm
from
django.http
import
HttpResponseRedirect
from
django.http
import
HttpResponseRedirect
from
django.shortcuts
import
render
,
get_object_or_404
from
django.shortcuts
import
render
,
get_object_or_404
from
django.forms
import
ValidationError
from
django.views.generic.edit
import
DeleteView
from
django.views.generic.edit
import
DeleteView
from
.models
import
User
,
Product_Type
,
Item
,
Recipe
from
.models
import
User
,
Product_Type
,
Item
,
Recipe
...
@@ -58,9 +59,17 @@ def add_product_type(request):
...
@@ -58,9 +59,17 @@ def add_product_type(request):
product_description
=
form
.
cleaned_data
.
get
(
"Product_Description"
)
product_description
=
form
.
cleaned_data
.
get
(
"Product_Description"
)
to_buy
=
form
.
cleaned_data
.
get
(
"To_Buy"
)
to_buy
=
form
.
cleaned_data
.
get
(
"To_Buy"
)
icon
=
form
.
cleaned_data
.
get
(
"Icon"
)
icon
=
form
.
cleaned_data
.
get
(
"Icon"
)
if
icon
:
if
icon
.
size
>
4
*
1024
*
1024
:
#( > 4mb )
raise
ValidationError
(
"Image file too large"
)
return
icon
else
:
raise
ValidationError
(
"Couldn't read uploaded image"
)
#item = Product_Type.objects.create(Product_Name = product_name, Product_Category = product_category, Product_Description = product_description, To_Buy = to_buy, User_id = self.request.user.User_ID, Icon = icon)
#item = Product_Type.objects.create(Product_Name = product_name, Product_Category = product_category, Product_Description = product_description, To_Buy = to_buy, User_id = self.request.user.User_ID, Icon = icon)
instance
=
Product_Type
.
objects
.
create
(
Product_Name
=
product_name
,
Product_Category
=
product_category
,
Product_Description
=
product_description
,
To_Buy
=
to_buy
,
User_ID
=
request
.
user
,
Icon
=
icon
)
instance
=
Product_Type
.
objects
.
create
(
Product_Name
=
product_name
,
Product_Category
=
product_category
,
Product_Description
=
product_description
,
To_Buy
=
to_buy
,
User_ID
=
request
.
user
,
Icon
=
icon
)
instance
.
save
()
instance
.
save
()
return
HttpResponseRedirect
(
'/fridge/list/'
)
else
:
else
:
form
=
ProductTypeForm
()
form
=
ProductTypeForm
()
context
[
'form'
]
=
form
context
[
'form'
]
=
form
...
...
media/upload/carrot_skXk6Hw.png
deleted
100644 → 0
View file @
5635366c
14.9 KB
media/upload/milk_eciWSYY.png
deleted
100644 → 0
View file @
5635366c
19.4 KB
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