Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Boodle
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Martina Therese R. Reyes
Boodle
Commits
707af165
Commit
707af165
authored
Apr 12, 2022
by
Christine Dela Rosa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ValidationErrors for StartAuction, Edit+Delete item and Adjust auctionstart/end format
parent
ce44a995
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
167 additions
and
13 deletions
+167
-13
startauction.html
boodlesite/templates/startauction.html
+1
-1
store.html
boodlesite/templates/store.html
+42
-2
forms.py
main/forms.py
+40
-3
0003_store.py
main/migrations/0003_store.py
+25
-0
urls.py
main/urls.py
+3
-0
views.py
main/views.py
+56
-7
No files found.
boodlesite/templates/startauction.html
View file @
707af165
{% extends 'boodlesite\templates\base.html' %}
{% load static %}
{% block title %}Schedule Auction{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
...
...
boodlesite/templates/store.html
View file @
707af165
...
...
@@ -42,7 +42,48 @@
<h4>
{{ item.itemname }}
</h4>
<p>
{{item.itemspecs}}
<span
class=
"item-price"
>
PHP {{item.floorprice}}
</span></p>
</div>
<div
class=
"item-btns"
>
<button>
Auction
</button>
<button>
Edit
</button>
<button>
Delete
</button>
<div
class=
"item-btns"
>
<button>
Auction
</button>
<button><a
href=
"{% url 'edititemid' item.itemid %}"
>
Edit
</a></button>
<!-- <button>Delete</button> -->
<button
type=
"button"
class=
"btn btn-primary"
data-toggle=
"modal"
data-target=
"#delete_{{ item.itemid }}"
data-whatever=
"@mdo"
>
Delete
</button>
<div
class=
"modal fade"
id=
"delete_{{ item.itemid }}"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"exampleModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog"
role=
"document"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<h5
class=
"modal-title"
id=
"exampleModalLabel"
>
Delete Item
</h5>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
>
<span
aria-hidden=
"true"
>
×
</span>
</button>
</div>
<div
class=
"modal-body"
>
<form
action=
""
method=
"POST"
>
<div
class=
"form-group"
>
<h3>
Are you sure you want to delete {{item.itemname}}?
</h3>
{% csrf_token %}
<!-- input is to get the itemid to POST for deletion -->
<!-- {{form.itemid.value|default_if_none:item.itemid }} -->
<input
name=
"itemid"
type=
"hidden"
value=
"{{item.itemid}}"
>
</div>
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-secondary"
data-dismiss=
"modal"
>
Cancel
</button>
<button
type=
"submit"
class=
"btn btn-secondary"
name=
"Submit"
>
Confirm
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
...
...
@@ -72,7 +113,6 @@
<button
type=
"button"
><a
href=
"{% url 'additemid' current_store.storeid %}"
>
Add Item
</a></button>
</div>
]
</div>
...
...
main/forms.py
View file @
707af165
from
datetime
import
datetime
from
tracemalloc
import
start
from
django
import
forms
from
django.forms
import
(
ModelForm
,
TextInput
,
Textarea
,
widgets
)
TextInput
,
Textarea
,
widgets
,
MultiWidget
)
from
django.utils.translation
import
gettext_lazy
as
_
from
.models
import
*
from
django.utils
import
timezone
import
datetime
,
pytz
from
django.contrib.admin.widgets
import
AdminSplitDateTime
from
django.contrib.admin
import
widgets
from
django.core.exceptions
import
ValidationError
class
PlaceBidForm
(
forms
.
ModelForm
):
...
...
@@ -43,7 +51,17 @@ class AddItemForm(forms.ModelForm):
'floorprice'
:
_
(
'Floor Price'
)
}
class
DeleteItemForm
(
forms
.
Form
):
itemid
=
forms
.
IntegerField
()
widgets
=
{
'itemid'
:
forms
.
HiddenInput
()}
class
StartAuctionForm
(
forms
.
ModelForm
):
# the widget is supposed to have a pop up but not showing, keeping here bc it separates date and time nicely
auctionstart
=
forms
.
SplitDateTimeField
(
widget
=
AdminSplitDateTime
())
auctionend
=
forms
.
SplitDateTimeField
(
widget
=
AdminSplitDateTime
())
class
Meta
:
model
=
Auction
fields
=
'__all__'
...
...
@@ -57,8 +75,27 @@ class StartAuctionForm(forms.ModelForm):
}
# datetime_format = ['%Y-%m-%d %H:%M']
# widgets = { 'auctionstart' : forms.
DateTimeInput(input_formats=['%Y-%m-%d %H:%M']), 'auctionend' : forms.DateTimeInput(input_formats=['%Y-%m-%d %H:%M']
)}
# widgets = { 'auctionstart' : forms.
AdminSplitDateTime()} #, 'auctionend' : forms.SplitDateTimeField(
)}
# vv fix later, is missing time widget
# widgets = { 'auctionstart' : forms.SelectDateWidget, 'auctionend':forms.SelectDateWidget}
# 'itemid': forms.HiddenInput()}
def
clean
(
self
):
super
()
.
clean
()
end_time
=
self
.
cleaned_data
[
'auctionend'
]
start_time
=
self
.
cleaned_data
[
'auctionstart'
]
current_date
=
timezone
.
now
()
auctioned_item
=
self
.
cleaned_data
[
'itemid'
]
auctions
=
Auction
.
objects
.
all
()
if
start_time
>
end_time
:
raise
ValidationError
(
'Start date should be before end date.'
)
elif
start_time
<
current_date
or
end_time
<
current_date
:
raise
ValidationError
(
'Date cannot be in the past'
)
else
:
for
auc
in
auctions
:
if
auc
.
itemid
==
auctioned_item
:
raise
ValidationError
(
'Auction Already Exists, pick another Item'
)
main/migrations/0003_store.py
0 → 100644
View file @
707af165
# Generated by Django 3.2.12 on 2022-04-07 18:31
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'main'
,
'0002_auctionbid_authgroup_authgrouppermissions_and_more'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Store'
,
fields
=
[
(
'storeid'
,
models
.
AutoField
(
primary_key
=
True
,
serialize
=
False
)),
(
'storename'
,
models
.
CharField
(
max_length
=
255
)),
(
'storedesc'
,
models
.
CharField
(
max_length
=
700
)),
],
options
=
{
'db_table'
:
'store'
,
'managed'
:
False
,
},
),
]
main/urls.py
View file @
707af165
from
django.urls
import
path
from
.views
import
*
from
django.views.i18n
import
JavaScriptCatalog
urlpatterns
=
[
path
(
''
,
homepage
,
name
=
'index'
),
...
...
@@ -11,6 +12,8 @@ urlpatterns = [
path
(
'store/<int:pk>'
,
mystore
,
name
=
'storeid'
),
path
(
'additem'
,
addItem
,
name
=
'additem'
),
path
(
'additem/<int:pk>'
,
addItem
,
name
=
'additemid'
),
path
(
'edititem/<int:pk>'
,
editItem
,
name
=
'edititemid'
),
path
(
'jsi18n'
,
JavaScriptCatalog
.
as_view
(),
name
=
'js-catlog'
),
path
(
'startauction'
,
startAuction
,
name
=
'startauction'
),
path
(
'startauction/<int:pk>'
,
startAuction
,
name
=
'startauctionid'
),
...
...
main/views.py
View file @
707af165
...
...
@@ -94,12 +94,31 @@ def tempstore(request): # temp view
def
mystore
(
request
,
pk
):
#### Access to store 1 [ edit accordingly when it becomes accessible thru a user ] ####
# pk is storeid
current_store
=
Store
.
objects
.
get
(
pk
=
pk
)
store_items
=
Item
.
objects
.
filter
(
storeid
=
pk
)
all_auctions
=
Auction
.
objects
.
all
()
form
=
DeleteItemForm
()
if
request
.
method
==
"POST"
:
form
=
DeleteItemForm
(
request
.
POST
)
if
form
.
is_valid
():
item_id
=
form
.
cleaned_data
[
'itemid'
]
current_item
=
Item
.
objects
.
get
(
itemid
=
item_id
)
for
auction
in
all_auctions
:
if
auction
.
itemid
==
current_item
:
Auction
.
objects
.
filter
(
itemid
=
item_id
)
.
delete
()
Item
.
objects
.
get
(
itemid
=
item_id
)
.
delete
()
return
redirect
(
'storeid'
,
pk
=
pk
)
context
=
{
'current_store'
:
current_store
,
'store_items'
:
store_items
'store_items'
:
store_items
,
'form'
:
form
}
...
...
@@ -125,27 +144,57 @@ def addItem(request, pk):
return
render
(
request
,
"boodlesite/templates/additem.html"
,
context
)
def
editItem
(
request
,
pk
):
item
=
Item
.
objects
.
get
(
itemid
=
pk
)
current_store
=
item
.
storeid
.
storeid
form
=
AddItemForm
(
instance
=
item
)
if
request
.
method
==
'POST'
:
form
=
AddItemForm
(
request
.
POST
,
instance
=
item
)
if
form
.
is_valid
():
form
.
save
()
return
redirect
(
'storeid'
,
pk
=
current_store
)
context
=
{
'form'
:
form
,
}
return
render
(
request
,
"boodlesite/templates/additem.html"
,
context
)
def
startAuction
(
request
,
pk
):
# pk is store id
current_store
=
Store
.
objects
.
get
(
pk
=
pk
)
store_id
=
current_store
.
storeid
# get items under this store
store_items
=
Item
.
objects
.
filter
(
storeid
=
pk
)
form
=
StartAuctionForm
(
initial
=
{
'storeid'
:
current_store
})
# temp: all auctions
all_auctions
=
Auction
.
objects
.
all
()
form
=
StartAuctionForm
(
initial
=
{
'auctionstart'
:
datetime
.
now
()})
if
request
.
method
==
'POST'
:
form
=
StartAuctionForm
(
request
.
POST
,
initial
=
{
'storeid'
:
current_store
}
)
form
=
StartAuctionForm
(
request
.
POST
)
if
form
.
is_valid
():
form
.
save
()
return
redirect
(
'storeid'
,
pk
=
pk
)
try
:
title
=
form
.
cleaned_data
[
'title'
]
info
=
form
.
cleaned_data
[
'info'
]
starttime
=
form
.
cleaned_data
[
'auctionstart'
]
endtime
=
form
.
cleaned_data
[
'auctionend'
]
current_item
=
form
.
cleaned_data
[
'itemid'
]
new_auction
=
Auction
(
title
=
title
,
info
=
info
,
auctionstart
=
starttime
,
auctionend
=
endtime
,
itemid
=
current_item
)
new_auction
.
save
()
return
redirect
(
f
"/startauction/{pk}"
)
except
:
pass
context
=
{
'current_store'
:
current_store
,
'store_items'
:
store_items
,
'all_auctions'
:
all_auctions
,
'form'
:
form
}
return
render
(
request
,
"boodlesite/templates/startauction.html"
,
context
)
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