def notes(request, obj_type=None): """ Display all repositories or accounts with a note """ if obj_type is None: return redirect(notes, obj_type='repositories') model = obj_type_from_url(obj_type) sort_key = request.GET.get('sort_by', '-note') if model == 'account': sort = get_account_sort(sort_key, default=None) per_page = settings.ACCOUNTS_PER_PAGE else: sort = get_repository_sort(sort_key, default=None) per_page = settings.REPOSITORIES_PER_PAGE if not sort.get('db_sort'): sort = prepare_sort(sort_key, dict(note='modified'), default='note', default_reverse=True) all_notes = _get_last_user_notes(request.user, only=model, sort_by=sort['db_sort'])[model] page = paginate(request, all_notes, per_page) context = dict( page = page, obj_type = obj_type, sort = dict( key = sort['key'], reverse = sort['reverse'], ), ) return render(request, 'dashboard/notes.html', context)
def get_order(self): """ Get the correct order for the current search """ order_map_type = 'solr' if self.query else 'db' result = prepare_sort(self.query_order, self.order_map[order_map_type], self.filter.default_sort, False) if not result['key']: result['key'] = '' return result
def get_account_sort(key, default='name', default_reverse=False, disabled=None): """ Return needed informations about sorting accounts """ _account_sort_map = account_sort_map if disabled: _account_sort_map = copy(account_sort_map) for entry in disabled: _account_sort_map.pop(entry, None) return prepare_sort(key, _account_sort_map, default, default_reverse)
def get_sort(self): """ Prepare (with validiti check) sorting key """ if not hasattr(self.request, "_haystack_sort"): self.request._haystack_sort = None if self.sort_map: sort_key = self.request.GET.get("sort_by", None) self._haystack_sort = prepare_sort( key=sort_key, sort_map=self.sort_map, default=None, default_reverse=False ) return self._haystack_sort
def get_sort(self): """ Prepare (with validiti check) sorting key """ if not hasattr(self.request, '_haystack_sort'): self.request._haystack_sort = None if self.sort_map: sort_key = self.request.GET.get('sort_by', None) self._haystack_sort = prepare_sort(key=sort_key, sort_map=self.sort_map, default=None, default_reverse=False) return self._haystack_sort
def get_repository_sort(key, allow_owner=True, default='name', default_reverse=False, disabled=None): """ Return needed informations about sorting repositories """ _repository_sort_map = copy(repository_sort_map) if not allow_owner: del _repository_sort_map['owner'] if disabled: for entry in disabled: _repository_sort_map.pop(entry, None) return prepare_sort(key, _repository_sort_map, default, default_reverse)
def get_order(self): """ Get the correct order for the current search """ order_map_type = 'solr' if self.query else 'db' result = prepare_sort( self.query_order, self.order_map[order_map_type], self.filter.default_sort, False ) if not result['key']: result['key'] = '' return result
def notes(request, obj_type=None): """ Display all repositories or accounts with a note """ if obj_type is None: return redirect(notes, obj_type='repositories') model = obj_type_from_url(obj_type) sort_key = request.GET.get('sort_by', '-note') if model == 'account': sort = get_account_sort(sort_key, default=None) per_page = settings.ACCOUNTS_PER_PAGE else: sort = get_repository_sort(sort_key, default=None) per_page = settings.REPOSITORIES_PER_PAGE if not sort.get('db_sort'): sort = prepare_sort(sort_key, dict(note='modified'), default='note', default_reverse=True) all_notes = _get_last_user_notes(request.user, only=model, sort_by=sort['db_sort'])[model] page = paginate(request, all_notes, per_page) context = dict( page=page, obj_type=obj_type, sort=dict( key=sort['key'], reverse=sort['reverse'], ), ) return render(request, 'dashboard/notes.html', context)