Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_aguandhischipmunks
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
Adrian Lance Damalerio
midterm_aguandhischipmunks
Commits
09d5779c
Commit
09d5779c
authored
May 15, 2023
by
Jan Ericsson Ong Ang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplified views.py cbv and fbc implementation
parent
6dcb5fd1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
35 deletions
+6
-35
views.py
widget_aguandhischipmunks/calendar_app/views.py
+6
-35
No files found.
widget_aguandhischipmunks/calendar_app/views.py
View file @
09d5779c
from
django.shortcuts
import
render
,
redirect
from
django.views.generic
import
DetailView
,
CreateView
,
UpdateView
from
.models
import
Event
,
Location
from
.forms
import
AddEventForm
# calendar view for FBV implmentation
def
calendar_view
(
request
):
events
=
Event
.
objects
.
all
()
.
order_by
(
'id'
)
events
=
Event
.
objects
.
all
()
return
render
(
request
,
'calendar.html'
,
{
'events'
:
events
})
#calendar Detail View for CBV Implementation
class
EventDetailView
(
DetailView
):
model
=
Event
,
Location
model
=
Event
template_name
=
'event-details.html'
context_object_name
=
'event'
class
EventAddListView
(
CreateView
):
model
=
Event
,
Location
form_class
=
AddEventForm
model
=
Event
template_name
=
"event-add.html"
def
post
(
self
,
request
):
form
=
AddEventForm
(
request
.
POST
)
if
form
.
is_valid
():
# onSave is called, the form will have essential data and this includes pk as well.
new_event
=
form
.
save
()
# pass the pk and redirect.
return
redirect
(
'event_details'
,
pk
=
new_event
.
pk
)
else
:
return
render
(
request
,
'event-details.html'
,
{
'form'
:
form
})
fields
=
"__all__"
# calendar for editing CBV implementation.
class
EventEditView
(
UpdateView
):
model
=
Event
,
Location
form_class
=
AddEventForm
model
=
Event
template_name
=
'event-edit.html'
formatDate
=
Event
.
target_datetime
.
strftime
(
"
%
d-
%
b-
%
y"
)
# This will get the object, and this object is used to tell Django
# that we are updating.
def
get_object
(
self
,
queryset
=
None
):
pk
=
self
.
kwargs
.
get
(
'pk'
)
return
Event
.
objects
.
get
(
pk
=
pk
)
fields
=
"__all__"
def
post
(
self
,
request
,
pk
):
event
=
self
.
get_object
()
form
=
AddEventForm
(
request
.
POST
,
instance
=
event
)
if
form
.
is_valid
():
# onSave is called, the form will have essential data and this includes pk as well.
update_event
=
form
.
save
()
# pass the pk and redirect.
return
redirect
(
'event_details'
,
pk
=
update_event
.
pk
)
else
:
return
render
(
request
,
'event-details.html'
,
{
'form'
:
form
})
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