Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs50-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Minhao Qiu
cs50-web
Commits
2fa6beed
Commit
2fa6beed
authored
5 years ago
by
Minhao Qiu
Browse files
Options
Downloads
Patches
Plain Diff
add total vote function
parent
b84678a8
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app_9/app.py
+9
-4
9 additions, 4 deletions
app_9/app.py
app_9/static/js/index.js
+11
-0
11 additions, 0 deletions
app_9/static/js/index.js
app_9/templates/index.html
+5
-2
5 additions, 2 deletions
app_9/templates/index.html
with
25 additions
and
6 deletions
app_9/app.py
+
9
−
4
View file @
2fa6beed
...
@@ -11,16 +11,21 @@ socketio = SocketIO(app)
...
@@ -11,16 +11,21 @@ socketio = SocketIO(app)
# A list which is used to save the history vote
# A list which is used to save the history vote
history
=
[]
history
=
[]
votes
=
{
"
yes
"
:
0
,
"
no
"
:
0
,
"
maybe
"
:
0
}
@app.route
(
"
/
"
)
@app.route
(
"
/
"
)
def
index
():
def
index
():
return
render_template
(
"
index.html
"
)
return
render_template
(
"
index.html
"
,
votes
=
votes
)
@socketio.on
(
'
submit vote
'
)
@socketio.on
(
'
submit vote
'
)
def
vote
(
data
):
def
vote
(
data
):
selection
=
data
[
"
selection
"
]
selection
=
data
[
"
selection
"
]
history
.
append
(
"
selection:
"
+
selection
)
#history.append("selection: " + selection)
votes
[
selection
]
+=
1
print
(
votes
)
emit
(
'
announce vote
'
,
{
"
selection
"
:
selection
},
broadcast
=
True
)
emit
(
'
announce vote
'
,
{
"
selection
"
:
selection
},
broadcast
=
True
)
print
(
history
)
emit
(
"
votes total
"
,
votes
,
broadcast
=
True
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
socketio
.
run
(
app
)
socketio
.
run
(
app
,
debug
=
True
)
\ No newline at end of file
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app_9/static/js/index.js
+
11
−
0
View file @
2fa6beed
...
@@ -21,6 +21,17 @@ document.addEventListener('DOMContentLoaded', () => {
...
@@ -21,6 +21,17 @@ document.addEventListener('DOMContentLoaded', () => {
const
li
=
document
.
createElement
(
'
li
'
);
const
li
=
document
.
createElement
(
'
li
'
);
li
.
innerHTML
=
`Vote recorded:
${
data
.
selection
}
`
;
li
.
innerHTML
=
`Vote recorded:
${
data
.
selection
}
`
;
document
.
querySelector
(
'
#votes
'
).
append
(
li
);
document
.
querySelector
(
'
#votes
'
).
append
(
li
);
});
socket
.
on
(
'
votes total
'
,
data
=>
{
document
.
querySelector
(
'
#yes
'
).
innerHTML
=
data
.
yes
;
document
.
querySelector
(
'
#no
'
).
innerHTML
=
data
.
no
;
document
.
querySelector
(
'
#maybe
'
).
innerHTML
=
data
.
maybe
;
});
});
});
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app_9/templates/index.html
+
5
−
2
View file @
2fa6beed
...
@@ -6,8 +6,11 @@
...
@@ -6,8 +6,11 @@
<title>
Vote
</title>
<title>
Vote
</title>
</head>
</head>
<body>
<body>
<ul
id=
"votes"
>
<ul
id=
"votes"
></ul>
</ul>
<hr>
<div>
Yes Votes:
<span
id=
"yes"
>
{{ votes["yes"] }}
</span></div>
<div>
No Votes:
<span
id=
"no"
>
{{ votes["no"] }}
</span></div>
<div>
Maybe Votes:
<span
id=
"maybe"
>
{{ votes["maybe"] }}
</span></div>
<hr>
<hr>
<button
data-vote=
"yes"
>
Yes
</button>
<button
data-vote=
"yes"
>
Yes
</button>
<button
data-vote=
"no"
>
No
</button>
<button
data-vote=
"no"
>
No
</button>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment