Exemple #1
0
def merge(request, word, clade=None):
    form = MergeCognateForm(
        request.POST or None,
        prefix='merge',
        queryset=CognateSet.objects.all(
        )  # needed as we've explicitly set None in the form.
    )

    if request.POST and form.is_valid():
        old = form.cleaned_data['old']
        new = form.cleaned_data['new']

        messages.add_message(request,
                             messages.INFO,
                             'Moving cognate set %r to %r' % (old, new),
                             extra_tags='warning')
        # get the lexical items already in this cognateset
        already = [lex for lex in new.lexicon.all()]

        with reversion.create_revision():
            for cog in old.cognate_set.all():
                if cog.lexicon in already:
                    cog.delete(
                    )  # already got it in this cognate set. Delete the cognate
                else:
                    cog.cognateset = new
                    cog.save()
            old.delete()
    url = reverse('cognacy:do', kwargs={'word': word, 'clade': clade})
    return redirect(url)
Exemple #2
0
def merge(request, word, clade=None):
    form = MergeCognateForm(request.POST or None,
        prefix='merge', 
        queryset=CognateSet.objects.all()  # needed as we've explicitly set None in the form.
    )
    
    if request.POST and form.is_valid():
        old = form.cleaned_data['old']
        new = form.cleaned_data['new']
        
        messages.add_message(request, messages.INFO,
            'Moving cognate set %r to %r' % (old, new),
            extra_tags='warning'
        )
        # get the lexical items already in this cognateset
        already = [lex for lex in new.lexicon.all()]
        
        with reversion.create_revision():
            for cog in old.cognate_set.all():
                if cog.lexicon in already:
                    cog.delete()  # already got it in this cognate set. Delete the cognate
                else:
                    cog.cognateset = new
                    cog.save()
            old.delete()
    url = reverse('cognacy:do', kwargs={'word': word, 'clade': clade})
    return redirect(url)
 def test_error_on_identical_cognate_sets(self):
     cogset_1 = CognateSet.objects.create(protoform='test-1', editor=self.editor)
     form_data = {
         'old': cogset_1.id, 
         'new': cogset_1.id, 
     }
     f = MergeCognateForm(form_data, queryset=CognateSet.objects.all())
     assert not f.is_valid()
 def test_ok(self):
     cogset_1 = CognateSet.objects.create(protoform='test-1', editor=self.editor)
     cogset_2 = CognateSet.objects.create(protoform='test-2', editor=self.editor)
     form_data = {
         'old': cogset_1.id, 
         'new': cogset_2.id, 
     }
     f = MergeCognateForm(form_data, queryset=CognateSet.objects.all())
     assert f.is_valid()
Exemple #5
0
 def test_error_on_identical_cognate_sets(self):
     cogset_1 = CognateSet.objects.create(protoform='test-1',
                                          editor=self.editor)
     form_data = {
         'old': cogset_1.id,
         'new': cogset_1.id,
     }
     f = MergeCognateForm(form_data, queryset=CognateSet.objects.all())
     assert not f.is_valid()
Exemple #6
0
 def test_ok(self):
     cogset_1 = CognateSet.objects.create(protoform='test-1',
                                          editor=self.editor)
     cogset_2 = CognateSet.objects.create(protoform='test-2',
                                          editor=self.editor)
     form_data = {
         'old': cogset_1.id,
         'new': cogset_2.id,
     }
     f = MergeCognateForm(form_data, queryset=CognateSet.objects.all())
     assert f.is_valid()