Skip to content

Commit 1267ec7

Browse files
committed
Now the add video view model and view work together to capture the form data.
1 parent 5d648e3 commit 1267ec7

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import Optional
2+
3+
from viewmodels.shared.viewmodelbase import ViewModelBase
4+
5+
6+
class AddViewViewModel(ViewModelBase):
7+
def __init__(self, cat_name: str):
8+
super().__init__()
9+
10+
self.cat_name = cat_name
11+
self.id: Optional[str] = None
12+
self.title: Optional[str] = None
13+
self.author: Optional[str] = None
14+
self.view_count: Optional[int] = None
15+
16+
def restore_from_form(self):
17+
d = self.request_dict
18+
self.title = d.get('title')
19+
self.author = d.get('author')
20+
self.id = d.get('id')
21+
self.view_count = int(d.get('view_count', 0))

code/ch4_app/ch4_final_video_collector/views/videos.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import flask
22

33
from infrastructure.view_modifiers import response
4+
from viewmodels.videos.add_video_viewmodel import AddViewViewModel
45
from viewmodels.videos.category_viewmodel import CategoryViewModel
56
from viewmodels.videos.play_viewmodel import PlayViewModel
67

@@ -19,3 +20,15 @@ def category(cat_name: str):
1920
def play(video_id: str):
2021
vm = PlayViewModel(video_id)
2122
return vm.to_dict()
23+
24+
25+
@blueprint.post('/videos/add/<cat_name>')
26+
def add_post(cat_name: str):
27+
vm = AddViewViewModel(cat_name)
28+
vm.restore_from_form()
29+
30+
# TODO: Add video here
31+
32+
return flask.redirect(f'/videos/category/{cat_name}')
33+
34+

0 commit comments

Comments
 (0)