def index(request): lists = [ ml for ml in MailingList.objects.all() if not settings.FILTER_VHOST or show_mlist(ml, request) ] for mlist in lists: if not mlist.is_private: mlist.can_view = True else: if is_mlist_authorized(request, mlist): mlist.can_view = True else: mlist.can_view = False if mlist.can_view: mlist.recent_threads_count = mlist.recent_threads.count() else: mlist.recent_threads_count = None # sorting sort_mode = request.GET.get('sort') if not sort_mode: sort_mode = "popular" if sort_mode == "name": lists.sort(key=lambda l: l.name) elif sort_mode == "active": # Don't show private lists when sorted by activity, to avoid disclosing # info about the private list's activity lists = [l for l in lists if l.is_private == False] lists.sort(key=lambda l: l.recent_threads_count, reverse=True) elif sort_mode == "popular": # Don't show private lists when sorted by popularity, to avoid disclosing # info about the private list's popularity lists = [l for l in lists if l.is_private == False] lists.sort(key=lambda l: l.recent_participants_count, reverse=True) elif sort_mode == "creation": lists.sort(key=lambda l: l.created_at, reverse=True) else: return HttpResponse("Wrong search parameter", content_type="text/plain", status=500) context = { 'view_name': 'all_lists', 'all_lists': lists, 'sort_mode': sort_mode, } return render(request, "hyperkitty/index.html", context)
def index(request): lists = [ ml for ml in MailingList.objects.all() if not settings.FILTER_VHOST or show_mlist(ml, request) ] for mlist in lists: if not mlist.is_private: mlist.can_view = True else: if is_mlist_authorized(request, mlist): mlist.can_view = True else: mlist.can_view = False if mlist.can_view: mlist.recent_threads_count = mlist.recent_threads.count() else: mlist.recent_threads_count = None # sorting sort_mode = request.GET.get('sort') if not sort_mode: sort_mode = "popular" if sort_mode == "name": lists.sort(key=lambda l: l.name) elif sort_mode == "active": # Don't show private lists when sorted by activity, to avoid disclosing # info about the private list's activity lists = [ l for l in lists if l.is_private == False ] lists.sort(key=lambda l: l.recent_threads_count, reverse=True) elif sort_mode == "popular": # Don't show private lists when sorted by popularity, to avoid disclosing # info about the private list's popularity lists = [ l for l in lists if l.is_private == False ] lists.sort(key=lambda l: l.recent_participants_count, reverse=True) elif sort_mode == "creation": lists.sort(key=lambda l: l.created_at, reverse=True) else: return HttpResponse("Wrong search parameter", content_type="text/plain", status=500) context = { 'view_name': 'all_lists', 'all_lists': lists, 'sort_mode': sort_mode, } return render(request, "hyperkitty/index.html", context)
def index(request): now = datetime.datetime.now() store = get_store(request) lists = [ l for l in store.get_lists() if not settings.FILTER_VHOST or show_mlist(l, request) ] initials = set() for mlist in lists: if mlist.archive_policy != ArchivePolicy.private: mlist.is_private = False mlist.can_view = True else: mlist.is_private = True if is_mlist_authorized(request, mlist): mlist.can_view = True else: mlist.can_view = False if mlist.created_at and \ now - mlist.created_at <= datetime.timedelta(days=30): mlist.is_new = True else: mlist.is_new = False initials.add(mlist.name[0]) # sorting sort_mode = request.GET.get('sort') if sort_mode == "active": lists.sort(key=lambda l: l.recent_threads_count, reverse=True) elif sort_mode == "popular": lists.sort(key=lambda l: l.recent_participants_count, reverse=True) elif sort_mode == "creation": lists.sort(key=lambda l: l.created_at, reverse=True) else: sort_mode = None context = { 'view_name': 'all_lists', 'all_lists': lists, 'initials': sorted(list(initials)), 'sort_mode': sort_mode, } return render(request, "index.html", context)
def index(request): mlists = [ml for ml in MailingList.objects.all() if not settings.FILTER_VHOST or show_mlist(ml, request)] # Sorting sort_mode = request.GET.get("sort") if not sort_mode: sort_mode = "popular" if sort_mode == "name": mlists.sort(key=lambda ml: ml.name) elif sort_mode == "active": # Don't show private lists when sorted by activity, to avoid disclosing # info about the private list's activity mlists = [ml for ml in mlists if ml.is_private == False] mlists.sort(key=lambda l: l.recent_threads_count, reverse=True) elif sort_mode == "popular": # Don't show private lists when sorted by popularity, to avoid disclosing # info about the private list's popularity mlists = [l for l in mlists if l.is_private == False] mlists.sort(key=lambda l: l.recent_participants_count, reverse=True) elif sort_mode == "creation": mlists.sort(key=lambda l: l.created_at, reverse=True) else: return HttpResponse("Wrong search parameter", content_type="text/plain", status=500) mlists = paginate(mlists, request.GET.get("page"), results_per_page=request.GET.get("count")) # Permissions for mlist in mlists: if not mlist.is_private: mlist.can_view = True else: if is_mlist_authorized(request, mlist): mlist.can_view = True else: mlist.can_view = False context = {"view_name": "all_lists", "all_lists": mlists, "sort_mode": sort_mode} return render(request, "hyperkitty/index.html", context)
def _do_test(self, listdomain, vhost, expected): mlist = FakeKSList("test@%s" % listdomain) req = HttpRequest() req.META["HTTP_HOST"] = vhost self.assertEqual(show_mlist(mlist, req), expected)
def _do_test(self, listdomain, vhost, expected): mlist = MailingList.objects.get_or_create(name="test@{}".format(listdomain))[0] req = HttpRequest() req.META["HTTP_HOST"] = vhost self.assertEqual(show_mlist(mlist, req), expected)
def _do_test(self, listdomain, vhost, expected): mlist = MailingList.objects.get_or_create( name="test@{}".format(listdomain))[0] req = HttpRequest() req.META["HTTP_HOST"] = vhost self.assertEqual(show_mlist(mlist, req), expected)