Skip to content
This repository was archived by the owner on Sep 3, 2020. It is now read-only.

Commit 7c291db

Browse files
author
Arjun
committed
v0.4.5
- Add a Cool Search Option
1 parent 0d8caa9 commit 7c291db

File tree

13 files changed

+127
-1
lines changed

13 files changed

+127
-1
lines changed

db.sqlite3

0 Bytes
Binary file not shown.

qa/templates/qa/add.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ <h1><a href="/">Simple QA </a><small>Add Question</small></h1>
3636
<small><a href="/login">Login</a></small>
3737
{% endif %}
3838
| <a href="/admin">Admin Panel</a></small></center>
39+
<br/><br/>

qa/templates/qa/answer.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ <h4>Answering Question : {{ question.question_text }}</h4>
4040
<small><a href="/login">Login</a></small>
4141
{% endif %}
4242
| <a href="/admin">Admin Panel</a></small></center>
43+
<br/><br/>

qa/templates/qa/comment.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ <h1><a href="/">Simple QA </a><small>Add Question</small></h1>
3434
<small><a href="/login">Login</a></small>
3535
{% endif %}
3636
| <a href="/admin">Admin Panel</a></small></center>
37+
<br/><br/>

qa/templates/qa/detail.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,4 @@ <h3 class="panel-title">Answers</h3>
9696
<small><a href="/login">Login</a></small>
9797
{% endif %}
9898
| <a href="/admin">Admin Panel</a></small></center>
99+
<br/><br/>

qa/templates/qa/index.html

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{% load bootstrap3 %}
22

33
{% bootstrap_css %}
4+
5+
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
6+
47
{% bootstrap_javascript %}
58

69
<link href='http://fonts.googleapis.com/css?family=Roboto:300' rel='stylesheet' type='text/css'>
@@ -14,11 +17,96 @@
1417
background-color:#E0E0E0;
1518
color:#500000;
1619
}
20+
21+
22+
#search {
23+
position: fixed;
24+
top: 0px;
25+
left: 0px;
26+
width: 100%;
27+
height: 100%;
28+
background-color: rgba(0, 0, 0, 0.7);
29+
30+
-webkit-transition: all 0.5s ease-in-out;
31+
-moz-transition: all 0.5s ease-in-out;
32+
-o-transition: all 0.5s ease-in-out;
33+
-ms-transition: all 0.5s ease-in-out;
34+
transition: all 0.5s ease-in-out;
35+
36+
-webkit-transform: translate(0px, -100%) scale(0, 0);
37+
-moz-transform: translate(0px, -100%) scale(0, 0);
38+
-o-transform: translate(0px, -100%) scale(0, 0);
39+
-ms-transform: translate(0px, -100%) scale(0, 0);
40+
transform: translate(0px, -100%) scale(0, 0);
41+
42+
opacity: 0;
43+
}
44+
45+
#search.open {
46+
-webkit-transform: translate(0px, 0px) scale(1, 1);
47+
-moz-transform: translate(0px, 0px) scale(1, 1);
48+
-o-transform: translate(0px, 0px) scale(1, 1);
49+
-ms-transform: translate(0px, 0px) scale(1, 1);
50+
transform: translate(0px, 0px) scale(1, 1);
51+
opacity: 1;
52+
}
53+
54+
#search input[type="search"] {
55+
position: absolute;
56+
top: 50%;
57+
width: 100%;
58+
color: rgb(255, 255, 255);
59+
background: rgba(0, 0, 0, 0);
60+
font-size: 60px;
61+
font-weight: 300;
62+
text-align: center;
63+
border: 0px;
64+
margin: 0px auto;
65+
margin-top: -51px;
66+
padding-left: 30px;
67+
padding-right: 30px;
68+
outline: none;
69+
}
70+
#search .btn {
71+
position: absolute;
72+
top: 50%;
73+
left: 50%;
74+
margin-top: 61px;
75+
margin-left: -45px;
76+
}
77+
#search .close {
78+
position: fixed;
79+
top: 15px;
80+
right: 15px;
81+
color: #fff;
82+
background-color: #428bca;
83+
border-color: #357ebd;
84+
opacity: 1;
85+
padding: 10px 17px;
86+
font-size: 27px;
87+
}
88+
1789
</style>
90+
<script>
91+
$(function () {
92+
$('a[href="#search"]').on('click', function(event) {
93+
event.preventDefault();
94+
$('#search').addClass('open');
95+
$('#search > form > input[type="search"]').focus();
96+
});
97+
98+
$('#search, #search button.close').on('click keyup', function(event) {
99+
if (event.target == this || event.target.className == 'close' || event.keyCode == 27) {
100+
$(this).removeClass('open');
101+
}
102+
});
103+
104+
});
105+
</script>
18106

19107
<div class="container">
20108
<div class="page-header">
21-
<a class="btn btn-lg btn-danger pull-right" href="/add/">Ask Question</a><h1><a href="/">Simple QA </a><small>Open Questions</small></h1>
109+
<a class="btn btn-lg btn-warning pull-right" href="#search"><span class="glyphicon glyphicon-search" aria-hidden="true"></span> Find</a><a class="btn btn-lg btn-danger pull-right" href="/add/">Ask Question</a><h1><a href="/">Simple QA </a><small>Open Questions</small></h1>
22110
</div>
23111

24112
{% if questions %}
@@ -62,3 +150,13 @@
62150
<small><a href="/login">Login</a></small>
63151
{% endif %}
64152
| <a href="/admin">Admin Panel</a></small></center>
153+
<br/><br/>
154+
155+
<div id="search">
156+
<button type="button" class="close">×</button>
157+
<form method="post" action="/search/">
158+
{% csrf_token %}
159+
<input type="search" value="" name="word" placeholder="type keyword(s) here" />
160+
<input class="btn btn-lg btn-warning" type="submit" value="Find" />
161+
</form>
162+
</div>

qa/templates/qa/login.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ <h3 class="panel-title">New User?</h3>
5050
<small><a href="/login">Login</a></small>
5151
{% endif %}
5252
| <a href="/admin">Admin Panel</a></small></center>
53+
<br/><br/>

qa/templates/qa/profile.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ <h2 class="pull-right">Points: {{ user.points }}</h1>
2626
<small><a href="/login">Login</a></small>
2727
{% endif %}
2828
| <a href="/admin">Admin Panel</a></small></center>
29+
<br/><br/>

qa/templates/qa/register.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ <h1><a href="/">Simple QA </a><small>New User Registration</small></h1>
3939
<small><a href="/login">Login</a></small>
4040
{% endif %}
4141
| <a href="/admin">Admin Panel</a></small></center>
42+
<br/><br/>

qa/views.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88
from qa.models import *
99
import datetime
1010

11+
def search(request):
12+
if request.method == 'POST':
13+
word = request.POST['word']
14+
latest_question_list = Question.objects.filter(question_text__contains=word)
15+
paginator = Paginator(latest_question_list, 10)
16+
page = request.GET.get('page')
17+
try:
18+
questions = paginator.page(page)
19+
except PageNotAnInteger:
20+
# If page is not an integer, deliver first page.
21+
questions = paginator.page(1)
22+
except EmptyPage:
23+
# If page is out of range (e.g. 9999), deliver last page of results.
24+
questions = paginator.page(paginator.num_pages)
25+
template = loader.get_template('qa/index.html')
26+
context = RequestContext(request, {
27+
'questions': questions,
28+
})
29+
return HttpResponse(template.render(context))
30+
1131
def index(request):
1232
latest_question_list = Question.objects.order_by('-pub_date')
1333
paginator = Paginator(latest_question_list, 10)

0 commit comments

Comments
 (0)