def clean_docs_from_session(documents, session, doc=None): # This method takes an original list of documents, then filters, sorts, and # paginates them from the given session object. filters = session.get('document-filters', []) documents, filter_form = filter_documents(documents, filters) sort_by = session.get('document-sort', 'filename') documents = sort_documents(documents, sort_by) #session['documents-list'] = documents page_num = session.get('document-page', 1) per_page = session.get('documents-per-page', 20) docs, num_pages, page = paginate_list(documents, page_num, per_page, doc) if page: session['document-page'] = page return docs, filter_form, num_pages
def get_word_page(request, dataset, analysis, number): request.session['word-page'] = int(number) ret_val = dict() words = get_word_list(request, dataset) num_per_page = request.session.get('words-per-page', 30) page = int(number) words, num_pages, _ = paginate_list(words, page, num_per_page) ret_val['words'] = [vars(AjaxWord(word.type)) for word in words] ret_val['num_pages'] = num_pages ret_val['page'] = page return HttpResponse(anyjson.dumps(ret_val))
def get_topic_page(request, dataset, analysis, number): request.session['topic-page'] = int(number) name_scheme_id = request.session['current_name_scheme_id'] ret_val = dict() topics = request.session.get('topics-list', None) if not topics: topics = Topic.objects.filter(analysis__name=analysis, analysis__dataset__name=dataset) num_per_page = request.session.get('topics-per-page', 20) page = int(number) topics, num_pages, _ = paginate_list(topics, page, num_per_page) ret_val['topics'] = [vars(AjaxTopic(topic, get_topic_name(topic, name_scheme_id))) for topic in topics] ret_val['num_pages'] = num_pages ret_val['page'] = page return HttpResponse(simplejson.dumps(ret_val))
def get_attribute_page(request, dataset, analysis, attribute, number): request.session['attribute-page'] = int(number) ret_val = dict() values = request.session.get('values-list', None) if not values: attribute = Attribute.objects.get(dataset__name=dataset, name=attribute) values = attribute.value_set.all() num_per_page = request.session.get('attributes-per-page', 20) page = int(number) values, num_pages, _ = paginate_list(values, page, num_per_page) ret_val['values'] = [vars(AjaxValue(val.value)) for val in values] ret_val['num_pages'] = num_pages ret_val['page'] = page return HttpResponse(anyjson.dumps(ret_val))
def get_context_data(self, request, **kwargs): context = super(AttributeView, self).get_context_data(request, **kwargs) dataset = context['dataset'] analysis = context['analysis'] attribute = kwargs['attribute'] try: value = kwargs['value'] except KeyError: value = '' context['highlight'] = 'attributes_tab' context['tab'] = 'attribute' context['attributes'] = dataset.attribute_set.all() if attribute: attribute = get_object_or_404(Attribute, dataset=dataset, name=attribute) prev_attribute = request.session.get('attribute-name', '') if prev_attribute != attribute.name: request.session['attribute-name'] = attribute.name request.session['attribute-page'] = 1 else: request.session['attribute-page'] = 1 attribute = context['attributes'][0] context['attribute'] = attribute values = attribute.value_set.all() page_num = request.session.get('attribute-page', 1) num_per_page = request.session.get('attributes-per-page', 20) values, num_pages, _ = paginate_list(values, page_num, num_per_page) context['num_pages'] = num_pages context['page_num'] = page_num context['values'] = [v.value for v in values] if value: value = get_object_or_404(Value, attribute=attribute, value=value) else: value = values[0] context['value'] = value context['view_description'] = "Attribute '{0}'".format(attribute.name) context['tabs'] = [attribute_info_tab(analysis, attribute, value, context['analysis_url'], context['attributes_url'])] context['breadcrumb'] = \ BreadCrumb().item(dataset).item(analysis).item(attribute).item(value) return context
def clean_topics_from_session(topics, session, extra_filters=[], topic=None): # This method takes an original list of topics, then filters, sorts, and # paginates them from the given session object. If topic is given, we find # the page for that topic filters = session.get('topic-filters', []) topics, filter_form = filter_topics(topics, filters) for filter in extra_filters: topics = filter.apply(topics) sort_by = session.get('topic-sort', 'name') topics = sort_topics(topics, sort_by, session) session['topics-list'] = topics page_num = session.get('topic-page', 1) per_page = session.get('topics-per-page', 20) topics, num_pages, page = paginate_list(topics, page_num, per_page, topic) if page: session['topic-page'] = page return topics, filter_form, num_pages
def get_context_data(self, request, **kwargs): context = super(WordView, self).get_context_data(request, **kwargs) dataset = context['dataset'] analysis = context['analysis'] word = kwargs['word'] context['highlight'] = 'words_tab' context['tab'] = 'word' words = get_word_list(request, dataset.name) num_per_page = request.session.get('words-per-page', 30) page_num = request.session.get('word-page', 1) words, num_pages, _ = paginate_list(words, page_num, num_per_page) context['words'] = words context['num_pages'] = num_pages context['page_num'] = page_num if word: word = Word.objects.get(dataset=dataset, type=word) else: word = context['words'][0] context['word'] = word context['breadcrumb'] = BreadCrumb().item(dataset).item(analysis).item(word) word_url = context['words_url'] + '/' + word.type word_base = request.session.get('word-find-base', '') context['word_find_form'] = WordFindForm(word_base) context['view_description'] = "Word '{0}'".format(word.type) context['tabs'] = [words_tab(analysis, word, word_url, context['IMAGES'])] return context