Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Create input form #26

Merged
merged 60 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
9ac2894
:+1: Add title and subtitle for index.html
yusuke-sforzando Nov 20, 2020
8f6cb62
:sparkles: Add form for index.html
yusuke-sforzando Nov 20, 2020
8886f23
:sparkles: Improve main.py and index.html by form.get
yusuke-sforzando Nov 20, 2020
0eefc68
:sparkles: Improve main.py by session
yusuke-sforzando Nov 20, 2020
0105455
:sparkles:Remove api key
yusuke-sforzando Nov 20, 2020
c1cd94e
:sparkles:Use app secret key
yusuke-sforzando Nov 20, 2020
59fdc0d
:+1: Improve secret key by app secret key
yusuke-sforzando Nov 20, 2020
4f1963b
:+1: Imorove test_main.py for search result
yusuke-sforzando Nov 21, 2020
c936eee
:+1: Add tests for search-result
tomoya-sforzando Nov 21, 2020
9e15b60
:wrench: Update test for search-result
tomoya-sforzando Nov 21, 2020
4e5f0c4
:+1: Imrove main.py for test_main.py
yusuke-sforzando Nov 21, 2020
378c919
:memo: Remove template file name
yusuke-sforzando Nov 21, 2020
b4ae448
:memo: Rename html tag p to label
yusuke-sforzando Nov 21, 2020
93d857d
:memo: Check gpg
yusuke-sforzando Nov 21, 2020
e457dfa
:memo: Improve .env.gpg
yusuke-sforzando Nov 21, 2020
75529d3
:+1: Improve main.py for use context_dict
yusuke-sforzando Nov 21, 2020
86fc943
:memo: Modify index.html for use input_keyword
yusuke-sforzando Nov 21, 2020
f6cbf85
:art: Improve index.html by using label
yusuke-sforzando Nov 21, 2020
8cbdd47
:100: Fix test for search.html
tomoya-sforzando Nov 21, 2020
08e3a68
:recycle: Merge Register Airtable
yusuke-sforzando Nov 21, 2020
bc89cfd
Merge branch '009_Create_input_form' of ssh://github.com/sforzando/q-…
yusuke-sforzando Nov 21, 2020
e631e43
:bug: Fix test_GET_index
tomoya-sforzando Nov 21, 2020
c027bd6
:wrench: Rename search-result to search
tomoya-sforzando Nov 21, 2020
e5e5e20
Merge branch 'main' into 009_Create_input_form
yusuke-sforzando Nov 23, 2020
bc5fffa
:sparkles: Improve index and search by useing post method
yusuke-sforzando Nov 23, 2020
5f90e7c
:+1: Improve search.html by using if message
yusuke-sforzando Nov 23, 2020
aaf2fbd
:art: Improve main.py by using get method
yusuke-sforzando Nov 23, 2020
435c6be
:+1: Add subtitle for search
yusuke-sforzando Nov 23, 2020
c0b697f
Update tests/test_main.py
yusuke-sforzando Nov 23, 2020
345152e
Update templates/index.html
yusuke-sforzando Nov 23, 2020
a1477ac
Update templates/index.html
yusuke-sforzando Nov 23, 2020
7a7d527
Update main.py
yusuke-sforzando Nov 23, 2020
dbeb73b
Update main.py
yusuke-sforzando Nov 23, 2020
4d969ff
:+1: Improve _base.html for message
yusuke-sforzando Nov 23, 2020
e91b0fc
Merge branch '009_Create_input_form' of ssh://github.com/sforzando/q-…
yusuke-sforzando Nov 23, 2020
a91ad93
Update main.py
yusuke-sforzando Nov 23, 2020
9dc7561
:memo: Rename search.html to product list
yusuke-sforzando Nov 23, 2020
9447ba6
:memo: Change template_filename to search.html
yusuke-sforzando Nov 23, 2020
fc9494c
:memo: Change product list to search result
yusuke-sforzando Nov 23, 2020
69f704f
:wrench: Fix syntax
tomoya-sforzando Nov 23, 2020
0e19a40
:art: Improve index.html to English UI
yusuke-sforzando Nov 25, 2020
575f490
:art: Modified index.html
yusuke-sforzando Nov 25, 2020
648e8c2
:art: Improve index.html for English
yusuke-sforzando Nov 25, 2020
cb83a6d
:memo: Change search word
yusuke-sforzando Nov 25, 2020
7abe861
:+1: Change search result
yusuke-sforzando Nov 25, 2020
2695e50
:wrench: Minor update
shin-sforzando Nov 25, 2020
18e74ee
:+1: Improve base.html for display message
yusuke-sforzando Nov 25, 2020
87fde39
:recycle: Format code for html file
yusuke-sforzando Nov 25, 2020
0dcd3ee
:art: Insert a blank line for base.html
yusuke-sforzando Nov 25, 2020
909e0a9
:+1: Improve search.html for no-keyword
yusuke-sforzando Nov 25, 2020
a9678a1
:sparkles: Improve mai.py for no-search-word
yusuke-sforzando Nov 26, 2020
447a083
:anger: Merge improment heeder
yusuke-sforzando Nov 26, 2020
51ec344
:recycle: Format code
yusuke-sforzando Nov 26, 2020
7990ff9
:memo: Improve base.html for desplay message
yusuke-sforzando Nov 26, 2020
ded703b
:memo: Improve main.py for message
yusuke-sforzando Nov 26, 2020
cb5edd7
:recycle: Improve message for test_main.py
yusuke-sforzando Nov 26, 2020
dec680d
:sparkles: Add not inputed_query for test_main.py
yusuke-sforzando Nov 26, 2020
b47d07d
:fire: Remove flask_session directory
yusuke-sforzando Nov 26, 2020
7e379ca
:fire: Remove flask_session for .gitignore
yusuke-sforzando Nov 26, 2020
fd33994
:sparkles: Improve context_dict for main.py
yusuke-sforzando Nov 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .env.gpg
Binary file not shown.
25 changes: 20 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
# !/usr/bin/env python3

from flask import render_template
from flask import render_template, request

from __init__ import app


@app.route("/", methods=["GET"])
def index():
app.logger.info("index(): GET /")
context_dict = {
"message": "This is dummy message."
}
return render_template("index.html", **context_dict)
return render_template("index.html")


@app.route("/search", methods=["GET"])
def search():
app.logger.info(f"search(): GET {request.full_path}.")
keyword = request.args.get("query", None)
if keyword:
context_dict = {
"subtitle": f"Search Result for {keyword}",
"keyword": keyword,
"message": None
}
return render_template("search.html", **context_dict)
else:
context_dict = {
"message": "Enter any keywords."
}
return render_template("index.html", **context_dict)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これでは index.htmltitleSearch Result for になります。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうですね。
context_dictsubtitleを変更するコードを追記します。



if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions templates/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="static/images/favicon.png">
<title>q-lako - {{ subtitle | default("a service to quickly register equipments and books") }}</title>
<title>q-lako - {{ subtitle | default("a service to quickly register equipments and books.") }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://unpkg.com/tailwindcss@%5E1.0/dist/tailwind.min.css" rel="stylesheet">
<link href="static/css/common.css" rel="stylesheet">
Expand All @@ -15,7 +15,7 @@
<div class="flex flex-col h-screen">
{% include "_header.html" %}
{% if message %}
<p class="text-center">TODO: Show "{{ message }}" as a flash message.</p>
<p class="text-center">{{ message }}</p>
{% endif %}
<div class="container mx-auto flex-1 overflow-y-auto">
{% block main %}
Expand Down
6 changes: 6 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{% extends "_base.html" %}
{% block main %}
<h1>Registration of equipment and books.</h1>
<form action="/search" method="get">
<label for="query">Enter one of the following keywords: keyword, ISBN code, or ASIN code.</label>
<input type="text" name="query" id="query" placeholder="サーカスTC" />
<input type="submit" value="Search" />
</form>
{% endblock %}
7 changes: 7 additions & 0 deletions templates/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "_base.html" %}
{% block main %}
<h1>Search Result</h1>
{% if not message %}
<h2>Keyword: {{ keyword }}</h2>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flash messageを実装したらそもそもTopページにリダイレクトさせてからのメッセージ表示とかにできたらと思っているのだけど、

現時点では、messageが表示される = Keyword がない というない状況で、keyword: と表示されているのは変だから、

{% if not message %}
<h2>Keyword: {{ keyword }}</h2>
{% endif %}

の場合分けをするのはどうでしょうか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうですね。その方が良いですね。
修正します。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いや、むしろ index.html に戻してあげなよ。message付きで。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほどですね。
そうですね、そちらの方がユーザーファーストなのでそちらでやってみます。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index.html がレンダーされた、と言うテストが必要なのでは?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらもそうですね。
追記します。

{% endif %}
{% endblock %}
24 changes: 23 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,27 @@ def test_client():

def test_GET_index(test_client):
response = test_client.get("/")
assert b"This is dummy message." in response.data
assert response.status_code == 200
assert b"Registration of equipment and books." in response.data
assert b"Enter one of the following keywords: keyword, ISBN code, or ASIN code." in response.data


def test_GET_search_with_correct_query(test_client):
response = test_client.get("/search?query=kindle")
assert b"kindle" in response.data


def test_GET_search_with_incorrect_query(test_client):
response = test_client.get("/search?unexpected_query=kindle")
assert b"Enter any keywords." in response.data


def test_GET_search_with_not_inputted_query(test_client):
response = test_client.get("/search?query=")
assert b"a service to quickly register equipments and books." in response.data
assert b"Enter any keywords." in response.data


def test_GET_search_direct_access(test_client):
response = test_client.get("/search")
assert b"Enter any keywords." in response.data