Esempio n. 1
0
def events(request):
    """
    Display a list of events that are present in the system.
    """
    all_events = Event.all_visible.all()

    sort_form = SortForm((('name', _('name')), ('date', _('date'))), request.GET,
                         initial={'sort_by': 'date', 'sort_ord': '-'})

    if sort_form.is_valid():
        sort_by = sort_form.cleaned_data['sort_by']
        sort_ord = sort_form.cleaned_data['sort_ord']
        all_events = all_events.order_by('{}{}'.format(sort_ord, sort_by), 'id')
    else:
        sort_by = 'date'
        sort_ord = '-'

    page_length = UserSettings.get_page_length(request)
    paginator = Paginator(all_events, page_length, orphans=page_length // 10)

    page_num = request.GET.get('page', '1')

    try:
        page = paginator.page(page_num)
    except PageNotAnInteger:
        page = paginator.page(1)
    except EmptyPage:
        page = paginator.page(paginator.num_pages)

    to_show = page_numbers_to_show(paginator, page.number)

    return render(request, 'palanaeum/events_list.html', {'page_numbers_to_show': to_show, 'page': page,
                                                          'sort_by': sort_by, 'sort_ord': sort_ord})
Esempio n. 2
0
def recent_entries(request):
    """
    Show recent entries, sorted by their assigned date, modification or creation date.
    """
    date_mode = request.GET.get('mode', 'created')

    if date_mode == 'modified':
        entries_ids = Entry.all_visible.order_by('-modified').values_list('id', flat=True)
    elif date_mode == 'recorded':
        entries_ids = EntryVersion.newest.order_by('-entry_date', '-entry_id')\
            .values_list('entry_id', flat=True).distinct()
    else:  # Sort by creation date by default
        entries_ids = Entry.all_visible.order_by('-created').values_list('id', flat=True)

    page_length = UserSettings.get_page_length(request)
    page_num = request.GET.get('page', '1')

    paginator = Paginator(entries_ids, page_length, orphans=page_length // 10)

    try:
        page = paginator.page(page_num)
    except PageNotAnInteger:
        page = paginator.page(1)
    except EmptyPage:
        page = paginator.page(paginator.num_pages)

    to_show = page_numbers_to_show(paginator, page.number)

    entries_map = Entry.prefetch_entries(page, show_unapproved=is_contributor(request))
    entries = [entries_map[entry_id] for entry_id in page]

    return render(request, 'palanaeum/recent_entries.html',
                  {'page_numbers_to_show': to_show, 'page': page, 'entries': entries, 'mode': date_mode,
                   'page_params': 'mode={}'.format(date_mode)})
Esempio n. 3
0
def adv_search(request):
    """
    Display an advances search form + search results.
    """
    filters = init_filters(request)

    ordering = request.GET.get('ordering', 'rank')

    search_params = [urlencode({'ordering': ordering})]
    for search_filter in filters:
        if search_filter:
            search_params.append(search_filter.as_url_param())
    search_params = "&".join(search_params)

    if any(filters):
        start_time = time.time()
        entries_scores = execute_filters(filters)

        entries, paginator, page = paginate_search_results(
            request, get_search_results(entries_scores, ordering))
        entries_found = paginator.count
        search_time = time.time() - start_time

        if entries_scores:
            to_show = page_numbers_to_show(paginator, page.number)
        else:
            to_show = []

    else:
        entries = []
        entries_found = 0
        page = None
        search_time = 0
        to_show = []

    return render(request,
                  'palanaeum/search/adv_search_results.html', {
                      'page_numbers_to_show': to_show,
                      'entries': entries,
                      'entries_found': entries_found,
                      'filters': filters,
                      'search_done': any(filters),
                      'query': request.GET.get('query', ''),
                      'search_params': search_params,
                      'page': page,
                      'search_time': search_time,
                      'ordering': ordering
                  },
                  status=200 if entries else 404)
Esempio n. 4
0
def users_list(request):
    only_staff = request.GET.get('only_staff', False)
    if only_staff:
        users = User.objects.filter(is_staff=True)
    else:
        users = User.objects.all()

    users = users.order_by('username')

    paginator = Paginator(users, 50, 10)
    try:
        page = paginator.page(request.GET.get('page', 0))
    except PageNotAnInteger:
        page = paginator.page(1)
    except EmptyPage:
        page = paginator.page(paginator.num_pages)

    to_show = page_numbers_to_show(paginator, page.number)

    return render(request, 'palanaeum/admin/users_list.html', {'page': page,
                                                               'page_numbers_to_show': to_show})