def test_paginate_no_negative_page_num(self): self._watch_project(self.project) logs = list(self.user.get_recent_log_ids()) size = 10 page = -1 total = len(logs) with assert_raises(HTTPError): paginate(self.user.get_recent_log_ids(), total, page, size)
def test_paginate_not_go_beyond_limit(self): self._watch_project(self.project) logs = list(self.user.get_recent_log_ids()) size = 10 total = len(logs) pages_num = math.ceil(total / float(size)) page = pages_num with assert_raises(HTTPError): paginate(self.user.get_recent_log_ids(), total, page, size)
def _get_logs(node, count, auth, link=None, page=0): """ :param Node node: :param int count: :param auth: :return list: List of serialized logs, boolean: if there are more logs """ logs = [] total = 0 for log in reversed(node.logs): # A number of errors due to database inconsistency can arise here. The # log can be None; its `node__logged` back-ref can be empty, and the # 0th logged node can be None. Need to make sure that log is not None if log: log_node = log.resolve_node(node) if log.can_view(node, auth): total += 1 anonymous = has_anonymous_link(log_node, auth) logs.append(serialize_log(log, anonymous)) else: logger.warn('Log on node {} is None'.format(node._id)) paginated_logs, pages = paginate(logs, total, page, count) return list(paginated_logs), total, pages
def test_paginate_helper(self): self._watch_project(self.project) logs = list(self.user.get_recent_log_ids()) size = 10 page = 0 total = len(logs) paginated_logs, pages = paginate(self.user.get_recent_log_ids(), total, page, size) page_num = math.ceil(total / float(size)) assert_equal(len(list(paginated_logs)), total) assert_equal(page_num, pages)
def test_paginate_helper(self): self._watch_project(self.project) logs = list(self.user.get_recent_log_ids()) size = 10 page = 0 total = len(logs) paginated_logs, pages = paginate( self.user.get_recent_log_ids(), total, page, size) page_num = math.ceil(total / float(size)) assert_equal(len(list(paginated_logs)), total) assert_equal(page_num, pages)
def list_user(request, user_id, is_open=True, tag_slug=None): if request.user.is_authenticated(): if request.permissions.is_company_admin: return HttpResponseRedirect(reverse("company_admin_jobs", args=[request.company.id])) if request.user in request.company.get_users(): return HttpResponseRedirect(reverse("mycompany_jobs")) user = get_object_or_404(User, id=user_id) profile = helpers.get_profile(user) _jobs = Job.objects.filter(user__id=user_id, is_open=is_open) if tag_slug: _jobs = _jobs.filter(tags__slug=tag_slug) jobs = paginate(request, _jobs) return render_to_response("jobs/list_public.html", RequestContext(request, locals()))