Commit b7fbe838 authored by Leila's avatar Leila

create search form

parent 6faf06c9
Pipeline #462 skipped
......@@ -5194,7 +5194,7 @@ button.close {
main {
margin-top: 75px;
margin-left: 15px;
height: 80%; }
margin-bottom: 70px; }
.navbar-fixed-top {
background-color: #56CEE9;
......@@ -5203,6 +5203,8 @@ main {
margin-bottom: 0; }
.navbar-fixed-top .container {
height: 100%; }
.navbar-fixed-top .search {
float: right; }
.navbar-fixed-top .navbar-header img {
float: left;
width: 50px;
......@@ -5278,6 +5280,13 @@ main {
.article-body .readmore a {
text-decoration: none; }
.readmore {
margin-top: -20px; }
.tag {
margin-left: 10px;
margin-top: -20px; }
@font-face {
font-family: "fontleroybrownregular";
src: url("../fonts/bootstrap/../FontleroyBrown-webfont.eot");
......
......@@ -45,16 +45,16 @@
<li class="active"><a href="{% url 'post' %}">Articles</a></li>
<li class="active"><a href="{% url 'contact' %}">Contact</a></li>
</ul>
<form method="get" action="{% url 'search' %}" class="navbar-form search navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" name="q" value="{{ request.GET.q }}" placeholder="Search">
</div>
<button type="Submit" class="btn btn-default">Submit</button>
</form>
</div><!--/.nav-collapse -->
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="Submit" class="btn btn-default">Submit</button>
</form>
</div>
</nav>
<main style="height:100%">
<main>
{% block content %}
{% endblock %}
</main>
......
from django.views.generic import ListView, DetailView
from django.views.generic.edit import FormView
from django.db.models import Q
from django.core.urlresolvers import reverse_lazy
from taggit.models import Tag
......@@ -42,10 +44,30 @@ class PostTaggedView(PostView):
queryset = super(PostTaggedView, self).get_queryset()
return queryset.filter(tags__slug__iexact=slug)
def get_contect_data(self, **kwargs):
context = super(PostTaggedView, self).get_contect_data(**kwargs)
def get_context_data(self, **kwargs):
context = super(PostTaggedView, self).get_context_data(**kwargs)
slug = self.kwargs.get('slug', '')
tag = Tag.object.filter(slug__iexact=slug)
tag = Tag.objects.filter(slug__iexact=slug)
if len(tag):
context['cur_tag']=tag[0]
return context
class PostSearchView(PostView):
def get_context_data(self, **kwargs):
context = super(PostSearchView, self).get_context_data(**kwargs)
context['active_page'] = ''
return context
def get_queryset(self, *args, **kwargs):
queryset = super(PostSearchView, self).get_queryset(*args, **kwargs)
return queryset.filter(
Q(tags__slug__iexact=self.q) |
Q(title__icontains=self.q) |
Q(intro__icontains=self.q) |
Q(parts__text__icontains=self.q)
).distinct()
def dispatch(self, request, *args, **kwargs):
self.q = request.GET.get('q', '')
return super(PostSearchView, self).dispatch(request, *args, **kwargs)
main {
margin-top: $navbar-height*1.5;
margin-left: 15px;
height: 80%;
margin-bottom: 70px;
}
.navbar-fixed-top {
......@@ -15,6 +15,10 @@ main {
height: 100%;
}
.search {
float: right;
}
.navbar-header {
......
......@@ -56,3 +56,12 @@
}
}
}
.readmore {
margin-top: -20px;
}
.tag {
margin-left: 10px;
margin-top: -20px;
}
......@@ -4,7 +4,13 @@ from django.conf.urls.static import static
from django.contrib import admin
from cuisine_entre_amis.views import ContactView, PostView, PostDetailsView, PostTaggedView
from cuisine_entre_amis.views import(
ContactView,
PostView,
PostDetailsView,
PostTaggedView,
PostSearchView,
)
# from cuisine_entre_amis.views import HomeView
......@@ -16,6 +22,7 @@ urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^contact/$', ContactView.as_view(template_name='cuisine_entre_amis/contact.html'), name='contact'),
url(r'^tagged/(?P<slug>[\w-]+)\.html$', PostTaggedView.as_view(), name='tagged_entries'),
url(r'search\.html$', PostSearchView.as_view(), name='search'),
url(r'^$', PostView.as_view(template_name='cuisine_entre_amis/post.html'), name='post'),
url(r'^Detail/(?P<pk>[0-9]+)/$', PostDetailsView.as_view(template_name='cuisine_entre_amis/post_details.html'), name='post_details'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment