Esempio n. 1
0
def view_collection(request, collection_id):
    collection = get_object_or_404(Collection, id=collection_id)
    if request.user.is_authenticated and \
       collection.collector == request.user.collector:
        collection_list = request.user.collector.ordered_collections()
    elif collection.public is True:
        collection_list = Collection.objects.none()
    elif not request.user.is_authenticated:
        return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
    else:
        raise PermissionDenied

    items = collection.items.all().select_related('issue__series')
    base_url = urlresolvers.reverse('view_collection',
                                    kwargs={'collection_id': collection_id})
    vars = {
        'collection': collection,
        'collection_list': collection_list,
        'base_url': base_url
    }
    paginator = ResponsePaginator(items,
                                  vars=vars,
                                  per_page=DEFAULT_PER_PAGE,
                                  alpha=True)
    paginator.paginate(request)
    return render(request, COLLECTION_TEMPLATE, vars)
Esempio n. 2
0
def view_collection(request, collection_id):
    collection = get_object_or_404(Collection, id=collection_id)
    if request.user.is_authenticated and \
       collection.collector == request.user.collector:
        collection_list = request.user.collector.ordered_collections()
    elif collection.public is True:
        collection_list = Collection.objects.none()
    elif not request.user.is_authenticated:
        return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
    else:
        raise PermissionDenied

    items = collection.items.all().select_related('issue__series')
    base_url = urlresolvers.reverse('view_collection',
                                    kwargs={'collection_id': collection_id})
    needed_covers_url = urlresolvers.reverse("process_advanced_search") + \
                        "?target=issue&method=iexact&logic=False" \
                        "&cover_needed=on&in_collection=%s" \
                        "&in_selected_collection=on" \
                        "&order1=series&order2=date" % collection_id
    unindexed_issues_url = urlresolvers.reverse("process_advanced_search") + \
                           "?target=issue&method=iexact&logic=False" \
                           "&is_indexed=False&in_collection=%s" \
                           "&in_selected_collection=on" \
                           "&order1=series&order2=date" % collection_id
    vars = {
        'collection': collection,
        'collection_list': collection_list,
        'base_url': base_url,
        'needed_covers_url': needed_covers_url,
        'unindexed_issues_url': unindexed_issues_url
    }
    f = CollectionItemFilter(request.GET,
                             queryset=items,
                             collection=collection)
    vars['filter'] = f
    paginator = ResponsePaginator(f.qs,
                                  vars=vars,
                                  per_page=DEFAULT_PER_PAGE,
                                  alpha=True)
    paginator.paginate(request)
    get_copy = request.GET.copy()
    get_copy.pop('page', None)
    if get_copy:
        extra_query_string = '&%s' % get_copy.urlencode()
    else:
        extra_query_string = ''
    vars['extra_query_string'] = extra_query_string

    return render(request, COLLECTION_TEMPLATE, vars)
Esempio n. 3
0
    def __call__(self, request):
        self.request = request

        self.form = self.build_form()
        if 'search_object' in request.GET:
            if request.GET['search_object'] != "all":
                self.form.selected_facets = [u'facet_model_name_exact:%s' % \
                                              request.GET['search_object']]
        self.query = self.get_query()
        #TODO List of fields should be gathered
        # automatically from our SearchIndex classes
        fields = ['content', 'name' , 'title']
        sq, not_sq = parse_query_into_sq(self.query, fields)
        if sq:
            self.form.searchqueryset = self.form.searchqueryset.filter(sq)
        if not_sq:
            self.form.searchqueryset = self.form.searchqueryset.exclude(not_sq)

        self.results = self.get_results()
        self.sort = ''
        if len(self.form.selected_facets) == 1:
            if 'sort' in request.GET:
                self.sort = request.GET['sort']
                if self.form.selected_facets[0] in \
                  [u'facet_model_name_exact:publisher',
                   u'facet_model_name_exact:indicia publisher',
                   u'facet_model_name_exact:brand group',
                   u'facet_model_name_exact:brand emblem',
                   u'facet_model_name_exact:series']:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'year_began')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('year_began',
                                                             'sort_name')
                elif u'facet_model_name_exact:issue' in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'key_date',
                                                             'sort_code')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('key_date',
                                                             'sort_name',
                                                             'sort_code')
                elif u'facet_model_name_exact:story' in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'key_date',
                                                             'sort_code',
                                                             'sequence_number')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('key_date',
                                                             'sort_name',
                                                             'sort_code',
                                                             'sequence_number')
        self.query = urlencode({'q': self.query.encode('utf-8')})
        self.paginator = ResponsePaginator(self.results,
                                           view=self.create_response)
        return self.paginator.paginate(request)
Esempio n. 4
0
def view_collection_series(request, collection_id):
    collection = get_object_or_404(Collection, id=collection_id)
    if request.user.is_authenticated and \
       collection.collector == request.user.collector:
        collection_list = request.user.collector.ordered_collections()
    elif collection.public is True:
        collection_list = Collection.objects.none()
    elif not request.user.is_authenticated:
        return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
    else:
        raise PermissionDenied

    items = collection.items.all().select_related('issue__series')
    series_ids = items.values_list('issue__series__id', flat=True)\
                      .order_by('issue__series__id')\
                      .distinct()
    series_list = Series.objects.filter(id__in=series_ids)
    base_url = urlresolvers.reverse('view_collection_series',
                                    kwargs={'collection_id': collection_id})
    needed_covers_url = urlresolvers.reverse("process_advanced_search") + \
                        "?target=issue&method=iexact&logic=False" \
                        "&cover_needed=on&in_collection=%s" \
                        "&in_selected_collection=on" \
                        "&order1=series&order2=date" % collection_id
    unindexed_issues_url = urlresolvers.reverse("process_advanced_search") + \
                           "?target=issue&method=iexact&logic=False" \
                           "&is_indexed=False&in_collection=%s" \
                           "&in_selected_collection=on" \
                           "&order1=series&order2=date" % collection_id
    vars = {
        'collection': collection,
        'collection_list': collection_list,
        'base_url': base_url,
        'needed_covers_url': needed_covers_url,
        'unindexed_issues_url': unindexed_issues_url
    }
    paginator = ResponsePaginator(series_list,
                                  vars=vars,
                                  per_page=DEFAULT_PER_PAGE,
                                  alpha=True)
    paginator.paginate(request)
    return render(request, COLLECTION_SERIES_TEMPLATE, vars)
Esempio n. 5
0
def view_collection(request, collection_id):
    collection = get_object_or_404(Collection, id=collection_id)
    if request.user.is_authenticated() and \
      collection.collector == request.user.collector:
        collection_list = request.user.collector.ordered_collections()
    elif collection.public == True:
        collection_list = Collection.objects.none()
    elif not request.user.is_authenticated():
        return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
    else:
        raise PermissionDenied

    items = collection.items.all().select_related('issue__series')
    vars = {'collection': collection,
            'collection_list': collection_list}
    paginator = ResponsePaginator(items, template=COLLECTION_TEMPLATE,
                                  vars=vars, per_page=DEFAULT_PER_PAGE)
    alpha_paginator = AlphaPaginator(items, per_page=DEFAULT_PER_PAGE)
    paginator.vars['alpha_paginator'] = alpha_paginator
    return paginator.paginate(request)
def view_collection(request, collection_id):
    collection = get_object_or_404(Collection, id=collection_id)
    if request.user.is_authenticated() and \
      collection.collector == request.user.collector:
        collection_list = request.user.collector.ordered_collections()
    elif collection.public == True:
        collection_list = Collection.objects.none()
    elif not request.user.is_authenticated():
        return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
    else:
        raise PermissionDenied

    items = collection.items.all().select_related('issue__series')
    vars = {'collection': collection, 'collection_list': collection_list}
    paginator = ResponsePaginator(items,
                                  template=COLLECTION_TEMPLATE,
                                  vars=vars,
                                  per_page=DEFAULT_PER_PAGE)
    alpha_paginator = AlphaPaginator(items, per_page=DEFAULT_PER_PAGE)
    paginator.vars['alpha_paginator'] = alpha_paginator
    return paginator.paginate(request)
    def __call__(self, request, context=None):
        self.request = request

        self.form = self.build_form()
        if 'search_object' in request.GET:
            if request.GET['search_object'] != "all":
                self.form.selected_facets = [u'facet_model_name_exact:%s' %
                                             request.GET['search_object']]
        self.query = self.get_query().strip('\\')
        # TODO List of fields should be gathered
        # automatically from our SearchIndex classes
        fields = ['content', 'name', 'title']
        sq, not_sq = parse_query_into_sq(self.query, fields)
        if sq:
            self.form.searchqueryset = self.form.searchqueryset.filter(sq)
        if not_sq:
            self.form.searchqueryset = self.form.searchqueryset.exclude(not_sq)

        self.results = self.get_results()
        if 'date_facet' in request.GET:
            year = datetime.strptime(request.GET['date_facet'],
                                     '%Y-%m-%d %H:%M:%S')
            self.results = self.results.filter(date__gte=year)\
                               .filter(date__lt=year.replace(year=year.year+1))
            self.date_facet = request.GET['date_facet']
        else:
            self.date_facet = None
        if 'sort' in request.GET:
            self.sort = request.GET['sort']
        else:
            self.sort = ''
        if self.sort == 'country':
            self.results = self.results.order_by('country',
                                                 '-_score')
        elif self.sort == 'year':
            self.results = self.results.order_by('year',
                                                 '-_score')
        elif len(self.form.selected_facets) >= 1:
            if self.sort:
                if (u'facet_model_name_exact:publisher'
                    in self.form.selected_facets) or \
                  (u'facet_model_name_exact:indicia publisher'
                   in self.form.selected_facets) or \
                  (u'facet_model_name_exact:brand group'
                   in self.form.selected_facets) or \
                  (u'facet_model_name_exact:brand emblem'
                   in self.form.selected_facets) or \
                  (u'facet_model_name_exact:series'
                   in self.form.selected_facets):
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'year')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('year',
                                                             'sort_name')
                elif u'facet_model_name_exact:issue' \
                     in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'key_date',
                                                             'sort_code')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('key_date',
                                                             'sort_name',
                                                             'sort_code')
                elif u'facet_model_name_exact:story' \
                     in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'key_date',
                                                             'sort_code',
                                                             'sequence_number')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('key_date',
                                                             'sort_name',
                                                             'sort_code',
                                                             'sequence_number')

                elif self.form.selected_facets[0] in \
                    [u'facet_model_name_exact:creator',
                     u'facet_model_name_exact:creator membership',
                     u'facet_model_name_exact:creator artinfluence',
                     u'facet_model_name_exact:creator award',
                     u'facet_model_name_exact:creator noncomicwork']:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'year')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('year',
                                                             'sort_name')
        if self.query:
            self.query = urlencode({'q': self.query.encode('utf-8')})
        self.paginator = ResponsePaginator(self.results,
                                           vars=context)
        self.paginator.vars['page'] = self.paginator.paginate(request)
        return self.create_response()
class PaginatedFacetedSearchView(FacetedSearchView):
    def __call__(self, request, context=None):
        self.request = request

        self.form = self.build_form()
        if 'search_object' in request.GET:
            if request.GET['search_object'] != "all":
                self.form.selected_facets = [u'facet_model_name_exact:%s' %
                                             request.GET['search_object']]
        self.query = self.get_query().strip('\\')
        # TODO List of fields should be gathered
        # automatically from our SearchIndex classes
        fields = ['content', 'name', 'title']
        sq, not_sq = parse_query_into_sq(self.query, fields)
        if sq:
            self.form.searchqueryset = self.form.searchqueryset.filter(sq)
        if not_sq:
            self.form.searchqueryset = self.form.searchqueryset.exclude(not_sq)

        self.results = self.get_results()
        if 'date_facet' in request.GET:
            year = datetime.strptime(request.GET['date_facet'],
                                     '%Y-%m-%d %H:%M:%S')
            self.results = self.results.filter(date__gte=year)\
                               .filter(date__lt=year.replace(year=year.year+1))
            self.date_facet = request.GET['date_facet']
        else:
            self.date_facet = None
        if 'sort' in request.GET:
            self.sort = request.GET['sort']
        else:
            self.sort = ''
        if self.sort == 'country':
            self.results = self.results.order_by('country',
                                                 '-_score')
        elif self.sort == 'year':
            self.results = self.results.order_by('year',
                                                 '-_score')
        elif len(self.form.selected_facets) >= 1:
            if self.sort:
                if (u'facet_model_name_exact:publisher'
                    in self.form.selected_facets) or \
                  (u'facet_model_name_exact:indicia publisher'
                   in self.form.selected_facets) or \
                  (u'facet_model_name_exact:brand group'
                   in self.form.selected_facets) or \
                  (u'facet_model_name_exact:brand emblem'
                   in self.form.selected_facets) or \
                  (u'facet_model_name_exact:series'
                   in self.form.selected_facets):
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'year')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('year',
                                                             'sort_name')
                elif u'facet_model_name_exact:issue' \
                     in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'key_date',
                                                             'sort_code')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('key_date',
                                                             'sort_name',
                                                             'sort_code')
                elif u'facet_model_name_exact:story' \
                     in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'key_date',
                                                             'sort_code',
                                                             'sequence_number')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('key_date',
                                                             'sort_name',
                                                             'sort_code',
                                                             'sequence_number')

                elif self.form.selected_facets[0] in \
                    [u'facet_model_name_exact:creator',
                     u'facet_model_name_exact:creator membership',
                     u'facet_model_name_exact:creator artinfluence',
                     u'facet_model_name_exact:creator award',
                     u'facet_model_name_exact:creator noncomicwork']:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'year')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('year',
                                                             'sort_name')
        if self.query:
            self.query = urlencode({'q': self.query.encode('utf-8')})
        self.paginator = ResponsePaginator(self.results,
                                           vars=context)
        self.paginator.vars['page'] = self.paginator.paginate(request)
        return self.create_response()

    def extra_context(self):
        extra = super(PaginatedFacetedSearchView, self).extra_context()
        extra.update(self.paginator.vars)

        suggestion = self.form.get_suggestion()
        if suggestion == self.get_query().lower():
            suggestion = u''
        facet_page = ''
        is_model_selected = False
        is_country_selected = False
        is_language_selected = False
        is_publisher_selected = False
        is_feature_selected = False
        if self.date_facet:
            is_date_selected = True
            facet_page += '&date_facet=%s' % self.date_facet
        else:
            is_date_selected = False
        if self.form.selected_facets:
            for facet in self.form.selected_facets:
                facet_page += '&selected_facets=%s' % facet
                if u'facet_model_name_exact:' in facet:
                    is_model_selected = True
                elif u'country_exact:' in facet:
                    is_country_selected = True
                elif u'language_exact:' in facet:
                    is_language_selected = True
                elif u'publisher_exact:' in facet:
                    is_publisher_selected = True
                elif u'feature_exact:' in facet:
                    is_feature_selected = True
        extra.update({'suggestion': suggestion,
                      'facet_page': facet_page,
                      'is_date_selected': is_date_selected,
                      'is_model_selected': is_model_selected,
                      'is_country_selected': is_country_selected,
                      'is_language_selected': is_language_selected,
                      'is_publisher_selected': is_publisher_selected,
                      'is_feature_selected': is_feature_selected})
        if self.sort:
            extra.update({'sort': '&sort=%s' % self.sort})
        else:
            extra.update({'sort': ''})
        return extra
Esempio n. 9
0
    def __call__(self, request, context=None):
        self.request = request

        self.form = self.build_form()
        if 'search_object' in request.GET:
            if request.GET['search_object'] != "all":
                self.form.selected_facets = [
                    'facet_model_name_exact:%s' % request.GET['search_object']
                ]
        self.query = self.get_query().strip('\\')
        # TODO List of fields should be gathered
        # automatically from our SearchIndex classes
        fields = ['content', 'name', 'title']
        sq, not_sq = parse_query_into_sq(self.query, fields)
        if sq:
            self.form.searchqueryset = self.form.searchqueryset.filter(sq)
        if not_sq:
            self.form.searchqueryset = self.form.searchqueryset.exclude(not_sq)

        self.results = self.get_results()
        if 'date_facet' in request.GET:
            try:
                year = datetime.strptime(request.GET['date_facet'],
                                         '%Y-%m-%d %H:%M:%S')
                self.results = self.results.filter(date__gte=year)\
                                   .filter(date__lt=year.replace(year=year.year+1))
                self.date_facet = request.GET['date_facet']
            except ValueError:
                self.date_facet = None
        else:
            self.date_facet = None
        if 'sort' in request.GET:
            self.sort = request.GET['sort']
        else:
            self.sort = ''
        if self.sort == 'country':
            self.results = self.results.order_by('country', '-_score')
        elif self.sort == 'year':
            self.results = self.results.order_by('year', '-_score')
        elif len(self.form.selected_facets) >= 1:
            if self.sort:
                if ('facet_model_name_exact:publisher'
                    in self.form.selected_facets) or \
                  ('facet_model_name_exact:indicia publisher'
                   in self.form.selected_facets) or \
                  ('facet_model_name_exact:brand group'
                   in self.form.selected_facets) or \
                  ('facet_model_name_exact:brand emblem'
                   in self.form.selected_facets) or \
                  ('facet_model_name_exact:series'
                   in self.form.selected_facets) or \
                  ('facet_model_name_exact:character'
                   in self.form.selected_facets) or \
                  ('facet_model_name_exact:feature'
                   in self.form.selected_facets):
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'year')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'year', 'sort_name')
                elif 'facet_model_name_exact:issue' \
                     in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'key_date', 'sort_code')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'key_date', 'sort_name', 'sort_code')
                elif 'facet_model_name_exact:story' \
                     in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'key_date', 'sort_code',
                            'sequence_number')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'key_date', 'sort_name', 'sort_code',
                            'sequence_number')

                elif self.form.selected_facets[0] in \
                    ['facet_model_name_exact:creator',
                     'facet_model_name_exact:creator membership',
                     'facet_model_name_exact:creator artinfluence',
                     'facet_model_name_exact:creator award',
                     'facet_model_name_exact:creator noncomicwork']:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'year')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'year', 'sort_name')
        if self.query:
            self.query = urlencode({'q': self.query})
        self.paginator = ResponsePaginator(self.results, vars=context)
        self.paginator.vars['page'] = self.paginator.paginate(request)
        return self.create_response()
Esempio n. 10
0
class PaginatedFacetedSearchView(FacetedSearchView):
    def __call__(self, request, context=None):
        self.request = request

        self.form = self.build_form()
        if 'search_object' in request.GET:
            if request.GET['search_object'] != "all":
                self.form.selected_facets = [
                    'facet_model_name_exact:%s' % request.GET['search_object']
                ]
        self.query = self.get_query().strip('\\')
        # TODO List of fields should be gathered
        # automatically from our SearchIndex classes
        fields = ['content', 'name', 'title']
        sq, not_sq = parse_query_into_sq(self.query, fields)
        if sq:
            self.form.searchqueryset = self.form.searchqueryset.filter(sq)
        if not_sq:
            self.form.searchqueryset = self.form.searchqueryset.exclude(not_sq)

        self.results = self.get_results()
        if 'date_facet' in request.GET:
            try:
                year = datetime.strptime(request.GET['date_facet'],
                                         '%Y-%m-%d %H:%M:%S')
                self.results = self.results.filter(date__gte=year)\
                                   .filter(date__lt=year.replace(year=year.year+1))
                self.date_facet = request.GET['date_facet']
            except ValueError:
                self.date_facet = None
        else:
            self.date_facet = None
        if 'sort' in request.GET:
            self.sort = request.GET['sort']
        else:
            self.sort = ''
        if self.sort == 'country':
            self.results = self.results.order_by('country', '-_score')
        elif self.sort == 'year':
            self.results = self.results.order_by('year', '-_score')
        elif len(self.form.selected_facets) >= 1:
            if self.sort:
                if ('facet_model_name_exact:publisher'
                    in self.form.selected_facets) or \
                  ('facet_model_name_exact:indicia publisher'
                   in self.form.selected_facets) or \
                  ('facet_model_name_exact:brand group'
                   in self.form.selected_facets) or \
                  ('facet_model_name_exact:brand emblem'
                   in self.form.selected_facets) or \
                  ('facet_model_name_exact:series'
                   in self.form.selected_facets) or \
                  ('facet_model_name_exact:character'
                   in self.form.selected_facets) or \
                  ('facet_model_name_exact:feature'
                   in self.form.selected_facets):
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'year')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'year', 'sort_name')
                elif 'facet_model_name_exact:issue' \
                     in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'key_date', 'sort_code')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'key_date', 'sort_name', 'sort_code')
                elif 'facet_model_name_exact:story' \
                     in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'key_date', 'sort_code',
                            'sequence_number')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'key_date', 'sort_name', 'sort_code',
                            'sequence_number')

                elif self.form.selected_facets[0] in \
                    ['facet_model_name_exact:creator',
                     'facet_model_name_exact:creator membership',
                     'facet_model_name_exact:creator artinfluence',
                     'facet_model_name_exact:creator award',
                     'facet_model_name_exact:creator noncomicwork']:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'year')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'year', 'sort_name')
        if self.query:
            self.query = urlencode({'q': self.query})
        self.paginator = ResponsePaginator(self.results, vars=context)
        self.paginator.vars['page'] = self.paginator.paginate(request)
        return self.create_response()

    def extra_context(self):
        extra = super(PaginatedFacetedSearchView, self).extra_context()
        extra.update(self.paginator.vars)

        suggestion = self.form.get_suggestion()
        if suggestion == self.get_query().lower():
            suggestion = ''
        facet_page = ''
        is_model_selected = False
        is_country_selected = False
        is_language_selected = False
        is_publisher_selected = False
        is_feature_selected = False
        if self.date_facet:
            is_date_selected = True
            facet_page += '&date_facet=%s' % self.date_facet
        else:
            is_date_selected = False
        if self.form.selected_facets:
            for facet in self.form.selected_facets:
                facet_page += '&selected_facets=%s' % facet
                if 'facet_model_name_exact:' in facet:
                    is_model_selected = True
                elif 'country_exact:' in facet:
                    is_country_selected = True
                elif 'language_exact:' in facet:
                    is_language_selected = True
                elif 'publisher_exact:' in facet:
                    is_publisher_selected = True
                elif 'feature_exact:' in facet:
                    is_feature_selected = True
        extra.update({
            'suggestion': suggestion,
            'facet_page': facet_page,
            'is_date_selected': is_date_selected,
            'is_model_selected': is_model_selected,
            'is_country_selected': is_country_selected,
            'is_language_selected': is_language_selected,
            'is_publisher_selected': is_publisher_selected,
            'is_feature_selected': is_feature_selected
        })
        if self.sort:
            extra.update({'sort': '&sort=%s' % self.sort})
        else:
            extra.update({'sort': ''})
        return extra
    def __call__(self, request, context=None):
        self.request = request

        self.form = self.build_form()
        if 'search_object' in request.GET:
            if request.GET['search_object'] != "all":
                self.form.selected_facets = [u'facet_model_name_exact:%s' % \
                                              request.GET['search_object']]
        self.query = self.get_query().strip('\\')
        #TODO List of fields should be gathered
        # automatically from our SearchIndex classes
        fields = ['content', 'name', 'title']
        sq, not_sq = parse_query_into_sq(self.query, fields)
        if sq:
            self.form.searchqueryset = self.form.searchqueryset.filter(sq)
        if not_sq:
            self.form.searchqueryset = self.form.searchqueryset.exclude(not_sq)

        self.results = self.get_results()
        if 'sort' in request.GET:
            self.sort = request.GET['sort']
        else:
            self.sort = ''
        if self.sort == 'country':
            self.results = self.results.order_by('country', '-_score')
        elif self.sort == 'year':
            self.results = self.results.order_by('year', '-_score')
        elif len(self.form.selected_facets) == 1:
            if self.sort:
                if self.form.selected_facets[0] in \
                  [u'facet_model_name_exact:publisher',
                   u'facet_model_name_exact:indicia publisher',
                   u'facet_model_name_exact:brand group',
                   u'facet_model_name_exact:brand emblem',
                   u'facet_model_name_exact:series']:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'year')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'year', 'sort_name')
                elif u'facet_model_name_exact:issue' in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'key_date', 'sort_code')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'key_date', 'sort_name', 'sort_code')
                elif u'facet_model_name_exact:story' in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'key_date', 'sort_code',
                            'sequence_number')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'key_date', 'sort_name', 'sort_code',
                            'sequence_number')
        if self.query:
            self.query = urlencode({'q': self.query.encode('utf-8')})
        self.paginator = ResponsePaginator(self.results,
                                           view=self.create_response,
                                           vars=context)
        return self.paginator.paginate(request)
Esempio n. 12
0
class PaginatedFacetedSearchView(FacetedSearchView):
    def __call__(self, request, context=None):
        self.request = request

        self.form = self.build_form()
        if 'search_object' in request.GET:
            if request.GET['search_object'] != "all":
                self.form.selected_facets = [u'facet_model_name_exact:%s' % \
                                              request.GET['search_object']]
        self.query = self.get_query().strip('\\')
        #TODO List of fields should be gathered
        # automatically from our SearchIndex classes
        fields = ['content', 'name', 'title']
        sq, not_sq = parse_query_into_sq(self.query, fields)
        if sq:
            self.form.searchqueryset = self.form.searchqueryset.filter(sq)
        if not_sq:
            self.form.searchqueryset = self.form.searchqueryset.exclude(not_sq)

        self.results = self.get_results()
        if 'sort' in request.GET:
            self.sort = request.GET['sort']
        else:
            self.sort = ''
        if self.sort == 'country':
            self.results = self.results.order_by('country', '-_score')
        elif self.sort == 'year':
            self.results = self.results.order_by('year', '-_score')
        elif len(self.form.selected_facets) >= 1:
            if self.sort:
                if (u'facet_model_name_exact:publisher' \
                  in self.form.selected_facets) or \
                  (u'facet_model_name_exact:indicia publisher'
                  in self.form.selected_facets) or \
                  (u'facet_model_name_exact:brand group'
                  in self.form.selected_facets) or \
                  (u'facet_model_name_exact:brand emblem'
                  in self.form.selected_facets) or \
                  (u'facet_model_name_exact:series'
                  in self.form.selected_facets):
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'year')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'year', 'sort_name')
                elif u'facet_model_name_exact:issue' in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'key_date', 'sort_code')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'key_date', 'sort_name', 'sort_code')
                elif u'facet_model_name_exact:story' in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by(
                            'sort_name', 'key_date', 'sort_code',
                            'sequence_number')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by(
                            'key_date', 'sort_name', 'sort_code',
                            'sequence_number')
        if self.query:
            self.query = urlencode({'q': self.query.encode('utf-8')})
        self.paginator = ResponsePaginator(self.results,
                                           view=self.create_response,
                                           vars=context)
        return self.paginator.paginate(request)

    def extra_context(self):
        extra = super(PaginatedFacetedSearchView, self).extra_context()
        extra.update(self.paginator.vars)

        suggestion = self.form.get_suggestion()
        if suggestion == self.get_query().lower():
            suggestion = u''
        facet_page = ''
        is_model_selected = False
        is_country_selected = False
        if self.form.selected_facets:
            for facet in self.form.selected_facets:
                facet_page += '&selected_facets=%s' % facet
                if u'facet_model_name_exact:' in facet:
                    is_model_selected = True
                elif u'country_exact:' in facet:
                    is_country_selected = True
        extra.update({
            'suggestion': suggestion,
            'facet_page': facet_page,
            'is_model_selected': is_model_selected,
            'is_country_selected': is_country_selected
        })
        if self.sort:
            extra.update({'sort': '&sort=%s' % self.sort})
        else:
            extra.update({'sort': ''})
        return extra
Esempio n. 13
0
class PaginatedFacetedSearchView(FacetedSearchView):
    def __call__(self, request):
        self.request = request

        self.form = self.build_form()
        if 'search_object' in request.GET:
            if request.GET['search_object'] != "all":
                self.form.selected_facets = [u'facet_model_name_exact:%s' % \
                                              request.GET['search_object']]
        self.query = self.get_query()
        #TODO List of fields should be gathered
        # automatically from our SearchIndex classes
        fields = ['content', 'name' , 'title']
        sq, not_sq = parse_query_into_sq(self.query, fields)
        if sq:
            self.form.searchqueryset = self.form.searchqueryset.filter(sq)
        if not_sq:
            self.form.searchqueryset = self.form.searchqueryset.exclude(not_sq)

        self.results = self.get_results()
        self.sort = ''
        if len(self.form.selected_facets) == 1:
            if 'sort' in request.GET:
                self.sort = request.GET['sort']
                if self.form.selected_facets[0] in \
                  [u'facet_model_name_exact:publisher',
                   u'facet_model_name_exact:indicia publisher',
                   u'facet_model_name_exact:brand group',
                   u'facet_model_name_exact:brand emblem',
                   u'facet_model_name_exact:series']:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'year_began')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('year_began',
                                                             'sort_name')
                elif u'facet_model_name_exact:issue' in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'key_date',
                                                             'sort_code')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('key_date',
                                                             'sort_name',
                                                             'sort_code')
                elif u'facet_model_name_exact:story' in self.form.selected_facets:
                    if request.GET['sort'] == 'alpha':
                        self.results = self.results.order_by('sort_name',
                                                             'key_date',
                                                             'sort_code',
                                                             'sequence_number')
                    elif request.GET['sort'] == 'chrono':
                        self.results = self.results.order_by('key_date',
                                                             'sort_name',
                                                             'sort_code',
                                                             'sequence_number')
        self.query = urlencode({'q': self.query.encode('utf-8')})
        self.paginator = ResponsePaginator(self.results,
                                           view=self.create_response)
        return self.paginator.paginate(request)

    def extra_context(self):
        extra = super(PaginatedFacetedSearchView, self).extra_context()
        extra.update(self.paginator.vars)

        suggestion = self.form.get_suggestion()
        if suggestion == self.query.lower():
            suggestion = u''
        facet_page = ''
        if self.form.selected_facets:
            for facet in self.form.selected_facets:
                facet_page += '&selected_facets=%s' % facet
        extra.update({'suggestion': suggestion,
                     'facet_page': facet_page})
        if self.sort:
            extra.update({'sort': '&sort=%s' % self.sort})
        else:
            extra.update({'sort': ''})
        return extra