Example #1
0
def isA(request):
    """Handels a GET/POST request to check if a given word is a word.

    GET/POST parameters:
    language --- language of the word
    word --- word to check
    """
    track(request, 'isA | words | API | TIMA')
    params = request.POST.copy() if request.method == 'POST' else request.GET.copy()

    language = None
    if 'language' in params and 'word' in params:
        l = params.pop('language')[-1]
        try:
            language = Language.objects.get(code=l)
        except Language.DoesNotExist:
            return HttpResponseNotFound('Language with "%s" not found.' % l)

        w = params.pop('word')[-1]
        try:
            word = Word.objects.get(name=w, language=language)
        except Word.DoesNotExist:
            if not exists(language.code.lower(), w):
                return HttpResponseNotFound('Word with "%s" not found.' % w)
    else:
        return HttpResponseBadRequest('Required parameter "language" or "word" is missing.')
    return HttpResponse(dumps({'response_date':timezone.now().strftime('%Y-%m-%dT%H:%M:%S:%f%z')}), 'application/json')
Example #2
0
    def clean(self):
        cleaned_data = super(AssociationForm, self).clean()
        word = cleaned_data.get('word')
        association = cleaned_data.get('association')
        if word == association:
            self.add_error('association',
                _('The word and the association may not match.'))

        a = cleaned_data['association'] if 'association' in cleaned_data else ''
        if not cleaned_data.get('association1') or cleaned_data.get('association1') != a:
            if not Word.objects.filter(name=a).filter(language__code=cleaned_data.get('language')).exists():
                if not exists(cleaned_data.get('language').lower(), a):
                    self.add_error('association',
                        _('We have not recognized your input as word.' +
                                ' Are you sure you have no spelling mistakes,' + 
                                ' in order to confirm your input press "Save".'))
        cleaned_data['association1'] = a