Ejemplo n.º 1
0
def staff_list(request):
    """
    Tests:
        - GETTest
        - SecurityTest
    """
    # User must be staff or admin to get to this page
    if not request.user.is_staff:
        t = loader.get_template('403.html')
        c = RC(request, {})
        return HttpResponseForbidden(t.render(c))
    users = User.objects.all().order_by('last_name')
    page_num = get_number(request.GET, 'page', PAGE_NUM)
    users_per_page = get_number(request.GET, 'per_page', PER_PAGE)
    paginator = Paginator(users, users_per_page)
    try:
        page_of_users = paginator.page(page_num)
    except (EmptyPage, InvalidPage):
        page_of_users = paginator.page(paginator.num_pages)
    if request.GET.get('dir', '') == 'asc': dir = 'desc'
    else: dir = 'asc'
    var_dict = {
        'users': page_of_users,
        'per_page': users_per_page,
        'page': page_num,
        'field': request.GET.get('field', 'any_field'),
        'filter_text': request.GET.get('filter', ''),
        'dir': dir,
    }
    template = 'books/staff.html'
    return rtr(template, var_dict, context_instance=RC(request))
Ejemplo n.º 2
0
def staff_list(request):
    """
    Tests:
        - GETTest
        - SecurityTest
    """
    # User must be staff or admin to get to this page
    if not request.user.is_staff:
        t = loader.get_template('403.html')
        c = RC(request, {})
        return HttpResponseForbidden(t.render(c))
    users = User.objects.filter(is_staff = True)
    page_num = get_number(request.GET, 'page', PAGE_NUM)
    users_per_page = get_number(request.GET, 'per_page', PER_PAGE)
    paginator = Paginator(users, users_per_page)
    try:
        page_of_users = paginator.page(page_num)
    except (EmptyPage, InvalidPage):
        page_of_users = paginator.page(paginator.num_pages)
    if request.GET.get('dir', '') == 'asc': dir = 'desc'
    else: dir = 'asc'
    var_dict = {
        'users' : page_of_users,
        'per_page' : users_per_page,
        'page' : page_num,
        'field' : request.GET.get('field', 'any_field'),
        'filter_text' : request.GET.get('filter', ''),
        'dir' : dir, 
    }
    template = 'books/staff.html'
    return rtr(template, var_dict,  context_instance=RC(request))
Ejemplo n.º 3
0
def book_list(request):
    """
    Shows a list of all the books listed.
    Does pagination, sorting and filtering.
    
    Tests:
        - GETTest
        - SearchBookTest
        - SortBookTest
    """
    house_cleaning()
    # Filter for the search box
    if request.method == 'GET':
        filter_form = FilterForm(request.GET)
        if filter_form.is_valid():
            cd = filter_form.cleaned_data
            all_books = Book.objects.all()
            books = book_filter(cd['filter'], cd['field'], all_books)
        elif request.GET.has_key("sort_by") and request.GET.has_key("dir"):
            books = book_sort(request.GET["sort_by"], request.GET["dir"])
        else:
            books = Book.objects.all()

    # Filter according to permissions
    if not request.user.is_staff:
        # Non staff can only see books which are for sale.
        books = filter(lambda x: x.status == 'F', books)
    # Staff want to see the unsold books first so if we sort them ascending, that should do
    else:
        # This alphabet is the order in which book statuses should be displayed
        alphabet = "AFOPMTSD"
        # Sort by the index value of the book status in the alphabet
        books = sorted(books, key=lambda book: [alphabet.index(book.status)])

    # Pagination
    page_num = get_number(request.GET, 'page', PAGE_NUM)
    books_per_page = get_number(request.GET, 'per_page', PER_PAGE)

    paginator = Paginator(books, books_per_page)
    try:
        page_of_books = paginator.page(page_num)
    except (EmptyPage, InvalidPage):
        page_of_books = paginator.page(paginator.num_pages)

    # Template time
    if request.GET.get('dir', '') == 'asc': dir = 'desc'
    else: dir = 'asc'
    var_dict = {
        'books' : page_of_books,
        'per_page' : books_per_page,
        'page' : page_num,
        'field' : request.GET.get('field', 'any_field'),
        'filter_text' : request.GET.get('filter', ''),
        'dir' : dir
    }
    return rtr('books/book_list.html', var_dict, context_instance=RC(request))
Ejemplo n.º 4
0
def book_list(request):
    """
    Shows a list of all the books listed.
    Does pagination, sorting and filtering.
    
    Tests:
        - GETTest
        - SearchBookTest
        - SortBookTest
    """
    house_cleaning()
    # Filter for the search box
    if request.method == 'GET':
        filter_form = FilterForm(request.GET)
        if filter_form.is_valid():
            cd = filter_form.cleaned_data
            all_books = Book.objects.all()
            books = book_filter(cd['filter'], cd['field'], all_books)
        elif request.GET.has_key("sort_by") and request.GET.has_key("dir"):
            books = book_sort(request.GET["sort_by"], request.GET["dir"])
        else:
            books = Book.objects.all()

    # Filter according to permissions
    if not request.user.is_staff:
        # Non staff can only see books which are for sale.
        books = filter(lambda x: x.status == 'F', books)
    # Staff want to see the unsold books first so if we sort them ascending, that should do
    else:
        # This alphabet is the order in which book statuses should be displayed
        alphabet = "AFOPMTSD"
        # Sort by the index value of the book status in the alphabet
        books = sorted(books, key=lambda book: [alphabet.index(book.status)])

    # Pagination
    page_num = get_number(request.GET, 'page', PAGE_NUM)
    books_per_page = get_number(request.GET, 'per_page', PER_PAGE)

    paginator = Paginator(books, books_per_page)
    try:
        page_of_books = paginator.page(page_num)
    except (EmptyPage, InvalidPage):
        page_of_books = paginator.page(paginator.num_pages)

    # Template time
    if request.GET.get('dir', '') == 'asc': dir = 'desc'
    else: dir = 'asc'
    var_dict = {
        'books': page_of_books,
        'per_page': books_per_page,
        'page': page_num,
        'field': request.GET.get('field', 'any_field'),
        'filter_text': request.GET.get('filter', ''),
        'dir': dir
    }
    return rtr('books/book_list.html', var_dict, context_instance=RC(request))
Ejemplo n.º 5
0
def setting_list(request):
    """
    Shows a list of all the application settings.
    Does pagination, sorting and filtering.
    
    Tests:
    """
    house_cleaning()
    # Filter for the search box
    if request.method == 'GET':
        filter_form = FilterForm(request.GET)
        if filter_form.is_valid():
            cd = filter_form.cleaned_data
            all_settings = AppSetting.objects.all()
            settings = settings_filter(cd['filter'], cd['field'], all_settings)
        elif request.GET.has_key("sort_by") and request.GET.has_key("dir"):
            settings = setting_sort(request.GET["sort_by"], request.GET["dir"])
        else:
            settings = AppSetting.objects.all()


# This filter for permissions was copied from the books view but probably isn't needed here
# Filter according to permissions
#    if not request.user.is_staff:
# Non staff can only see books which are for sale.
#        books = filter(lambda x: x.status == 'F', books)

# Pagination
    page_num = get_number(request.GET, 'page', PAGE_NUM)
    settings_per_page = get_number(request.GET, 'per_page', PER_PAGE)

    paginator = Paginator(settings, settings_per_page)
    try:
        page_of_settings = paginator.page(page_num)
    except (EmptyPage, InvalidPage):
        page_of_settings = paginator.page(paginator.num_pages)

    # Template time
    if request.GET.get('dir', '') == 'asc': dir = 'desc'
    else: dir = 'asc'
    var_dict = {
        'appsettings': page_of_settings,
        'per_page': settings_per_page,
        'page': page_num,
        'field': request.GET.get('field', 'any_field'),
        'filter_text': request.GET.get('filter', ''),
        'dir': dir
    }
    return rtr('appsettings/settings_list.html',
               var_dict,
               context_instance=RC(request))
Ejemplo n.º 6
0
def setting_list(request):
    """
    Shows a list of all the application settings.
    Does pagination, sorting and filtering.
    
    Tests:
    """
    house_cleaning()
    # Filter for the search box
    if request.method == 'GET':
        filter_form = FilterForm(request.GET)
        if filter_form.is_valid():
            cd = filter_form.cleaned_data
            all_settings = AppSetting.objects.all()
            settings = settings_filter(cd['filter'], cd['field'], all_settings)
        elif request.GET.has_key("sort_by") and request.GET.has_key("dir"):
            settings = setting_sort(request.GET["sort_by"], request.GET["dir"])
        else:
            settings = AppSetting.objects.all()

# This filter for permissions was copied from the books view but probably isn't needed here
    # Filter according to permissions
#    if not request.user.is_staff:
        # Non staff can only see books which are for sale.
#        books = filter(lambda x: x.status == 'F', books)

    # Pagination
    page_num = get_number(request.GET, 'page', PAGE_NUM)
    settings_per_page = get_number(request.GET, 'per_page', PER_PAGE)

    paginator = Paginator(settings, settings_per_page)
    try:
        page_of_settings = paginator.page(page_num)
    except (EmptyPage, InvalidPage):
        page_of_settings = paginator.page(paginator.num_pages)

    # Template time
    if request.GET.get('dir', '') == 'asc': dir = 'desc'
    else: dir = 'asc'
    var_dict = {
        'appsettings' : page_of_settings,
        'per_page' : settings_per_page,
        'page' : page_num,
        'field' : request.GET.get('field', 'any_field'),
        'filter_text' : request.GET.get('filter', ''),
        'dir' : dir
    }
    return rtr('appsettings/settings_list.html', var_dict, context_instance=RC(request))
Ejemplo n.º 7
0
def metabook_list(request):
    """
    List all metabooks in the database
    
    Tests:
        - GETTest
        - SecurityTest
    """
    # User must be staff or admin to get to this page
    if not request.user.is_staff:
        t = loader.get_template('403.html')
        c = RC(request)
        return HttpResponseForbidden(t.render(c))
    if request.GET.has_key("sort_by") and request.GET.has_key("dir"):
        metabooks = metabook_sort(request.GET["sort_by"], request.GET["dir"])
    else: metabooks = MetaBook.objects.all()

    # Pagination
    page_num = get_number(request.GET, 'page', PAGE_NUM)
    metabooks_per_page = get_number(request.GET, 'per_page', PER_PAGE)

    paginator = Paginator(metabooks, metabooks_per_page)
    try:
        page_of_metabooks = paginator.page(page_num)
    except (EmptyPage, InvalidPage):
        page_of_metabooks = paginator.page(paginator.num_pages)

    # Template time
    if request.GET.get('dir', '') == 'asc': dir = 'desc'
    else: dir = 'asc'
    var_dict = {
        'metabooks' : page_of_metabooks,
        'per_page' : metabooks_per_page,
        'page' : page_num,
        'dir' : 'desc' if request.GET.get('dir', '') == 'asc' else 'asc'
    }

    template = 'books/list_metabooks.html'
    return rtr(template, var_dict, context_instance=RC(request))