Ejemplo n.º 1
0
 def contrib_log(sent_id, tran_id, action):
     return Contributions(sentence_id=sent_id,
                          translation_id=tran_id,
                          action=action,
                          type='link',
                          datetime=now(),
                          user_id=cls.bot.id)
Ejemplo n.º 2
0
    def log_and_flag_sents_del(cls, main_id, ids, sents):
        sents = list(sents)
        contribs = []
        flags = []

        for sent in sents:
            contribs.append(Contributions(
                sentence_id=sent.id,
                sentence_lang=sent.lang,
                text=sent.text,
                action='delete',
                datetime=now(),
                type='sentence',
                user_id=cls.bot.id if hasattr(cls, 'bot') else 0,
                ))
            flags.append(ReindexFlags(
                sentence_id=sent.id,
                lang=sent.lang,
                indexed=0,
                type='removal',
                ))

        if not cls.dry:
            Contributions.objects.bulk_create(contribs)
            ReindexFlags.objects.bulk_create(flags)

        cls.log_entry(main_id, ids, 'delete Sentences', 'delete', 'sentence_id', sents)
        cls.log_entry(main_id, ids, 'log_deletion Contributions', 'insert', 'sentence_id', contribs)
        cls.log_entry(main_id, ids, 'flag_deleted ReindexFlags', 'insert', 'sentence_id', flags)
Ejemplo n.º 3
0
    def log_sents_del(cls, main_id, ids, sents):
        sents = list(sents)
        logs = []

        for sent in sents:
            logs.append(Contributions(
                sentence_id=sent.id,
                sentence_lang=sent.lang,
                text=sent.text,
                action='delete',
                datetime=now(),
                type='sentence',
                user_id=cls.bot.id if hasattr(cls, 'bot') else 0,
                ))

        if not cls.dry:
            Contributions.objects.bulk_create(logs)

        cls.log_entry(main_id, ids, 'delete Sentences', 'delete', 'sentence_id', sents)
        cls.log_entry(main_id, ids, 'log_deletion Contributions', 'insert', 'sentence_id', logs)
Ejemplo n.º 4
0
def sents(db, request):

    # no owner, no audio, no correctness 1-4
    Sentences(text='Normal, not duplicated.',
              lang='eng',
              modified=datetime(2014, 1, 1)).save()
    for i in xrange(3):
        Sentences(text='Normal, duplicated.',
                  lang='eng',
                  modified=datetime(2014, 1, 1)).save()

    # has owner 5-8
    Sentences(text='Has owner, not duplicated.',
              lang='eng',
              user_id=1,
              modified=datetime(2014, 1, 2)).save()
    for i in xrange(2):
        Sentences(text='Has owner, duplicated.',
                  lang='eng',
                  modified=datetime(2014, 1, 2)).save()
    Sentences(text='Has owner, duplicated.',
              lang='eng',
              user_id=1,
              modified=datetime(2014, 1, 2)).save()

    # has audio 9-12
    Sentences(text='Has audio, not duplicated.',
              lang='eng',
              hasaudio='shtooka',
              modified=datetime(2014, 1, 3)).save()
    for i in xrange(2):
        Sentences(text='Has audio, duplicated.',
                  lang='eng',
                  modified=datetime(2014, 1, 3)).save()
    Sentences(text='Has audio, duplicated.',
              lang='eng',
              hasaudio='shtooka',
              modified=datetime(2014, 1, 3)).save()

    # correctness -1  13-16
    Sentences(text='Correctness -1, not duplicated.',
              lang='eng',
              correctness=-1,
              modified=datetime(2014, 1, 4)).save()
    for i in xrange(2):
        Sentences(text='Correctness -1, duplicated.',
                  lang='eng',
                  modified=datetime(2014, 1, 4)).save()
    Sentences(text='Correctness -1, duplicated.',
              lang='eng',
              correctness=-1,
              modified=datetime(2014, 1, 4)).save()

    # has owner, has audio, correctness -1  17-21
    Sentences(text='Has owner, Has audio, Correctness -1, not duplicated.',
              lang='eng',
              user_id=1,
              hasaudio='shtooka',
              correctness=-1,
              modified=datetime(2014, 1, 5)).save()
    Sentences(text='Has owner, Has audio, Correctness -1 duplicated.',
              lang='eng',
              modified=datetime(2014, 1, 5)).save()
    Sentences(text='Has owner, Has audio, Correctness -1 duplicated.',
              lang='eng',
              user_id=1,
              modified=datetime(2014, 1, 5)).save()
    Sentences(text='Has owner, Has audio, Correctness -1 duplicated.',
              lang='eng',
              hasaudio='shtooka',
              modified=datetime(2014, 1, 5)).save()
    Sentences(text='Has owner, Has audio, Correctness -1 duplicated.',
              lang='eng',
              correctness=-1,
              modified=datetime(2014, 1, 5)).save()

    for i in xrange(6, 8 + 1):
        SentenceComments(sentence_id=i,
                         text='Comment on ' + str(i),
                         user_id=1,
                         created=datetime.now(),
                         hidden=0).save()

    SentencesTranslations(sentence_id=6, translation_id=9, distance=1).save()
    SentencesTranslations(sentence_id=9, translation_id=6, distance=1).save()
    SentencesTranslations(sentence_id=7, translation_id=10, distance=1).save()
    SentencesTranslations(sentence_id=10, translation_id=7, distance=1).save()

    TagsSentences(tag_id=1,
                  sentence_id=6,
                  user_id=1,
                  added_time=datetime.now()).save()
    TagsSentences(tag_id=2,
                  sentence_id=7,
                  user_id=1,
                  added_time=datetime.now()).save()
    TagsSentences(tag_id=3,
                  sentence_id=8,
                  user_id=1,
                  added_time=datetime.now()).save()

    SentencesSentencesLists(sentences_list_id=1, sentence_id=6).save()
    SentencesSentencesLists(sentences_list_id=2, sentence_id=7).save()
    SentencesSentencesLists(sentences_list_id=3, sentence_id=8).save()

    FavoritesUsers(user_id=1, favorite_id=6).save()
    FavoritesUsers(user_id=2, favorite_id=7).save()
    FavoritesUsers(user_id=3, favorite_id=8).save()

    SentenceAnnotations(meaning_id=1,
                        text='',
                        modified=datetime.now(),
                        user_id=1,
                        sentence_id=6).save()
    SentenceAnnotations(meaning_id=2,
                        text='',
                        modified=datetime.now(),
                        user_id=1,
                        sentence_id=7).save()
    SentenceAnnotations(meaning_id=3,
                        text='',
                        modified=datetime.now(),
                        user_id=1,
                        sentence_id=8).save()

    SentenceAnnotations(meaning_id=10,
                        text='',
                        modified=datetime.now(),
                        user_id=1,
                        sentence_id=13).save()
    SentenceAnnotations(meaning_id=11,
                        text='',
                        modified=datetime.now(),
                        user_id=1,
                        sentence_id=14).save()
    SentenceAnnotations(meaning_id=12,
                        text='',
                        modified=datetime.now(),
                        user_id=1,
                        sentence_id=15).save()

    Contributions(text='Logs for 6',
                  action='update',
                  user_id=1,
                  datetime=datetime.now(),
                  type='sentence',
                  sentence_id=6).save()
    Contributions(text='Logs for 6',
                  action='insert',
                  user_id=1,
                  datetime=datetime.now(),
                  type='link',
                  sentence_id=6,
                  translation_id=9).save()
    Contributions(text='Logs for 7',
                  action='insert',
                  user_id=1,
                  datetime=datetime.now(),
                  type='sentence',
                  sentence_id=7).save()
    Contributions(text='',
                  action='insert',
                  user_id=1,
                  datetime=datetime.now(),
                  type='sentence',
                  sentence_id=8).save()
    Contributions(text='Unknown datetime record',
                  action='update',
                  user_id=1,
                  datetime=None,
                  type='sentence',
                  sentence_id=8).save()

    Wall(owner=1,
         content='test post',
         date=datetime.utcnow(),
         title='',
         hidden=0,
         lft=1,
         rght=2).save()

    if request.config.option.mysql:

        def fin():
            conn = connections['default']

            def clean_up(model):
                Model = get_model('tatoeba2.' + model)
                Model.objects.all().delete()
                conn.cursor().execute('TRUNCATE TABLE ' +
                                      Model._meta.db_table + ';')
                conn.cursor().execute('ALTER TABLE ' + Model._meta.db_table +
                                      ' AUTO_INCREMENT = 1;')

            clean_up('Sentences')
            clean_up('SentencesTranslations')
            clean_up('SentenceComments')
            clean_up('TagsSentences')
            clean_up('SentencesSentencesLists')
            clean_up('FavoritesUsers')
            clean_up('Contributions')
            clean_up('Users')
            clean_up('Wall')
            clean_up('SentenceAnnotations')

        request.addfinalizer(fin)