Commits

Wilson Xu committed 88ba36d

Tweaked search page.

  • Participants
  • Parent commits 165c55c

Comments (0)

Files changed (3)

fbone/templates/layout.html

                         </ul>
                         </li>
                     </ul>
-                    {% elif request.url.split('/')|last != 'login' %}
+                    {% elif login_form is defined %}
                     <form class='pull-right' method='POST' action='{{ url_for('frontend.login') }}'>
                         {{ login_form.hidden_tag() }}
                         {{ login_form.next }}

fbone/templates/search.html

 
 {% extends 'layout.html' %}
 
-{% block title %}
-{% if keywords %}
-    {% trans keywords=keywords %}Search results for "{{ keywords }}"{% endtrans %}
-{% else %}
-    {{ _('Search results') }}
-{% endif %}
-{% endblock %}
-
-{% block search %}{% endblock %}
-{% block learn_more %}{% endblock %}
-
-{% block page_title %}
-<form id='search' action="{{ url_for('frontend.search') }}" method='GET'>
-    <input type='text' name='keywords' value="{{ keywords|default('') }}" placeholder="{{ _('Search...') }}" />
-    <input type='submit' value="{{ _('Search') }}" />
-</form>
 
 {% if keywords %}
-    <h2>{% trans keywords=keywords %}Search results for "{{ keywords }}"{% endtrans %}</h2>
+    {% set page_title = _('Search results for "%(keywords)s"', keywords=keywords) %}
 {% else %}
-    <h2>{{ _('Please give me some keywords.') }}</h2>
+    {% set page_title = _('Keywords needed!') %}
 {% endif %}
-{% endblock %}
 
 {% block body %}
-{% if keywords %}
     {% if pagination and pagination.pages > 0 %}
         <p>{% trans total=pagination.total, keywords=keywords %}<strong>{{ total }}</strong> found for your search "<strong>{{ keywords }}</strong>".{% endtrans %}</p>
         {{ render_users(pagination.items) }}
-        {{ render_pagination(pagination=pagination, endpoint='frontend.search') }}
+        {{ render_pagination(pagination, 'frontend.search') }}
     {% else %}
         <p>{% trans keywords=keywords %}Sorry, Nothing found for your search "<strong>{{ keywords }}</strong>".{% endtrans %}</p>
     {% trans %}
     </ul>
     {% endtrans %}
     {% endif %}
-{% endif %}
 {% endblock %}

fbone/views/frontend.py

 
 @frontend.route('/')
 def index():
-    login_form= LoginForm(next=request.args.get('next'))
+    login_form = None
+    if not current_user.is_authenticated():
+        login_form= LoginForm(next=request.args.get('next'))
     page = int(request.args.get('page', 1))
     pagination = User.query.paginate(page=page, per_page=1)
     return render_template('index.html', pagination=pagination, login_form=login_form,
 
 @frontend.route('/search')
 def search():
+    if not current_user.is_authenticated():
+        login_form= LoginForm(next=request.args.get('next'))
     keywords = request.args.get('keywords', '').strip()
     pagination = None
     if keywords:
         page = int(request.args.get('page', 1))
-        pagination = User.search(keywords).paginate(page, 10)
+        pagination = User.search(keywords).paginate(page, 1)
+    else:
+        flash('Please input keyword(s)', 'error')
     return render_template('search.html', pagination=pagination,
-                           keywords=keywords)
+                           keywords=keywords, login_form=login_form)
 
 
 @frontend.route('/login', methods=['GET', 'POST'])