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
a1fcb106
Commit
a1fcb106
authored
May 14, 2023
by
Jan Ericsson Ong Ang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated views.py
parent
511f08de
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
15 deletions
+47
-15
views.py
widget_aguandhischipmunks/calendar_app/views.py
+47
-15
No files found.
widget_aguandhischipmunks/calendar_app/views.py
View file @
a1fcb106
from
django.http
import
HttpResponse
from
django.shortcuts
import
render
,
redirect
from
django.views.generic
import
DetailView
,
CreateView
,
UpdateView
from
.models
import
Event
,
Location
from
.models
import
Event
,
Location
# calendar view f
rom .models
# calendar view f
or FBV implmentation
def
calendar
Index
(
request
):
def
calendar
_view
(
request
):
title
=
'Widget’s Calendar of Activities<br><br>'
calendars
=
Event
.
objects
.
all
()
.
order_by
(
'id'
)
events
=
Event
.
objects
.
all
(
)
return
render
(
request
,
calendar
.
html
,
{
'calendars'
,
calendars
}
)
output_view
=
""
#calendar Detail View for CBV Implementation
for
event
in
events
:
class
EventDetailView
(
DetailView
):
date_and_time
=
"Date and Time: "
+
event
.
target_datetime
.
strftime
(
"
%
m/
%
d/
%
Y,
%
I:
%
M
%
p"
)
+
"<br>"
model
=
Event
event_activity
=
"Activity: "
+
event
.
activity
+
"<br>"
template_name
=
'event-details.html'
estimated_duration
=
"Estimated Hours: "
+
str
(
event
.
estimated_hours
)
+
"<br>"
context_object_name
=
'event'
course_section
=
"Course/Section: "
+
event
.
course
.
code
+
" "
+
event
.
course
.
title
+
"-"
+
event
.
course
.
section
+
"<br>"
event_mode
=
"Mode: "
+
event
.
location
.
mode
+
"<br>"
event_venue
=
"Venue: "
+
event
.
location
.
venue
+
"<br><br>"
output_view
=
output_view
+
date_and_time
+
event_activity
+
estimated_duration
+
course_section
+
event_mode
+
event_venue
class
EventAddListView
(
CreateView
):
model
=
Event
form_class
=
AddEventForm
template_name
=
"event-add.html"
return
HttpResponse
(
title
+
output_view
)
def
post
(
self
,
request
):
\ No newline at end of file
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
})
# calendar for editing CBV implementation.
class
EventEditView
(
UpdateView
):
model
=
Event
form_class
=
AddEventForm
template_name
=
'event-edit.html'
# 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
)
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