Exemplo n.º 1
0
def search(request, search, page, templateName, column=None, translation=None):
    search = search.strip()
    searches = search.split(' ')
    try:
        searches = map(lambda s: s.decode('UTF8').replace('"', '').replace("'", ''), shlex.split(search.encode('utf8')))
    except:
        pass
    tag_search = reduce(operator.and_, (Q(versText__icontains=" " + x) | Q(versText__icontains=">" + x) for x in searches))

    bible_order = bible_translation_order(request, column, translation)

    # Try to search for this word
    search1 = BibleText.objects.filter(tag_search, translationIdentifier=BibleTranslation.objects.filter(identifier=BIBLES_IN_VIEW[bible_order[0]])).order_by('vers__bookNr', 'vers__chapterNr', 'vers__versNr')
    search2 = BibleText.objects.filter(tag_search, translationIdentifier=BibleTranslation.objects.filter(identifier=BIBLES_IN_VIEW[bible_order[1]])).order_by('vers__bookNr', 'vers__chapterNr', 'vers__versNr')
    search3 = BibleText.objects.filter(tag_search, translationIdentifier=BibleTranslation.objects.filter(identifier=BIBLES_IN_VIEW[bible_order[2]])).order_by('vers__bookNr', 'vers__chapterNr', 'vers__versNr')
    search4 = BibleText.objects.filter(tag_search, translationIdentifier=BibleTranslation.objects.filter(identifier=BIBLES_IN_VIEW[bible_order[3]])).order_by('vers__bookNr', 'vers__chapterNr', 'vers__versNr')
    if search1.count() > 0 or search2.count() > 0 or search3.count() > 0 or search4.count() > 0:
        # only show the first 200 items
        num = 30
        idx1 = num * (int(page) - 1) if int(page) > 0 else 0
        idx2 = num * int(page) if int(page) > 0 else num
        count = max(search1.count(), search2.count(), search3.count(), search4.count())
        pagecnt = max(1, int(math.ceil(count * 1.0 / num)))

        # select the current verse list if user is logged in
        versLists = []
        versList = None
        versListItems = []
        if request.user.is_authenticated():
            versLists = BibleVersList.objects.filter(user=request.user).order_by('-lastchanged')
            if versLists.count() <= 0:
                versList = BibleVersList(lastchanged=_get_date(), title='Neue Versliste', user=request.user).save()
            else:
                versList = versLists[0]
                versListItems = BibleVersNote.objects.filter(user=request.user, versList=versList).order_by('order')
        # return render(request, 'strongs/search.html', {'count': count, 'pageact': idx2 / num, 'pagecnt': pagecnt, 'search': search, 'translation1': BIBLE_NAMES_IN_VIEW[0], 'translation2': BIBLE_NAMES_IN_VIEW[1], 'translation3': BIBLE_NAMES_IN_VIEW[2], 'translation4': BIBLE_NAMES_IN_VIEW[3], 'verses': izip_longest(search1[idx1:idx2], search2[idx1:idx2], search3[idx1:idx2], search4[idx1:idx2])})
        response = render(request, templateName, {'versLists': versLists, 'versListItems': versListItems, 'versList': versList, 'count1': search1.count(), 'count2': search2.count(), 'count3': search3.count(), 'count4': search4.count(), 'maxcount': count, 'pageact': idx2 / num, 'pagecnt': pagecnt, 'search': search, 'translation1': BIBLE_NAMES_IN_VIEW[bible_order[0]], 'translation2': BIBLE_NAMES_IN_VIEW[bible_order[1]], 'translation3': BIBLE_NAMES_IN_VIEW[bible_order[2]], 'translation4': BIBLE_NAMES_IN_VIEW[bible_order[3]], 'verses1': search1[idx1:idx2], 'verses2': search2[idx1:idx2], 'verses3': search3[idx1:idx2], 'verses4': search4[idx1:idx2], 'bible_hint1': BIBLE_HINTS_IN_VIEW[bible_order[0]], 'bible_hint2': BIBLE_HINTS_IN_VIEW[bible_order[1]], 'bible_hint3': BIBLE_HINTS_IN_VIEW[bible_order[2]], 'bible_hint4': BIBLE_HINTS_IN_VIEW[bible_order[3]], 'trOptions': BIBLE_NAMES_IN_VIEW})

        # handle cookies
        set_cookies(response, bible_order)

        return response
        # return HttpResponse('Found ' + str(search1.count()) + ' verses')
    else:
        # return HttpResponse('No book found for %s' % search)
        return render(request, 'strongs/error.html', {'search': search, 'message': 'Diese Suche lieferte keine Ergebnisse zurück!', 'solution':u'Bitte verwende einen anderen Suchbegriff, oder verwende nur einen Teil des Wortes als Suchbegriff.<br/>Hinweis: Das Wort muss nicht vollständig ausgeschrieben sein!'})
Exemplo n.º 2
0
def bible(request, bible_book, templateName, column=None, translation=None):
    # if strong-number, then forward
    if bible_book.isdigit():
        return strongs(request, bible_book)

    regex = re.compile(r"([0-9]?\.?\s?[^0-9\s]+)\s?([0-9]+)?,?([0-9]+)?$", re.UNICODE)
    if regex is not None:
        s = regex.search(bible_book)
        if s is not None and len(s.groups()) > 0:
            book = BibleBook.objects.filter(Q(name__iexact=s.group(1)) | Q(short_name__iexact=s.group(1)) | Q(alternativeNames__icontains=',' + s.group(1) + ','))
            chapter = s.group(2) or 1
            vers = s.group(3) or None;
            if book.count() > 0:
                # get the last chapter for this book
                max_chapter = BibleVers.objects.filter(bookNr=book).aggregate(Max('chapterNr'))
                max_chapter = max_chapter['chapterNr__max']

                # verify that the chapter is > 1, else select the previous book
                if int(chapter) < 1 and book[0].nr > 1:
                    book = BibleBook.objects.filter(nr=book[0].nr - 1)
                    max_chapter = BibleVers.objects.filter(bookNr=book).aggregate(Max('chapterNr'))
                    max_chapter = max_chapter['chapterNr__max']
                    chapter = max_chapter

                if int(chapter) > max_chapter and book[0].nr < 66:
                    # try the next first chapter
                    book = BibleBook.objects.filter(nr=book[0].nr + 1)
                    chapter = 1

                bible_order = bible_translation_order(request, column, translation)

                tr1 = BibleTranslation.objects.filter(identifier=BIBLES_IN_VIEW[bible_order[0]])
                tr2 = BibleTranslation.objects.filter(identifier=BIBLES_IN_VIEW[bible_order[1]])
                tr3 = BibleTranslation.objects.filter(identifier=BIBLES_IN_VIEW[bible_order[2]])
                tr4 = BibleTranslation.objects.filter(identifier=BIBLES_IN_VIEW[bible_order[3]])
                if tr1.count() > 0 and tr2.count() > 0 and tr3.count() > 0 and tr4.count() > 0:
                    verses1 = BibleText.objects.filter(translationIdentifier=tr1, vers__bookNr=book, vers__chapterNr=chapter).order_by('vers__versNr')
                    verses2 = BibleText.objects.filter(translationIdentifier=tr2, vers__bookNr=book, vers__chapterNr=chapter).order_by('vers__versNr')
                    verses3 = BibleText.objects.filter(translationIdentifier=tr3, vers__bookNr=book, vers__chapterNr=chapter).order_by('vers__versNr')
                    verses4 = BibleText.objects.filter(translationIdentifier=tr4, vers__bookNr=book, vers__chapterNr=chapter).order_by('vers__versNr')
                    if verses1.count() > 0 or verses2.count() > 0 or verses3.count() > 0 or verses4.count() > 0:
                        # return render(request, 'strongs/bible.html', {'vers': s.group(3), 'search': book[0].name + ' ' + str(chapter), 'translation1': BIBLE_NAMES_IN_VIEW[0], 'translation2': BIBLE_NAMES_IN_VIEW[1], 'translation3': BIBLE_NAMES_IN_VIEW[2], 'translation4': BIBLE_NAMES_IN_VIEW[3], 'verses': izip_longest(verses1, verses2, verses3, verses4)})
                        srch = book[0].name + ' ' + str(chapter)
                        if vers != None:
                            srch += ',' + str(vers)


                        # select the current verse list if user is logged in
                        versLists = []
                        versList = None
                        versListItems = []
                        if request.user.is_authenticated():
                            versLists = BibleVersList.objects.filter(user=request.user).order_by('-lastchanged')
                            if versLists.count() <= 0:
                                versList = BibleVersList(lastchanged=_get_date(), title='Neue Versliste', user=request.user).save()
                            else:
                                versList = versLists[0]
                                versListItems = BibleVersNote.objects.filter(user=request.user, versList=versList).order_by('order')

                        response = render(request, templateName, {'versLists': versLists, 'versListItems': versListItems, 'versList': versList, 'full_url': request.build_absolute_uri(None),'vers': vers, 'search': srch, 'translation1': BIBLE_NAMES_IN_VIEW[bible_order[0]], 'translation2': BIBLE_NAMES_IN_VIEW[bible_order[1]], 'translation3': BIBLE_NAMES_IN_VIEW[bible_order[2]], 'translation4': BIBLE_NAMES_IN_VIEW[bible_order[3]], 'verses1': verses1, 'verses2': verses2, 'verses3': verses3, 'verses4': verses4, 'bible_hint1': BIBLE_HINTS_IN_VIEW[bible_order[0]], 'bible_hint2': BIBLE_HINTS_IN_VIEW[bible_order[1]], 'bible_hint3': BIBLE_HINTS_IN_VIEW[bible_order[2]], 'bible_hint4': BIBLE_HINTS_IN_VIEW[bible_order[3]], 'trOptions': BIBLE_NAMES_IN_VIEW})

                        # handle cookies
                        set_cookies(response, bible_order)

                        return response;

                    else:
                        # return HttpResponse('No verses found')
                        return render(request, 'strongs/error.html', {'search': bible_book, 'message': u'Die Bibelstelle konnte nicht geladen werden!', 'solution':u'Versuche es bitte später noch einmal.<br/>Sollte der Fehler noch immer bestehen, gib uns bitte unter [email protected] bescheid!'})
                else:
                    # return HttpResponse('No translation found')
                    return render(request, 'strongs/error.html', {'search': bible_book, 'message': u'Die Übersetzungen konnten nicht geladen werden!', 'solution':'Probiere es bitte später noch einmal.<br/>Sollte der Fehler noch immer bestehen, gib uns bitte unter [email protected] bescheid!'})
            else:
                # Try to search for this word
                return False
        else:
            # Try to search for the string
            return sync_search(request, bible_book, 1)
    else:
        return render(request, 'strongs/error.html', {'search': bible_book, 'message': 'Es ist ein Fehler aufgetreten!', 'solution':u'Bitte probiere es später noch einmal.<br/>Sollte der Fehler noch immer bestehen, gib uns bitte unter [email protected] bescheid!'})
Exemplo n.º 3
0
def search_strong(request, strong, templateName, page='1', column=None, translation=None):
    nr = strong[1:]

    bible_order = bible_translation_order(request, column, translation)

    search = "<gr str=\"" + str(nr) + "\""
    heb = False
    if strong[0].upper() == 'H':
        search1 = BibleText.objects.filter(vers__bookNr__nr__lt=40, versText__icontains=search, translationIdentifier=BibleTranslation.objects.filter(identifier=BIBLES_IN_VIEW[0]))
        heb = True
    elif strong[0].upper() == 'G':
        search1 = BibleText.objects.filter(vers__bookNr__nr__gte=40, versText__icontains=search, translationIdentifier=BibleTranslation.objects.filter(identifier=BIBLES_IN_VIEW[0]))
    else:
        return sync_search(request, strong, page)

    if search1.count() > 0:
        search2, search3, search4 = [], [], []
        count = search1.count()

        # only show the first 30 items
        num = 30
        idx1 = num * (int(page) - 1) if int(page) > 0 else 0
        idx2 = num * int(page) if int(page) > 0 else num
        search1 = search1[idx1:idx2]
        verses = search1.values('vers')

        # for x in search1:
        if bible_order[1] == 0:
            search2 = search1
            search1 = BibleText.objects.filter(translationIdentifier__identifier=BIBLES_IN_VIEW[bible_order[0]], vers=verses)
        else:
            search2 = BibleText.objects.filter(translationIdentifier__identifier=BIBLES_IN_VIEW[bible_order[1]], vers=verses)
        if bible_order[2] == 0:
            search3 = search1
            search1 = BibleText.objects.filter(translationIdentifier__identifier=BIBLES_IN_VIEW[bible_order[0]], vers=verses)
        else:
            search3 = BibleText.objects.filter(translationIdentifier__identifier=BIBLES_IN_VIEW[bible_order[2]], vers=verses)
        if bible_order[3] == 0:
            search4 = search1
            search1 = BibleText.objects.filter(translationIdentifier__identifier=BIBLES_IN_VIEW[bible_order[0]], vers=verses)
        else:
            search4 = BibleText.objects.filter(translationIdentifier__identifier=BIBLES_IN_VIEW[bible_order[3]], vers=verses)
        # if s2.count() > 0:
            # search2.append(s2[0])
        # if s3.count() > 0:
            # search3.append(s3[0])
        # if s4.count() > 0:
            # search4.append(s4[0])

        pagecnt = max(1, int(math.ceil(count * 1.0 / num)))

        # select the current verse list if user is logged in
        versLists = []
        versList = None
        versListItems = []
        if request.user.is_authenticated():
            versLists = BibleVersList.objects.filter(user=request.user).order_by('-lastchanged')
            if versLists.count() <= 0:
                versList = BibleVersList(lastchanged=_get_date(), title='Neue Versliste', user=request.user).save()
            else:
                versList = versLists[0]
                versListItems = BibleVersNote.objects.filter(user=request.user, versList=versList).order_by('order')

        # return render(request, 'strongs/search.html', {'count': count, 'pageact': idx2 / num, 'pagecnt': pagecnt, 'search': strong, 'translation1': BIBLE_NAMES_IN_VIEW[0], 'translation2': BIBLE_NAMES_IN_VIEW[1], 'translation3': BIBLE_NAMES_IN_VIEW[2], 'translation4': BIBLE_NAMES_IN_VIEW[3], 'verses': izip_longest(search1, search2, search3, search4)})
        return render(request, templateName, {'versLists': versLists, 'versListItems': versListItems, 'versList': versList, 'count': count, 'pageact': idx2 / num, 'pagecnt': pagecnt, 'search': strong, 'translation1': BIBLE_NAMES_IN_VIEW[bible_order[0]], 'translation2': BIBLE_NAMES_IN_VIEW[bible_order[1]], 'translation3': BIBLE_NAMES_IN_VIEW[bible_order[2]], 'translation4': BIBLE_NAMES_IN_VIEW[bible_order[3]], 'verses1': search1, 'verses2': search2, 'verses3': search3, 'verses4': search4, 'bible_hint1': BIBLE_HINTS_IN_VIEW[bible_order[0]], 'bible_hint2': BIBLE_HINTS_IN_VIEW[bible_order[1]], 'bible_hint3': BIBLE_HINTS_IN_VIEW[bible_order[2]], 'bible_hint4': BIBLE_HINTS_IN_VIEW[bible_order[3]], 'trOptions': BIBLE_NAMES_IN_VIEW})
    else:
        # return HttpResponse('No verses found for strong number ' + strong)
        alt = 'H' + strong[1:]
        if heb:
            alt = 'G' + strong[1:]
        return render(request, 'strongs/error.html', {'search': strong, 'message': 'Keine Verse mit dieser Strong-Nummer gefunden!', 'solution':u'Scheinbar existiert die Strong-Nummer ' + strong + ' nicht!<br/>Korrigiere deine Eingabe, oder probiere es einmal mit <a href="/' + alt + '">' + alt + '</a>.'})