Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_tee jays angelos
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
Ramon Angelo Enriquez
widget_tee jays angelos
Commits
39206cac
Commit
39206cac
authored
May 16, 2022
by
Sumawang, Tee Jay Jr. C.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added working foundations for announcements templates. CSS style necessary
parent
1c3111e9
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
27 deletions
+81
-27
details.html
...ngelos/announcements/templates/announcements/details.html
+10
-0
index.html
..._angelos/announcements/templates/announcements/index.html
+11
-0
urls.py
widget_tee_jays_angelos/announcements/urls.py
+2
-1
views.py
widget_tee_jays_angelos/announcements/views.py
+55
-26
db.sqlite3
widget_tee_jays_angelos/db.sqlite3
+0
-0
settings.py
widget_tee_jays_angelos/widget_tee_jays_angelos/settings.py
+3
-0
No files found.
widget_tee_jays_angelos/announcements/templates/announcements/details.html
0 → 100644
View file @
39206cac
{% if Announcement %}
<h2>
{{Announcement.announcement_title}}
</h2>
<h3>
by {{Announcement.author.first_name}} {{Announcement.author.last_name}}, {{Announcement.pub_date}}
</h3>
<h4>
{{Announcement.announcement_body}}
</h4>
{% for reaction in reactions %}
<h4>
{{reaction.reaction_name}}: {{reaction.tally}}
</h4>
{% endfor %}
{% else %}
<p>
Announcement not found.
</p>
{% endif %}
\ No newline at end of file
widget_tee_jays_angelos/announcements/templates/announcements/index.html
0 → 100644
View file @
39206cac
{% if announcement_list %}
<h1>
Announcement Board
</h1>
<h2>
Important Announcements:
</h2>
<ul>
{% for Announcement in announcement_list %}
<li><a
href=
"/announcements/{{Announcement.id}}/details"
>
{{Announcement.announcement_title}}, by {{Announcement.author.last_name}}, {{Announcement.author.first_name}}, dated {{Announcement.pub_date}}
</a></li>
{% endfor %}
</ul>
{% else %}
<p>
No Announcements are available
</p>
{% endif %}
\ No newline at end of file
widget_tee_jays_angelos/announcements/urls.py
View file @
39206cac
...
...
@@ -2,5 +2,6 @@ from django.urls import path
from
.
import
views
urlpatterns
=
[
path
(
''
,
views
.
index
,
name
=
"announcements"
)
path
(
''
,
views
.
index
,
name
=
"announcements"
),
path
(
'<int:announcement_id>/details/'
,
views
.
details
,
name
=
"details"
),
]
widget_tee_jays_angelos/announcements/views.py
View file @
39206cac
from
django.http
import
HttpResponse
from
array
import
array
from
django.http
import
HttpResponse
,
Http404
from
announcements.models
import
Announcement
,
Reaction
,
WidgetUser
from
django.shortcuts
import
render
from
django.template
import
loader
# Create your views here.
def
index
(
request
):
announcementEntries
=
Announcement
.
objects
.
all
()
.
count
()
n
=
1
announcement
=
"ANNOUNCEMENTS:<br/>"
while
(
n
<=
announcementEntries
):
announcement
+=
getAnnouncementHeader
(
n
)
announcement
+=
getReactions
(
n
)
n
+=
1
return
HttpResponse
(
announcement
)
# announcementEntries = Announcement.objects.all().count()
# n = 1
# announcement = "ANNOUNCEMENTS:<br/>"
# while(n<=announcementEntries):
# announcement += getAnnouncementHeader(n)
# announcement += getReactions(n)
# n += 1
# return HttpResponse(announcement)
announcement_list
=
Announcement
.
objects
.
order_by
(
"pub_date"
)
context
=
{
"announcement_list"
:
announcement_list
,
}
return
render
(
request
,
"announcements/index.html"
,
context
)
# helper function that iterates through every reaction of an announcement
and returns it
# helper function that iterates through every reaction of an announcement
, adds it to an array, then returns it
def
getReactions
(
pk
):
announcementReactions
=
""
# announcementReactions = ""
# for reaction in Announcement.objects.get(pk=pk).announcements.all():
# announcementReactions += "{}: {}<br/>" .format(reaction.reaction_name, reaction.tally)
# announcementReactions += "<br/> "
# return announcementReactions
# announcementReactions = ""
announcementReactions
=
[]
for
reaction
in
Announcement
.
objects
.
get
(
pk
=
pk
)
.
announcements
.
all
():
announcementReactions
+=
"{}: {}<br/>"
.
format
(
reaction
.
reaction_name
,
reaction
.
tally
)
announcementReactions
+=
"<br/> "
announcementReactions
.
append
(
reaction
)
return
announcementReactions
# helper function that takes the data in an announcement and creates the header of the announcement
# (First and Second lines)
def
getAnnouncementHeader
(
pk
):
announcementFirstLine
=
""
announcementSecondLine
=
""
announcementHeader
=
""
# def getAnnouncementHeader(pk):
# announcementFirstLine = ""
# announcementSecondLine = ""
# announcementHeader = ""
# announcementTitle = Announcement.objects.get(pk=pk).announcement_title
# authorFirstName = Announcement.objects.get(pk=pk).author.first_name
# authorLastName = Announcement.objects.get(pk=pk).author.last_name
# publicationDate = Announcement.objects.get(pk=pk).pub_date
# announcementBody = Announcement.objects.get(pk=pk).announcement_body
# announcementFirstLine = "{} by {} {} dated {}:<br/>" .format(announcementTitle, authorFirstName, authorLastName, publicationDate)
# announcementSecondLine = "{}<br/>" .format(announcementBody)
# announcementHeader += announcementFirstLine + announcementSecondLine
announcementTitle
=
Announcement
.
objects
.
get
(
pk
=
pk
)
.
announcement_title
authorFirstName
=
Announcement
.
objects
.
get
(
pk
=
pk
)
.
author
.
first_name
authorLastName
=
Announcement
.
objects
.
get
(
pk
=
pk
)
.
author
.
last_name
publicationDate
=
Announcement
.
objects
.
get
(
pk
=
pk
)
.
pub_date
announcementBody
=
Announcement
.
objects
.
get
(
pk
=
pk
)
.
announcement_body
announcementFirstLine
=
"{} by {} {} dated {}:<br/>"
.
format
(
announcementTitle
,
authorFirstName
,
authorLastName
,
publicationDate
)
announcementSecondLine
=
"{}<br/>"
.
format
(
announcementBody
)
announcementHeader
+=
announcementFirstLine
+
announcementSecondLine
# return announcementHeader
return
announcementHeader
def
details
(
request
,
announcement_id
):
try
:
announcement
=
Announcement
.
objects
.
get
(
pk
=
announcement_id
)
except
Announcement
.
DoesNotExist
:
raise
Http404
(
"Announcement does not exist!"
)
try
:
reactions
=
getReactions
(
pk
=
announcement_id
)
except
Reaction
.
DoesNotExist
:
raise
Http404
(
"Reaction does not exist"
)
context
=
{
"Announcement"
:
announcement
,
"reactions"
:
reactions
}
return
render
(
request
,
"announcements/details.html"
,
context
)
\ No newline at end of file
widget_tee_jays_angelos/db.sqlite3
View file @
39206cac
No preview for this file type
widget_tee_jays_angelos/widget_tee_jays_angelos/settings.py
View file @
39206cac
...
...
@@ -31,6 +31,9 @@ DEBUG = True
ALLOWED_HOSTS
=
[]
# Change Date Format
DATE_FORMAT
=
"m-d-Y"
USE_L10N
=
False
# Application definition
...
...
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