Beispiel #1
0
def show_definition(request, word):
    context = {}

    definition = logic.define_word(word)

    # If a definition is retrieved, 
    if definition:
        context = definition
        try:
            selected_word = WordLookupCount.objects.get(word=word)
            selected_word.count += 1
            context['count'] = selected_word.count
            selected_word.save()
        except WordLookupCount.DoesNotExist:
            WordLookupCount.objects.create(word=word, count=1)
            context['count'] = 1
        except:
            # TODO:
            # Is there an 'oops, somethign when wrong here' expception?
            # that can be handled nicely in the views? I'm assuming something 
            # like this exists for a 404 error.
            pass
            
    # Temp stuff, remove this and to the ReponseRedirector(reverse stuff)
    return render(request, 'my_dictionary/index.html', context)
Beispiel #2
0
import logic

print "Initializing..."

# The NLTK lib to define a word has a 3 second delay the first time it is 
# used. This is no longer present after the first time. Eliminate this delay 
# from the first user to use the app after the server restarts by 
# definining some random word here.

definition = logic.define_word('cake')