def test_empty(self):
     pdm = Paradigm.objects.create(language=self.lang,
                                   source=self.source,
                                   editor=self.editor,
                                   comment="TestFindIdenticals")
     pdm._prefill_pronouns()
     table = add_pronoun_table(pdm.pronoun_set.all(),
                               filter_empty_rows=True)
     assert table == []
Exemplo n.º 2
0
def detail(request, paradigm_id):
    try:
        p = Paradigm.objects.select_related().get(pk=paradigm_id)
        ptable = p.pronoun_set.prefetch_related("entries", "pronountype").all()
        out = {
            'paradigm': p,
            'language': p.language,
            'source': p.source,
            'pronoun_rows': add_pronoun_table(ptable),
            'relationship_table': None
        }
        return render(request, 'pronouns/detail.html', out)
    except Paradigm.DoesNotExist:
        raise Http404  # fail. Doesn't exist so pop out a 404
 def test_partial(self):
     pron = self.pdm.pronoun_set.all()[0]
     lex = Lexicon.objects.create(
         editor=self.editor,
         language=self.lang,
         source=self.source,
         word=self.word,
         entry='fudge'
     )
     lex.save()
     pron.entries.add(lex)
     pron.save()
     
     table = add_pronoun_table(self.pdm.pronoun_set.all(), filter_empty_rows=True)
     assert len(table) == 1
     assert table[0][0] == u'1st (excl) Person Singular'
     assert table[0][1].get('A') == pron
 def test_full(self):
     for counter, pron in enumerate(self.pdm.pronoun_set.all(), 1):
         lex = Lexicon.objects.create(
             editor=self.editor,
             language=self.lang,
             source=self.source,
             word=self.word,
             entry='fudge-%d' % counter
         )
         lex.save()
         pron.entries.add(lex)
         pron.save()
         
     table = add_pronoun_table(self.pdm.pronoun_set.all(), filter_empty_rows=False)
     assert len(table) == 3
     for counter, row in enumerate(table, 1):
         assert row[1].get('A').entries.all()[0].entry == 'fudge-%d' % counter
Exemplo n.º 5
0
def detail(request, paradigm_id):
    try:
        p = Paradigm.objects.select_related().get(pk=paradigm_id)
        ptable = p.pronoun_set.prefetch_related("entries", "pronountype").all()
        out = {
            'paradigm': p,
            'language': p.language,
            'source': p.source,
            'pronoun_rows': add_pronoun_table(ptable),
            'relationship_table': None
        }
        relationships = p.relationship_set.select_related().all()
        if len(relationships) > 0:
            out['relationship_table'] = PronounRelationshipTable(relationships)
        
        return render(request, 'pronouns/detail.html', out)
    except Paradigm.DoesNotExist:
        raise Http404 # fail. Doesn't exist so pop out a 404
    def test_partial(self):
        pdm = Paradigm.objects.create(language=self.lang,
                                      source=self.source,
                                      editor=self.editor,
                                      comment="TestFindIdenticals")
        pdm._prefill_pronouns()
        pron = pdm.pronoun_set.all().order_by('pronountype__person')[0]
        lex = Lexicon.objects.create(editor=self.editor,
                                     language=self.lang,
                                     source=self.source,
                                     word=self.word,
                                     entry='fudge-partial')
        lex.save()
        pron.entries.add(lex)
        pron.save()

        table = add_pronoun_table(pdm.pronoun_set.all(),
                                  filter_empty_rows=True)
        assert len(table) == 1
        assert table[0][0] == u'1st (excl) Person Singular'
        assert table[0][1].get('A') == pron
    def test_full(self):
        pdm = Paradigm.objects.create(language=self.lang,
                                      source=self.source,
                                      editor=self.editor,
                                      comment="TestFindIdenticals")
        pdm._prefill_pronouns()

        for counter, pron in enumerate(pdm.pronoun_set.all(), 1):
            lex = Lexicon.objects.create(editor=self.editor,
                                         language=self.lang,
                                         source=self.source,
                                         word=self.word,
                                         entry='fudge-full-%d' % counter)
            lex.save()
            pron.entries.add(lex)
            pron.save()

        table = add_pronoun_table(pdm.pronoun_set.all(),
                                  filter_empty_rows=False)
        assert len(table) == 3
        for counter, row in enumerate(table, 1):
            expected = 'fudge-full-%d' % counter
            assert row[1].get('A').entries.all()[0].entry == expected
Exemplo n.º 8
0
def edit_relationships(request, paradigm_id):
    p = get_object_or_404(Paradigm, pk=paradigm_id)
    relationship_form = RelationshipFormSet(request.POST or None, instance=p)

    def _fix_relationship_form(relationship_form):
        # Yuck - filter pronouns to match the given paradigm.
        #    -> must be a better way to do this!
        q = Pronoun.objects.all().filter(paradigm=p)
        q = q.annotate(entry_count=Count('entries')).exclude(entry_count=0)
        q = q.select_related()

        for f in relationship_form.forms:
            f.fields['pronoun1'].queryset = q
            f.fields['pronoun2'].queryset = q
        return relationship_form

    relationship_form = _fix_relationship_form(relationship_form)

    if relationship_form.is_valid():
        instances = relationship_form.save(commit=False)
        for obj in instances:
            obj.editor = request.user
            obj.save()
        return redirect('pronouns:detail', p.id)

    ptable = p.pronoun_set.prefetch_related("entries", "pronountype").all()

    return render(
        request, 'pronouns/edit_relationships.html', {
            'paradigm': p,
            'language': p.language,
            'source': p.source,
            'pronoun_rows': add_pronoun_table(ptable),
            'relationships': relationship_form,
            'rule_form': RuleForm(),
            'applied_rules': p.rule_set.all(),
        })
Exemplo n.º 9
0
def edit_relationships(request, paradigm_id):
    p = get_object_or_404(Paradigm, pk=paradigm_id)
    relationship_form = RelationshipFormSet(request.POST or None, instance=p)
    
    def _fix_relationship_form(relationship_form):
        # Yuck - filter pronouns to match the given paradigm.
        #    -> must be a better way to do this!
        q = Pronoun.objects.all().filter(paradigm=p)
        q = q.annotate(entry_count=Count('entries')).exclude(entry_count=0)
        q = q.select_related()
        
        for f in relationship_form.forms:
            f.fields['pronoun1'].queryset = q
            f.fields['pronoun2'].queryset = q
        return relationship_form
        
    relationship_form = _fix_relationship_form(relationship_form)
    
    if relationship_form.is_valid():
        instances = relationship_form.save(commit=False)
        for obj in instances:
            obj.editor = request.user
            obj.save()
        return redirect('pronouns:detail', p.id)
    
    ptable = p.pronoun_set.prefetch_related("entries", "pronountype").all()
    
    return render_to_response('pronouns/edit_relationships.html', {
        'paradigm': p,
        'language': p.language,
        'source': p.source,
        'pronoun_rows': add_pronoun_table(ptable),
        'relationships': relationship_form,
        'rule_form': RuleForm(),
        'applied_rules': p.rule_set.all(),
    }, context_instance=RequestContext(request))
Exemplo n.º 10
0
def language_detail(request, language):
    """
    Show Language Details
    
    Uses a slug to lookup. If the slug is the primary one in the languages
    table, then the details page will be shown
    
    If nothing is found in the languages table, then the AlternateNames table
    is checked for a match. If found, then this view will redirect to the
    canonical slug.
    """
    # if we find the language slug, then render the language detail page.
    try:
        my_lang = Language.objects.get(slug=language)
        out = {
            'language': my_lang,
            'alternatenames': my_lang.alternatename_set.all(),
            'links': my_lang.link_set.all(),
            'attachments': my_lang.attachment_set.all(),
        }

        # sources used
        sources = my_lang.lexicon_set.values('source_id').distinct().all()
        source_ids = [_['source_id'] for _ in sources]
        out['sources_used'] = Source.objects.filter(pk__in=source_ids)

        # location
        out['location'] = None
        if my_lang.isocode:
            try:
                out['location'] = Location.objects.filter(
                    isocode=my_lang.isocode)[0]
            except (Location.DoesNotExist, IndexError):
                pass  # keep out['location'] as None

        # load lexicon if installed.
        if 'website.apps.lexicon' in settings.INSTALLED_APPS:
            qset = my_lang.lexicon_set.select_related().all()
            if request.user.is_authenticated():
                out['lexicon_table'] = LanguageLexiconEditTable(qset)
            else:
                out['lexicon_table'] = LanguageLexiconTable(qset)

            RequestConfig(request).configure(out['lexicon_table'])

            try:
                out['lexicon_table'].paginate(page=request.GET.get('page', 1),
                                              per_page=50)
            except EmptyPage:  # 404 on a empty page
                raise Http404
            except PageNotAnInteger:  # 404 on invalid page number
                raise Http404

        # load pronouns
        if 'website.apps.pronouns' in settings.INSTALLED_APPS:
            from website.apps.pronouns.models import Paradigm
            from website.apps.pronouns.tools import add_pronoun_table
            try:
                out['pronoun'] = Paradigm.objects.filter(language=my_lang)[0]
                out['pronoun_rows'] = add_pronoun_table(
                    out['pronoun'].pronoun_set.all())
            except IndexError:  # no paradigm
                pass

        return render(request, 'core/language_detail.html', out)
    except Language.DoesNotExist:
        pass

    # If we can find an alternate name, redirect it.
    try:
        return redirect(AlternateName.objects.get(slug=language).language,
                        permanent=True)
    except AlternateName.DoesNotExist:
        pass
    # fail. Doesn't exist so pop out a 404
    raise Http404
Exemplo n.º 11
0
def language_detail(request, language):
    """
    Show Language Details
    
    Uses a slug to lookup. If the slug is the primary one in the languages table,
        then the details page will be shown
    If nothing is found in the languages table, then the AlternateNames table is 
        checked for a match. If found, then this view will redirect to the canonical slug.
    """
    # if we find the language slug, then render the language detail page.
    try:
        my_lang = Language.objects.get(slug=language)
        out = {
            'language': my_lang,
            'alternatenames': my_lang.alternatename_set.all(),
            'links': my_lang.link_set.all(),
            'attachments': my_lang.attachment_set.all(),
        }
        
        # sources used 
        source_ids = [_['source_id'] for _ in my_lang.lexicon_set.values('source_id').distinct().all()]
        out['sources_used'] = Source.objects.filter(pk__in=source_ids)
        
        # location
        out['location'] = None
        if my_lang.isocode:
            try:
                out['location'] = Location.objects.filter(isocode=my_lang.isocode)[0]
            except (Location.DoesNotExist, IndexError):
                pass  # keep out['location'] as None
                
            
        # load lexicon if installed.
        if 'website.apps.lexicon' in settings.INSTALLED_APPS:
            qset = my_lang.lexicon_set.select_related().all()
            if request.user.is_authenticated():
                out['lexicon_table'] = LanguageLexiconEditTable(qset)
            else:
                out['lexicon_table'] = LanguageLexiconTable(qset)
            
            RequestConfig(request).configure(out['lexicon_table'])
            
            try:
                out['lexicon_table'].paginate(page=request.GET.get('page', 1), per_page=50)
            except EmptyPage: # 404 on a empty page
                raise Http404
            except PageNotAnInteger: # 404 on invalid page number
                raise Http404
        
        # load pronouns
        if 'website.apps.pronouns' in settings.INSTALLED_APPS:
            from website.apps.pronouns.models import Paradigm, Pronoun
            from website.apps.pronouns.tools import add_pronoun_table
            try: 
                out['pronoun'] = Paradigm.objects.filter(language=my_lang)[0]
                out['pronoun_rows'] =  add_pronoun_table(out['pronoun'].pronoun_set.all())
            except IndexError: # no paradigm
                pass
            
        return render(request, 'core/language_detail.html', out)
    except Language.DoesNotExist:
        pass
    
    # If we can find an alternate name, redirect it.
    try:
        return redirect(AlternateName.objects.get(slug=language).language, permanent=True)
    except AlternateName.DoesNotExist:
        pass
    # fail. Doesn't exist so pop out a 404
    raise Http404
 def test_empty(self):
     table = add_pronoun_table(self.pdm.pronoun_set.all(), filter_empty_rows=True)
     assert table == []