Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
final_quintupoltrobol
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
Matthew Karl David P. Arpas
final_quintupoltrobol
Commits
8b41b926
Commit
8b41b926
authored
May 14, 2023
by
Michael Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added announcement edit and create view on views.py
parent
8a8d3f8f
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
5 deletions
+27
-5
forms.cpython-39.pyc
...upoltrobol/announcements/__pycache__/forms.cpython-39.pyc
+0
-0
urls.cpython-39.pyc
...tupoltrobol/announcements/__pycache__/urls.cpython-39.pyc
+0
-0
views.cpython-39.pyc
...upoltrobol/announcements/__pycache__/views.cpython-39.pyc
+0
-0
announcement-add.html
...nouncements/templates/announcements/announcement-add.html
+1
-0
urls.py
widget_quintupoltrobol/announcements/urls.py
+1
-3
views.py
widget_quintupoltrobol/announcements/views.py
+25
-2
No files found.
widget_quintupoltrobol/announcements/__pycache__/forms.cpython-39.pyc
0 → 100644
View file @
8b41b926
File added
widget_quintupoltrobol/announcements/__pycache__/urls.cpython-39.pyc
View file @
8b41b926
No preview for this file type
widget_quintupoltrobol/announcements/__pycache__/views.cpython-39.pyc
View file @
8b41b926
No preview for this file type
widget_quintupoltrobol/announcements/templates/announcements/announcement-add.html
View file @
8b41b926
jjikjk
\ No newline at end of file
widget_quintupoltrobol/announcements/urls.py
View file @
8b41b926
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
AnnouncementDetailView
from
.views
import
*
from
.views
import
pageview
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
pageview
,
name
=
'pageview'
),
path
(
''
,
pageview
,
name
=
'pageview'
),
path
(
'<int:pk>/details/'
,
AnnouncementDetailView
.
as_view
(),
name
=
"announcement_details"
),
path
(
'<int:pk>/details/'
,
AnnouncementDetailView
.
as_view
(),
name
=
"announcement_details"
),
path
(
"add/"
,
)
]
]
app_name
=
"announcements"
app_name
=
"announcements"
\ No newline at end of file
widget_quintupoltrobol/announcements/views.py
View file @
8b41b926
import
pytz
# need to do "pip install pytz" for this to be activated
import
pytz
# need to do "pip install pytz" for this to be activated
from
.forms
import
*
from
.models
import
Announcement
,
Reaction
from
.models
import
Announcement
,
Reaction
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.views.generic
import
ListView
,
DetailView
from
django.views.generic
import
ListView
,
DetailView
,
CreateView
,
UpdateView
from
django.db.models
import
Sum
from
django.db.models
import
Sum
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.urls
import
reverse
def
pageview
(
request
):
def
pageview
(
request
):
model_object
=
Announcement
.
objects
.
order_by
(
"-pub_datetime"
)
model_object
=
Announcement
.
objects
.
order_by
(
"-pub_datetime"
)
return
render
(
request
,
"announcements/announcements.html"
,
context
=
{
"announcement_list"
:
model_object
})
return
render
(
request
,
"announcements/announcements.html"
,
context
=
{
"announcement_list"
:
model_object
})
def
UTC_to_PHTZ
(
utctime
):
def
UTC_to_PHTZ
(
utctime
):
ph_tz
=
"
%
m/
%
d/
%
Y,
%
I:
%
M
%
p"
ph_tz
=
"
%
m/
%
d/
%
Y,
%
I:
%
M
%
p"
utc
=
utctime
.
replace
(
tzinfo
=
pytz
.
UTC
)
utc
=
utctime
.
replace
(
tzinfo
=
pytz
.
UTC
)
local_tz
=
utc
.
astimezone
(
timezone
.
get_current_timezone
)
local_tz
=
utc
.
astimezone
(
timezone
.
get_current_timezone
)
return
local_tz
.
strftime
(
ph_tz
)
return
local_tz
.
strftime
(
ph_tz
)
class
AnnouncementListView
(
ListView
):
class
AnnouncementListView
(
ListView
):
model
=
Announcement
model
=
Announcement
template_name
=
"announcements/announcements.html"
template_name
=
"announcements/announcements.html"
...
@@ -35,4 +37,25 @@ class AnnouncementDetailView(DetailView):
...
@@ -35,4 +37,25 @@ class AnnouncementDetailView(DetailView):
context
[
'pubpost_datetime'
]
=
UTC_to_PHTZ
(
announcement
.
pub_datetime
)
context
[
'pubpost_datetime'
]
=
UTC_to_PHTZ
(
announcement
.
pub_datetime
)
return
context
return
context
class
AnnouncementCreateView
(
CreateView
):
model
=
Announcement
form_class
=
AddAnnouncement
template_name
=
"announcements/announcement-add.html"
def
form_valid
(
self
,
form
):
response
=
super
()
.
form_valid
(
form
)
form
.
save
()
return
response
def
get_success_url
(
self
):
return
reverse
(
"announcement_board:announcement_details"
,
args
=
(
self
.
object
.
pk
,))
class
AnnouncementEditView
(
UpdateView
):
model
=
Announcement
form_class
=
AddAnnouncement
template_name
=
"announcements/announcement-edit.html"
def
form_valid
(
self
,
form
):
response
=
super
()
.
form_valid
(
form
)
form
.
save
()
return
response
def
get_success_url
(
self
):
return
reverse
(
"announcement_board:announcement_details"
,
args
=
(
self
.
object
.
pk
,))
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