Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_jupert
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
Joseph Izon
widget_jupert
Commits
0f677172
Commit
0f677172
authored
May 26, 2022
by
Cherish Magpayo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add adding new announcement view and change index view to cbv
parent
1c329606
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
5 deletions
+24
-5
views.py
widget_jupert/announcements/views.py
+24
-5
No files found.
widget_jupert/announcements/views.py
View file @
0f677172
from
django.http
import
HttpResponse
,
Http404
from
django.http
import
HttpResponse
,
Http404
from
django.shortcuts
import
render
from
django.shortcuts
import
render
,
redirect
from
django.views
import
View
from
announcements.models
import
Announcement
from
announcements.models
import
Announcement
from
.forms
import
AnnouncementForm
# Create your views here.
# Create your views here.
def
index
(
request
):
class
IndexView
(
View
):
def
get
(
self
,
request
):
announcement_list
=
Announcement
.
objects
.
order_by
(
"
pub_date"
)
announcement_list
=
Announcement
.
objects
.
order_by
(
"-
pub_date"
)
context
=
{
context
=
{
"announcement_list"
:
announcement_list
,
"announcement_list"
:
announcement_list
,
}
}
return
render
(
request
,
"announcements/index.html"
,
context
)
return
render
(
request
,
"announcements/index.html"
,
context
)
'''def index(request):
announcement_list = Announcement.objects.order_by("-pub_date")
context = {
"announcement_list": announcement_list,
}
return render(request, "announcements/index.html", context) '''
def
details
(
request
,
announcement_id
):
def
details
(
request
,
announcement_id
):
try
:
try
:
...
@@ -20,6 +30,15 @@ def details(request, announcement_id):
...
@@ -20,6 +30,15 @@ def details(request, announcement_id):
raise
Http404
(
"Announcement does not exist!"
)
raise
Http404
(
"Announcement does not exist!"
)
return
render
(
request
,
"announcements/details.html"
,
{
"announcement"
:
announcement
})
return
render
(
request
,
"announcements/details.html"
,
{
"announcement"
:
announcement
})
def
add
(
request
):
if
request
.
method
==
"POST"
:
announcement_form
=
AnnouncementForm
(
request
.
POST
,
request
.
FILES
)
if
announcement_form
.
is_valid
():
announcement_form
.
save
()
return
redirect
(
"announcements:add"
)
else
:
announcement_form
=
AnnouncementForm
()
return
render
(
request
,
"announcements/add.html"
,
{
"announcement_form"
:
announcement_form
})
""" midterms
""" midterms
...
...
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