Ejemplo n.º 1
0
 def test_no_page_number_supplied(self):
     notes = Note.objects.all().order_by('id')
     paged_list_exists = helpers.pg_records(1, notes, 2)
     paged_list_no_page_supplied = helpers.pg_records('', notes, 2)
     self.assertEquals(str(paged_list_exists),
                       str(paged_list_no_page_supplied))
     paged_list_no_page_supplied = helpers.pg_records('j', notes, 2)
     self.assertEquals(str(paged_list_exists),
                       str(paged_list_no_page_supplied))
     paged_list_no_page_supplied = helpers.pg_records(45.6, notes, 2)
     self.assertEquals(str(paged_list_exists),
                       str(paged_list_no_page_supplied))
     paged_list_no_page_supplied = helpers.pg_records(u"\2191", notes, 2)
     self.assertEquals(str(paged_list_exists),
                       str(paged_list_no_page_supplied))
Ejemplo n.º 2
0
 def test_page_number_lower_than_exists(self):
     artists = Artist.objects.all().order_by('name')
     paged_list_exists = helpers.pg_records(1, artists, 2)
     paged_list_out_of_bounds = helpers.pg_records(-5, artists, 2)
     self.assertEquals(str(paged_list_exists),
                       str(paged_list_out_of_bounds))
     paged_list_out_of_bounds = helpers.pg_records(-10, artists, 2)
     self.assertEquals(str(paged_list_exists),
                       str(paged_list_out_of_bounds))
     paged_list_out_of_bounds = helpers.pg_records(-100, artists, 2)
     self.assertEquals(str(paged_list_exists),
                       str(paged_list_out_of_bounds))
     paged_list_out_of_bounds = helpers.pg_records(-1000, artists, 2)
     self.assertEquals(str(paged_list_exists),
                       str(paged_list_out_of_bounds))
Ejemplo n.º 3
0
 def test_second_page_correct_entries_note(self):
     notes = Note.objects.all().order_by('id')
     paged_list = helpers.pg_records(2, notes, 2)
     self.assertEqual(notes[2].id, paged_list[0].id)
     self.assertEqual(notes[2].title, paged_list[0].title)
     self.assertEqual(notes[2].text, paged_list[0].text)
     self.assertEqual(notes[2].show_id, paged_list[0].show_id)
     self.assertEqual(notes[2].user_id, paged_list[0].user_id)
     self.assertEqual(notes[2].posted_date, paged_list[0].posted_date)
Ejemplo n.º 4
0
def artist_list(request):
    """Show artist list and search for Artist"""
    form = ArtistSearchForm()
    search_name = request.GET.get('search_name')
    if search_name:
        artists = Artist.objects.filter(name__icontains=search_name).order_by('name')
    else:
        artists = Artist.objects.all().order_by('name')

    # get page number to be supplied to pagination for page number display
    page = request.GET.get('page')
    # created new page object to be supplied to rendered page
    artists = helpers.pg_records(page, artists, 5)

    return render(request, 'lmn/artists/artist_list.html', { 'artists': artists, 'form': form, 'search_term': search_name })
Ejemplo n.º 5
0
def latest_notes(request):
    """Show most recent notes """
    notes = Note.objects.all().order_by('-posted_date')
    search_form = NoteSearchForm(request.GET)
    if search_form.is_valid():
        search_term = search_form.cleaned_data['search_term']
        notes = Note.objects.filter(
            title__icontains=search_term).order_by('-posted_date')

    else:
        search_form = NoteSearchForm()
        notes = Note.objects.order_by('-posted_date')
    # get page number to be supplied to pagination for page number display
    page = request.GET.get('page')
    # Calls helper function to paginate records. (request, list of objects, how many entries per page)
    notes = helpers.pg_records(page, notes, 5)
    return render(request, 'lmn/notes/note_list.html', {
        'notes': notes,
        'search_form': search_form
    })
Ejemplo n.º 6
0
def venue_list(request):
    form = VenueSearchForm()
    search_name = request.GET.get('search_name')

    if search_name:
        #search for this venue, display results
        venues = Venue.objects.filter(
            name__icontains=search_name).order_by('name')
    else:
        venues = Venue.objects.all().order_by('name')

    # get page number to be supplied to pagination for page number display
    page = request.GET.get('page')
    # created new page object to be supplied to rendered page
    venues = helpers.pg_records(page, venues, 5)

    return render(request, 'lmn/venues/venue_list.html', {
        'venues': venues,
        'form': form,
        'search_term': search_name
    })
Ejemplo n.º 7
0
 def test_correct_number_of_items_returned_page_two_note(self):
     notes = Note.objects.all().order_by('id')
     paged_list = helpers.pg_records(2, notes, 2)
     self.assertEqual(len(paged_list), 1)
Ejemplo n.º 8
0
 def test_correct_number_of_items_returned_page_two_artist(self):
     artists = Artist.objects.all().order_by('name')
     paged_list = helpers.pg_records(2, artists, 2)
     self.assertEqual(len(paged_list), 1)
Ejemplo n.º 9
0
 def test_second_page_correct_entries_artist(self):
     artists = Artist.objects.all().order_by('name')
     paged_list = helpers.pg_records(2, artists, 2)
     self.assertEqual(artists[2].name, paged_list[0].name)