Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
movies-socket-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
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
Yevgeniy Ten
movies-socket-server
Commits
32c3a6b9
Commit
32c3a6b9
authored
Dec 23, 2021
by
yevgeniy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inital
parent
541db55e
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
33 additions
and
7 deletions
+33
-7
StaticResponder.cpython-310.pyc
__pycache__/StaticResponder.cpython-310.pyc
+0
-0
models.cpython-310.pyc
__pycache__/models.cpython-310.pyc
+0
-0
request.cpython-310.pyc
__pycache__/request.cpython-310.pyc
+0
-0
response.cpython-310.pyc
__pycache__/response.cpython-310.pyc
+0
-0
views.cpython-310.pyc
__pycache__/views.cpython-310.pyc
+0
-0
request.py
request.py
+1
-0
server.py
server.py
+6
-5
views.py
views.py
+26
-2
No files found.
__pycache__/StaticResponder.cpython-310.pyc
0 → 100644
View file @
32c3a6b9
File added
__pycache__/models.cpython-310.pyc
0 → 100644
View file @
32c3a6b9
File added
__pycache__/request.cpython-310.pyc
0 → 100644
View file @
32c3a6b9
File added
__pycache__/response.cpython-310.pyc
0 → 100644
View file @
32c3a6b9
File added
__pycache__/views.cpython-310.pyc
0 → 100644
View file @
32c3a6b9
File added
request.py
View file @
32c3a6b9
...
...
@@ -5,6 +5,7 @@ class Request:
self
.
uri
=
""
self
.
protocol
=
""
self
.
body
=
""
self
.
query
=
""
self
.
headers
=
{}
self
.
parse_request_line
()
self
.
parse_headers
()
...
...
server.py
View file @
32c3a6b9
...
...
@@ -6,7 +6,6 @@ import views
from
random
import
randint
class
HelloTCPServer
(
StreamRequestHandler
):
def
handle
(
self
):
request
=
Request
(
self
.
rfile
)
...
...
@@ -19,10 +18,12 @@ class HelloTCPServer(StreamRequestHandler):
else
:
response
.
add_header
(
"Content-Type"
,
"text/html"
)
response
.
add_header
(
"Connection"
,
"close"
)
if
'?'
in
request
.
uri
:
query_split
=
request
.
uri
.
split
(
"?"
)
request
.
uri
=
query_split
[
0
]
request
.
query
=
query_split
[
1
]
route_func
=
views
.
routes
.
get
(
request
.
uri
,
"404"
)
if
"/movies/"
in
request
.
uri
:
views
.
show_movie
(
request
,
response
)
elif
route_func
==
"404"
:
if
route_func
==
"404"
:
response
.
set_status
(
Response
.
HTTP_NOT_FOUND
)
else
:
route_func
(
request
,
response
)
...
...
@@ -34,7 +35,7 @@ class ThreadedTCPServe(ThreadingMixIn, TCPServer):
pass
HOST
,
PORT
=
"127.0.0.1"
,
800
0
HOST
,
PORT
=
"127.0.0.1"
,
800
1
TCPServer
.
allow_reuse_address
=
True
with
TCPServer
((
HOST
,
PORT
),
HelloTCPServer
)
as
s
:
...
...
views.py
View file @
32c3a6b9
...
...
@@ -22,7 +22,7 @@ def show_movies(request, response):
<div class="card-body">
<h5 class="card-title">{movie.id} {movie.name}</h5>
<p class="card-text">{movie.description}</p>
<a href="/movies/{movie.id}" class="btn btn-primary">Detail</a>
<a href="/movies/
find?id=
{movie.id}" class="btn btn-primary">Detail</a>
</div>
</div>
</div>
...
...
@@ -61,7 +61,31 @@ def create_movie(request, response):
response
.
add_header
(
'Location'
,
"/"
)
def
find_one_movie
(
request
,
response
):
id_split
=
request
.
query
.
split
(
"="
)
if
len
(
id_split
)
>
1
:
id
=
id_split
[
1
]
movie
=
db_movie
.
find_by_id
(
int
(
id
))
html_movie
=
f
'''
<div class="card" >
<img src="{movie.img_url}" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Name: {movie.name}</h5>
<p class="card-text">Description: {movie.description}.</p>
<p class="card-text">Rating: {movie.rating}.</p>
</div>
</div>
'''
with
open
(
"templates/detail.html"
,
"r"
)
as
file
:
html
=
file
.
read
()
result_html
=
html
.
replace
(
"{{movie}}"
,
html_movie
)
response
.
set_body
(
result_html
)
else
:
pass
routes
=
{
"/"
:
show_movies
,
"/create"
:
create_movie
"/create"
:
create_movie
,
"/movies/find"
:
find_one_movie
}
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