Beispiel #1
0
    def get_queryset(self):
        # person = get_person(self.request)
        queryset = Sentence.objects.all()\
            .order_by(
                'quality_control__approved',
                'quality_control__updated')

        q = self.request.query_params.get('recording', 'False')
        if 'True' in q:
            sentence = get_next_sentence(self.request)
            if sentence:
                queryset = [sentence]
            else:
                return []

        else:

            query = self.request.query_params.get(
                'quality_control__approved')
            if query is not None:
                queryset = queryset.annotate(sum_approved=Sum(
                    Case(
                        When(
                            quality_control__approved=True,
                            then=Value(1)),
                        When(
                            quality_control__approved=False,
                            then=Value(0)),
                        When(
                            quality_control__isnull=True,
                            then=Value(0)),
                        default=Value(0),
                        output_field=IntegerField())
                ))
                try:
                    if eval(query) is True:
                        queryset = queryset\
                            .filter(sum_approved__gte=1)\
                            .order_by('-updated')
                    elif eval(query) is False:
                        queryset = queryset\
                            .filter(sum_approved__lte=0)\
                            .annotate(text_length=Length('text'))\
                            .filter(text_length__gte=12)\
                            .order_by('-updated')\
                            .order_by(Length('text').asc())
                    else:
                        raise ValueError(
                            "Specify either True or False for \
                            quality_control__approved=")
                except:
                    raise ValueError(
                        "Specify either True or False for \
                        quality_control__approved=")

        return queryset
Beispiel #2
0
def person(request, uuid):
    # # from django.utils.translation import activate
    # # activate('mi')
    lang = get_current_language(request)
    sentence = get_next_sentence(request)

    logger.debug('Language Cookie Is: {0}'.format(lang))

    output = _('Today is %(month)s %(day)s.') % {'month': 10, 'day': 10}

    return render(request, 'people/person.html', {'language':lang, 'output':output, 'sentence': sentence})
    return render(request, 'people/person.html')
Beispiel #3
0
def profile(request):
    
    if request.user.is_authenticated():
        sentence = get_next_sentence(request)
        current_language = get_current_language(request)
        person = Person.objects.get(user=request.user)
        known_languages = KnownLanguage.objects.filter(person=person)
        unknown_languages = get_unknown_languages(person)

        if not current_language:
            if len(known_languages)==0:
                url = reverse('people:choose_language') + '?next=people:profile'
                return redirect(url)
            elif len(known_languages)>=1:
                set_current_language_for_person(person, known_languages[0].language)
                current_language = known_languages[0].language
            else:
                logger.error('PROFILE VIEW: We need to handle this situation - NO CURRENT LANGUAGE but len know languages is YUGE')
                raise Http404("Something went wrong. We're working on this...")



        recordings = Recording.objects.filter(person__user=request.user, sentence__language=current_language)
        sentences = get_sentences(request, recordings)
        known_languages = [i.language for i in known_languages]

        return render(request, 'people/profile.html', 
            {'request':request, 
             'user':request.user, 
             'sentence':sentence, 
             'current_language':current_language,
             'person': person,
             'recordings': recordings,
             'sentences': sentences,
             'known_languages': known_languages
             })
    else:
        # We should enable someone to provide recordings without loging in - and we can show their recordings - user coockies to track
        # BUt for now we'll redirect to login
        return redirect(reverse('account_login'))
Beispiel #4
0
    def get_queryset(self):
        # person = get_person(self.request)
        queryset = Sentence.objects.all()\
            .order_by('quality_control__approved', 'quality_control__updated')

        q = self.request.query_params.get('recording', 'False')
        if 'True' in q:
            sentence = get_next_sentence(self.request)
            if sentence:
                queryset = queryset.filter(pk=sentence.pk)
            else:
                return []

        else:

            query = self.request.query_params.get('quality_control__approved')
            if query is not None:
                queryset = queryset.annotate(sum_approved=Sum(
                    Case(When(quality_control__approved=True, then=Value(1)),
                         When(quality_control__approved=False, then=Value(0)),
                         default=Value(0),
                         output_field=IntegerField())))

                if eval(query) is True:

                    queryset = queryset.filter(
                        sum_approved__gte=1).order_by('-sum_approved')
                    # queryset = queryset.filter(quality_control__isnull=False)

                # filter by approved = false
                elif eval(query) is False:
                    queryset = queryset.filter(
                        sum_approved__lte=0).order_by('-sum_approved')
                else:
                    raise TypeError

        return queryset