1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-26 07:22:34 +00:00

move search related to seahub_extra

This commit is contained in:
lins05
2013-05-21 17:18:25 +08:00
parent 7f1ccc52e3
commit a81c1a583e
4 changed files with 1 additions and 274 deletions

View File

@@ -1,115 +0,0 @@
{% extends base_template %}
{% load seahub_tags avatar_tags i18n %}
{% load url from future %}
{% block right_panel %}
<form method="get" action="{% url 'search' %}" class="search-form" id="search-form">
<div class="input_and_submit">
<input class="search-input" name="q" placeholder="{% trans 'Search Files' %}" value="{{ keyword }}" />
<button type="submit" class="search-submit"><span class="icon-search"></span></button>
</div>
<span class="advanced-search vam icon-double-angle-{% if not search_repo and not search_ftypes %}down{% else %}up{% endif %}" title="{% trans "advanced" %}"></span>
</form>
<div id="search-results">
{% if not error %}
{% if not results %}
<p>{% trans 'No result found' %}</p>
{% else %}
<p class="tip">{% blocktrans count counter=total %}{{ total }} result{% plural %}{{ total }} results{% endblocktrans%}</p>
<ul id="search-results-list">
{% for file in results %}
<li class="search-results-item ovhd">
<img src="{{ MEDIA_URL }}img/file/{{ file.name|file_icon_filter }}" alt="{% trans "File"%}" class="fleft" />
<div class="main-con">
<a href="{% url 'repo' repo_id=file.repo.id %}" target="_blank">{{ file.repo.name }}</a>
<span></span>
<a href="{% url 'repo_view_file' repo_id=file.repo.id %}?p={{ file.fullpath|urlencode }}" target="_blank" title="{{ file.fullpath|slice:'1:'}}">{% if file.name_highlight %}{{ file.name_highlight|safe }}{% else %}{{ file.name }}{% endif %}</a>
<p>
{% if file.last_modified_by %}
{% avatar file.last_modified_by 20 %}
<a class="vam" href="{% url 'user_profile' file.last_modified_by|email2id %}">{{ file.last_modified_by|email2nickname }}</a>
{% endif %}
{% if file.last_modified %}
<span class="time vam">{{ file.last_modified|translate_seahub_time }}</span>
{% endif %}
</p>
{% if file.content_highlight %}
<p>{{ file.content_highlight|safe }}</p>
{% endif %}
</div>
</li>
{% endfor %}
</ul>
{% if total > per_page %}
<div id="paginator">
{% if current_page != 1 %}
<a href="?q={{ keyword|urlencode }}&page={{ prev_page }}&per_page={{ per_page }}">{% trans "Previous"%}</a>
{% endif %}
{% if has_more %}
<a href="?q={{ keyword|urlencode }}&page={{ next_page }}&per_page={{ per_page }}">{% trans "Next"%}</a>
{% endif %}
{% if current_page != 1 or has_more %}
|
{% endif %}
<span>{% trans "Per page: "%}</span>
{% if per_page == 25 %}
<span> 25 </span>
{% else %}
<a href="?q={{ keyword|urlencode }}&page={{ current_page }}&per_page=25" class="per-page">25</a>
{% endif %}
{% if per_page == 50 %}
<span> 50 </span>
{% else %}
<a href="?q={{ keyword|urlencode }}&page={{ current_page }}&per_page=50" class="per-page">50</a>
{% endif %}
{% if per_page == 100 %}
<span> 100 </span>
{% else %}
<a href="?q={{ keyword|urlencode }}&page={{ current_page }}&per_page=100" class="per-page">100</a>
{% endif %}
</div>
{% endif %}
{% endif %}
{% endif %}
</div>
{% endblock %}
{% block extra_script %}
<script type="text/javascript">
(function() {
var form = $('#search-form');
{% if search_repo or search_ftypes %}
form.append($('#advanced-search-form .search-scales').clone(true));
{% endif %}
form.find('.advanced-search').click(function() {
if (form.find('.search-scales').length == 0) {
form.append($('#advanced-search-form .search-scales').clone(true));
} else {
form.find('.search-scales').toggleClass('hide');
}
var it = $(this),
str = 'icon-double-angle-';
if (it.hasClass(str + 'down')) {
it.removeClass(str + 'down').addClass(str + 'up');
} else {
it.removeClass(str + 'up').addClass(str + 'down');
}
return false;
});
{% if custom_ftypes %}
var custom_ftypes = [];
{% for f in custom_ftypes %}
custom_ftypes.push("{{f}}");
{% endfor %}
var ftype_options = form.find('[name="ftype"]');
ftype_options.each(function() {
if (custom_ftypes.indexOf($(this).val()) != -1) {
$(this).attr('checked', true);
$(this).parent().addClass('checkbox-checked');
}
});
{% endif %}
})();
</script>
{% endblock %}

View File

@@ -6,7 +6,6 @@ from seahub.views import *
from seahub.views.file import view_file, view_history_file, view_trash_file,\
view_snapshot_file, file_edit
from seahub.views.repo import RepoView, RepoHistoryView
from seahub.views.search import search
from notifications.views import notification_list
from group.views import group_list
from seahub.views.wiki import personal_wiki, personal_wiki_pages, \
@@ -144,6 +143,7 @@ else:
)
if getattr(settings, 'ENABLE_FILE_SEARCH', False):
from seahub_extra.search.views import search
urlpatterns += patterns('',
url(r'^search/$', search, name='search'),
)

View File

@@ -1,79 +0,0 @@
from django.conf import settings
from seahub.utils import get_user_repos, get_file_last_modified
if getattr(settings, 'ENABLE_FILE_SEARCH', False):
from seafes import es_get_conn, es_search
es_conn = None
def search_file_by_name(request, keyword, suffixes, start, size):
owned_repos, shared_repos, groups_repos, pub_repo_list = get_user_repos(request.user)
# unify the repo.owner property
for repo in owned_repos:
repo.owner = request.user.username
for repo in shared_repos:
repo.owner = repo.user
for repo in pub_repo_list:
repo.owner = repo.user
pubrepo_id_map = {}
for repo in pub_repo_list:
# fix pub repo obj attr name mismatch in seafile/lib/repo.vala
repo.id = repo.repo_id
repo.name = repo.repo_name
pubrepo_id_map[repo.id] = repo
# remove duplicates from non-pub repos
nonpub_repo_list = []
for repo in owned_repos + shared_repos + groups_repos:
if repo.id not in nonpub_repo_list:
nonpub_repo_list.append(repo)
nonpub_repo_ids = [ repo.id for repo in nonpub_repo_list ]
global es_conn
if es_conn is None:
es_conn = es_get_conn()
files_found, total = es_search(es_conn, nonpub_repo_ids, keyword, suffixes, start, size)
if len(files_found) > 0:
# construt a (id, repo) hash table for fast lookup
repo_id_map = {}
for repo in nonpub_repo_list:
repo_id_map[repo.id] = repo
repo_id_map.update(pubrepo_id_map)
for f in files_found:
repo = repo_id_map.get(f['repo_id'].encode('UTF-8'), None)
if repo:
f['repo'] = repo
f['exists'] = True
f['last_modified_by'], f['last_modified'] = get_file_last_modified(f['repo_id'], f['fullpath'])
else:
f['exists'] = False
files_found = filter(lambda f: f['exists'], files_found)
return files_found, total
def search_repo_file_by_name(request, repo, keyword, suffixes, start, size):
global es_conn
if es_conn is None:
es_conn = es_get_conn()
files_found, total = es_search(es_conn, [repo.id], keyword, suffixes, start, size)
for f in files_found:
f['repo'] = repo
return files_found, total
else:
def search_file_by_name(*args):
pass
def search_repo_file_by_name(*args):
pass

View File

@@ -1,79 +0,0 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
from seaserv import get_repo
from seahub.auth.decorators import login_required
from seahub.utils import PREVIEW_FILEEXT
from seahub.utils.search import search_file_by_name, search_repo_file_by_name
@login_required
def search(request):
template = 'search_results.html'
error = False
keyword = request.GET.get('q', None)
if not keyword:
return render_to_response(template, {
'error': True,
}, context_instance=RequestContext(request))
# advanced search
search_repo = request.GET.get('search_repo', None) # val: 'all' or 'search_repo_id'
search_ftypes = request.GET.get('search_ftypes', None) # val: 'all' or 'custom'
custom_ftypes = request.GET.getlist('ftype') # types like 'Image', 'Video'... same in utils/file_types.py
input_fileexts = request.GET.get('input_fexts', '') # file extension input by the user
suffixes = None
if search_ftypes == 'custom':
suffixes = []
if len(custom_ftypes) > 0:
for ftp in custom_ftypes:
if PREVIEW_FILEEXT.has_key(ftp):
for ext in PREVIEW_FILEEXT[ftp]:
suffixes.append(ext)
if input_fileexts:
input_fexts = input_fileexts.split(',')
for i_ext in input_fexts:
i_ext = i_ext.strip()
if i_ext:
suffixes.append(i_ext)
current_page = int(request.GET.get('page', '1'))
per_page= int(request.GET.get('per_page', '25'))
start = (current_page - 1) * per_page
size = per_page
repo = None
if search_repo and search_repo != 'all':
repo_id = search_repo
repo = get_repo(repo_id)
if repo:
results, total = search_repo_file_by_name(request, repo, keyword, suffixes, start, size)
else:
results, total = [], 0
else:
results, total = search_file_by_name(request, keyword, suffixes, start, size)
if total > current_page * per_page:
has_more = True
else:
has_more = False
return render_to_response(template, {
'repo': repo,
'keyword': keyword,
'results': results,
'total': total,
'has_more': has_more,
'current_page': current_page,
'prev_page': current_page - 1,
'next_page': current_page + 1,
'per_page': per_page,
'search_repo': search_repo,
'search_ftypes': search_ftypes,
'custom_ftypes': custom_ftypes,
'input_fileexts': input_fileexts,
'error': error,
}, context_instance=RequestContext(request))