[GrandComicsDatabase/gcd-django] column sorting for credit results (#495)

1 view
Skip to first unread message

jochengcd

unread,
Jun 27, 2021, 5:09:16 AMJun 27
to GrandComicsDatabase/gcd-django, Subscribed

Hmm, we use elasticsearch for better performance of the credit results in the dropdown. But then, these searchquerysets cannot be sorted and displayed by django-tables without further effort. Have to see, if we keep haystack or go more directly with django-elasticsearch-dsl.

For record keeping, here is StoryMatchedSearchTable that we could add to apps/gcd/models/story.py for that purpose

class StoryMatchedSearchTable(StoryTable):
matched_search = tables.Column(accessor='script', orderable=False)

class Meta:
    model = Story
    fields = ('matched_search',)
    attrs = {'th': {'class': "non_visited"}}

def __init__(self, *args, **kwargs):
    self.which_credit = kwargs.pop('which_credit')
    super(StoryMatchedSearchTable, self).__init__(*args, **kwargs)

def render_matched_search(self, record):
    from apps.gcd.templatetags.credits import show_credit
    display_match = show_credit(record, self.which_credit)
    return mark_safe('<div class="sortable_listing">'
                     '<dl class="credits">%s</dl></div>' % display_match)

def value_matched_search(self, record):
    return str(value)

and the call from apps/gcd/views/seach.py in generic_by_name

            if credit in ['script', 'pencils', 'inks', 'colors',
                          'letters']:
                things = Story.objects.filter(
                  id__in=things.values_list('id', flat=True))\
                    .select_related('issue__series__publisher__country',
                                    'type').prefetch_related('credits')
                table = StoryMatchedSearchTable(
                  things, attrs={'class': 'sortable_listing'},
                  template_name='gcd/bits/sortable_table.html', 
                  order_by=('issue'), which_credit=credit)

and the diff for default.css
-.listing dl.credits dt {
+.listing dl.credits dt, .sortable_listing dl.credits dt {
float: left;
clear: both;
padding-right: 0.25em;
}

-.listing dl.credits dd {
+.listing dl.credits dd, .sortable_listing dl.credits dd {
margin: 0;
}


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Reply all
Reply to author
Forward
0 new messages