mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-30 06:25:28 -04:00
Initial implementation
This commit is contained in:
parent
7bc13204e6
commit
b1f70b2197
7 changed files with 73 additions and 4 deletions
|
@ -14,6 +14,9 @@ from django import forms
|
|||
from core.models import Snapshot, Tag
|
||||
from core.forms import AddLinkForm, TagField
|
||||
|
||||
from core.utils import get_icons
|
||||
from core.mixins import SearchResultsAdminMixin
|
||||
|
||||
from index.html import snapshot_icons
|
||||
from util import htmldecode, urldecode, ansi_to_html
|
||||
from logging_util import printable_filesize
|
||||
|
@ -82,7 +85,7 @@ class SnapshotAdminForm(forms.ModelForm):
|
|||
return instance
|
||||
|
||||
|
||||
class SnapshotAdmin(admin.ModelAdmin):
|
||||
class SnapshotAdmin(SearchResultsAdminMixin, admin.ModelAdmin):
|
||||
list_display = ('added', 'title_str', 'url_str', 'files', 'size')
|
||||
sort_fields = ('title_str', 'url_str', 'added')
|
||||
readonly_fields = ('id', 'url', 'timestamp', 'num_outputs', 'is_archived', 'url_hash', 'added', 'updated')
|
||||
|
|
21
archivebox/core/mixins.py
Normal file
21
archivebox/core/mixins.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from django.db.models import Q, Case, When, Value, IntegerField
|
||||
|
||||
from archivebox.search import search_index
|
||||
|
||||
class SearchResultsAdminMixin(object):
|
||||
def get_search_results(self, request, queryset, search_term):
|
||||
''' Show exact match for title and slug at top of admin search results.
|
||||
'''
|
||||
qs, use_distinct = \
|
||||
super(SearchResultsAdminMixin, self).get_search_results(
|
||||
request, queryset, search_term)
|
||||
|
||||
search_term = search_term.strip()
|
||||
if not search_term:
|
||||
return qs, use_distinct
|
||||
|
||||
snapshot_ids = search_index(search_term)
|
||||
qsearch = queryset.filter(id__in=snapshot_ids)
|
||||
qs |= qsearch
|
||||
|
||||
return qs, use_distinct
|
Loading…
Add table
Add a link
Reference in a new issue