Skip to content

Commit 4f50156

Browse files
committed
Has the ability to cancel adding a new video.
1 parent 18b529e commit 4f50156

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
<form class="video-form fade-me-in fade-me-out" action="/videos/add/{{ category.category }}" method="POST">
1+
<form class="video-form fade-me-in fade-me-out" action="/videos/add/{{ cat_name }}" method="POST">
22

33
<input type="text" class="form-control" name="id" placeholder="YouTube ID" required/>
44
<input type="text" class="form-control" name="title" placeholder="Video title" required/>
55
<input type="text" class="form-control" name="author" placeholder="Video author" required/>
66
<input type="number" class="form-control" name="view_count" placeholder="View count" required/>
77

8-
<button class="btn btn-danger" type="submit">Create</button>
8+
<button class="btn btn-success" type="submit">Create</button>
9+
10+
<button class="btn btn-danger"
11+
hx-get="/videos/cancel_add/{{ cat_name }}"
12+
hx-target=".video-form"
13+
>Cancel</button>
914

1015
</form>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<a hx-get="/videos/add/{{ cat_name }}"
2+
hx-swap="outerHTML swap:.25s"
3+
class="fade-me-out"
4+
><i class="fas fa-plus-circle"></i> add a video</a>

code/ch4_app/ch4_final_video_collector/views/videos.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ def play(video_id: str):
2323
return vm.to_dict()
2424

2525

26+
@blueprint.get('/videos/add/<cat_name>')
27+
@response(template_file='videos/partials/add_video_form.html')
28+
def add_get(cat_name: str):
29+
vm = AddViewViewModel(cat_name)
30+
return vm.to_dict()
31+
32+
2633
@blueprint.post('/videos/add/<cat_name>')
2734
def add_post(cat_name: str):
2835
vm = AddViewViewModel(cat_name)
@@ -31,3 +38,10 @@ def add_post(cat_name: str):
3138
video_service.add_video(cat_name, vm.id, vm.title, vm.author, vm.view_count)
3239

3340
return flask.redirect(f'/videos/category/{cat_name}')
41+
42+
43+
@blueprint.get('/videos/cancel_add/<cat_name>')
44+
@response(template_file='videos/partials/show_add_form.html')
45+
def cancel_add(cat_name: str):
46+
vm = AddViewViewModel(cat_name)
47+
return vm.to_dict()

0 commit comments

Comments
 (0)