Commit f3eebc12 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

added search

parent 93127c7d
Django==1.7.3
Whoosh==2.6.0
argparse==1.2.1
beautifulsoup4==4.3.2
django-allauth==0.19.0
django-analytical==0.19.0
django-autoslug==1.7.2
......@@ -7,8 +9,10 @@ django-braces==1.4.0
django-crispy-forms==1.4.0
git+https://github.com/the-ben-waters/django-cas.git
django-gravatar2==1.1.4
django-haystack==2.3.1
django-localflavor==1.0
django-model-utils==2.2
django-randomslugfield==0.3.0
oauthlib==0.7.2
psycopg2==2.5.4
python-openid==2.2.5
......
import datetime
from haystack import indexes
from .models import Student
class StudentIndex(indexes.SearchIndex, indexes.Indexable):
# search results
# there can BE ONLY ONE document=True per model
text = indexes.CharField(document=True, use_template=True)
# the use_template is in the app directory, just a text file
# with the fields that we want to display when returning results
# search filtering
user = indexes.CharField( model_attr = 'user' )
def get_model(self):
return Student
def index_queryset(self, using=None):
"""When the entire index for model is updated."""
return self.get_model().objects.all()
{{ object.user.username }}
{{ object.user.get_full_name }}
{% extends 'layouts/base.html' %}
{% block title %}
SRCT Roomlist • Search Students
{% endblock %}
{% block content %}
<div class="page-header" id="banner">
<div class="row">
<div class="col-lg-12">
<h1 class="text-center"><strong>SRCT</strong>&#8203;ROOMLIST</h1>
<p class="lead text-center"><strong>Search</strong></p>
</div>
</div>
</div>
<form class="form-horizontal" method="get" action=".">
<div class="form-group">
<label for="id_q" class="col-md-1 col-md-offset-4 control-label"><strong>Name</strong> or <strong>Username</strong></label>
<div class="col-md-2">
{{ form.q }}
</div>
<button type="submit" class="btn btn-default"><i class="fa fa-search fa-fw fa-lg"></i></button>
</div>
</form>
{% if query %}
<div class="row">
<div class="col-md-10 col-md-offset-1">
{% if page.object_list %}
<table class="table table-hover">
<thead>
<th class="col-md-2"><h3><small>Username</small></h3></th>
<th class="col-md-6"><h3><small>Name</small></h3></th>
<th class="col-md-4"><h3><small>Major</small></h3></th>
</thead>
{% endif %}
{% for result in page.object_list %}
<tr>
<td>
<h4>{{ result.object.user.username }}</h4>
</td>
<td>
<a href="{{ result.object.get_absolute_url }}"><h4><strong>{{ result.object.user.get_full_name }}</strong></h4></a>
</td>
<td>
<h4>{{ result.object.major }}</h4>
</td>
</tr>
{% empty %}
<h3 class="text-center">No results found.</h3>
{% endfor %}
{% if page.object_list %}
</table>
{% endif %}
</div>
</div>
<div class="row">
<div class="col-lg-4 col-lg-offset-4">
<ul class="pager">
{% if page.has_previous %}
<li class="previous">
<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">
<h4>&larr; Previous</h4>
</a>
</li>
{% else %}
<li class="previous disabled">
<a>
<h4>&larr; Previous</h4>
</a>
</li>
{% endif %}
{% if page.has_next %}
<li class="next">
<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">
<h4>Next &rarr;</h4>
</a>
</li>
{% else %}
<li class="next disabled">
<a>
<h4>Next &rarr;</h4>
</a>
</li>
{% endif %}
</ul>
</div>
</div>
{% endif %}
{% endblock %}
......@@ -21,6 +21,9 @@ urlpatterns = patterns('',
url(r'^housing/', include('housing.urls')),
url(r'^accounts/', include('accounts.urls')),
# search
url(r'^search/', include('haystack.urls'), name='search'),
# login and logout
#url(r'^login/', 'cas.views.login', name='login'),
#url(r'^logout/', 'cas.views.logout', name='logout'),
......
......@@ -21,10 +21,12 @@
</ul>
<ul class="nav navbar-nav navbar-right">
{% if user.is_authenticated %}
<li>
<a href="/search"><i class="fa fa-search fa-fw fa-lg"></i></a>
<li><a href="/accounts/student/{{ user.username }}">{{ user.username }}</a>
</li>
<li>
<a href="/accounts/settings/"><i class="fa fa-cog fa-fw"></i></a>
<a href="/accounts/settings/"><i class="fa fa-cog fa-fw fa-lg"></i></a>
</li>
<li><a href="{% url 'logout' %}">Logout</a>
</li>
......
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