Example #1
0
def authors_by_one_letter(request):
    '''returns authors arranged by first letter in their names'''
    letter = unquote(request.GET['letter'])
    alphabet_string = generate_alphabets()
    string = ""
    for let in alphabet_string:
        request_to_server = Q(book__pagelink__startswith="http://lib.ru", name__istartswith=letter + let)
        auth_count = Author.objects.filter(request_to_server).distinct().count()
        if auth_count > 0:          # TODO condition
            string += let
    string = string[0:-1]

    if len(string) < 1:
        request_to_server = Q(book__pagelink__startswith="http://lib.ru", name__istartswith=letter)
        authors = Author.objects.filter(request_to_server).distinct().\
                                                            order_by('name')
        return render_response(request, 'book/opds/libru/books_by_author.xml',
            {'authors': authors})

    my_list = []
    if letter in views.generate_russian_alphabet():
        my_string = letter + u'а'
    else:
        my_string = letter + 'a'

    for let in string:
        if my_string != letter + let:
            my_string += "-" + letter + let
        my_list.append(my_string)
        my_string = letter + unichr(ord(let) + 1)
    if letter in views.generate_russian_alphabet():
        my_string += "-" + letter + u"я"
    else:
        my_string += "-" + letter + "z"

    my_list.append(my_string)

    return render_response(request, 'book/opds/libru/books_by_author.xml',
        {'string': my_list, 'num': 2, 'letter': letter })
Example #2
0
def generate_alphabets():
    alphabet_string = views.generate_russian_alphabet()
    alphabet_string += views.generate_latin_alphabet()
    return alphabet_string