当前位置: 首页>>代码示例>>Python>>正文


Python models.Revision类代码示例

本文整理汇总了Python中pootle.core.models.Revision的典型用法代码示例。如果您正苦于以下问题:Python Revision类的具体用法?Python Revision怎么用?Python Revision使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Revision类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_noargs

    def handle_noargs(self, **options):
        if options["restore"]:
            from pootle_store.models import Unit

            Revision.set(Unit.max_revision())

        self.stdout.write("%s" % Revision.get())
开发者ID:likulogy,项目名称:pootle,代码行数:7,代码来源:revision.py

示例2: handle

    def handle(self, **options):
        if (not options['flush_rqdata'] and
            not options['flush_lru'] and
            not options['flush_django_cache'] and
            not options['flush_all']):
            raise CommandError("No options were provided. Use one of "
                               "--django-cache, --rqdata, --lru "
                               "or --all.")

        self.stdout.write('Flushing cache...')

        if options['flush_rqdata'] or options['flush_all']:
            # Flush all rq data, dirty counter and restore Pootle revision
            # value.
            r_con = get_redis_connection('redis')
            r_con.flushdb()
            self.stdout.write('RQ data removed.')
            Revision.set(Unit.max_revision())
            self.stdout.write('Max unit revision restored.')

        if options['flush_django_cache'] or options['flush_all']:
            r_con = get_redis_connection('default')
            r_con.flushdb()
            self.stdout.write('All default Django cache data removed.')

        if options['flush_lru'] or options['flush_all']:
            r_con = get_redis_connection('lru')
            r_con.flushdb()
            self.stdout.write('All lru cache data removed.')
开发者ID:ainslied,项目名称:pootle,代码行数:29,代码来源:flush_cache.py

示例3: fs_plugin_base

def fs_plugin_base(tutorial, tmpdir, settings, system, english, zulu):
    from django.core.cache import caches

    import pootle_fs_pytest

    from pootle.core.models import Revision
    from pootle_store.models import Unit

    caches["exports"].clear()

    Revision.set(Unit.max_revision())

    dir_path = str(tmpdir.dirpath())
    repo_path = os.path.join(dir_path, "__src__")
    src_path = os.path.abspath(
        os.path.join(
            os.path.dirname(pootle_fs_pytest.__file__),
            "data/fs/example_fs"))
    settings.POOTLE_FS_PATH = dir_path
    tutorial_path = os.path.join(dir_path, tutorial.code)
    if os.path.exists(tutorial_path):
        shutil.rmtree(tutorial_path)
    if os.path.exists(repo_path):
        shutil.rmtree(repo_path)
    return tutorial, src_path, repo_path, dir_path
开发者ID:ta2-1,项目名称:pootle_fs,代码行数:25,代码来源:plugin.py

示例4: test_update_set_last_sync_revision

def test_update_set_last_sync_revision(project0_nongnu, tp0, store0, test_fs):
    """Tests setting last_sync_revision after store creation.
    """
    unit = store0.units.first()
    unit.target = "UPDATED TARGET"
    unit.save()

    store0.sync()

    # Store is already parsed and store.last_sync_revision should be equal to
    # max unit revision
    assert store0.last_sync_revision == store0.get_max_unit_revision()

    # store.last_sync_revision is not changed after empty update
    saved_last_sync_revision = store0.last_sync_revision
    store0.updater.update_from_disk()
    assert store0.last_sync_revision == saved_last_sync_revision

    orig = str(store0)
    update_file = test_fs.open(
        "data/po/tutorial/ru/update_set_last_sync_revision_updated.po",
        "r")
    with update_file as sourcef:
        with open(store0.file.path, "wb") as targetf:
            targetf.write(sourcef.read())

    # any non-empty update sets last_sync_revision to next global revision
    next_revision = Revision.get() + 1
    store0.updater.update_from_disk()
    assert store0.last_sync_revision == next_revision

    # store.last_sync_revision is not changed after empty update (even if it
    # has unsynced units)
    item_index = 0
    next_unit_revision = Revision.get() + 1
    dbunit = store0.units.first()
    dbunit.target = "ANOTHER DB TARGET UPDATE"
    dbunit.save()
    assert dbunit.revision == next_unit_revision

    store0.updater.update_from_disk()
    assert store0.last_sync_revision == next_revision

    # Non-empty update sets store.last_sync_revision to next global revision
    # (even the store has unsynced units).  There is only one unsynced unit in
    # this case so its revision should be set next to store.last_sync_revision
    next_revision = Revision.get() + 1

    with open(store0.file.path, "wb") as targetf:
        targetf.write(orig)

    store0.updater.update_from_disk()
    assert store0.last_sync_revision == next_revision
    # Get unsynced unit in DB. Its revision should be greater
    # than store.last_sync_revision to allow to keep this change during
    # update from a file
    dbunit = store0.units[item_index]
    assert dbunit.revision == store0.last_sync_revision + 1
开发者ID:SafaAlfulaij,项目名称:pootle,代码行数:58,代码来源:store.py

示例5: revision

def revision(request, clear_cache):
    """Sets up the cached revision counter for each test call."""
    from pootle.core.models import Revision
    from pootle_store.models import Unit

    if request.node.get_marker("django_db"):
        Revision.set(Unit.max_revision())
    else:
        Revision.initialize()
开发者ID:AshishNamdev,项目名称:pootle,代码行数:9,代码来源:revision.py

示例6: test_update_set_last_sync_revision

def test_update_set_last_sync_revision(ru_update_set_last_sync_revision_po):
    """Tests setting last_sync_revision after store creation.
    """
    store = ru_update_set_last_sync_revision_po

    # Store is already parsed and store.last_sync_revision should be equal to
    # max unit revision
    assert store.last_sync_revision == store.get_max_unit_revision()

    # store.last_sync_revision is not changed after empty update
    saved_last_sync_revision = store.last_sync_revision
    store.update_from_disk()
    assert store.last_sync_revision == saved_last_sync_revision

    dir_path = os.path.join(store.translation_project.project.get_real_path(),
                            store.translation_project.language.code)
    copied_initial_filepath = os.path.join(
        dir_path,
        'update_set_last_sync_revision.po.temp'
    )
    shutil.copy(store.file.path, copied_initial_filepath)
    updated_filepath = os.path.join(
        dir_path,
        'update_set_last_sync_revision_updated.po'
    )
    shutil.copy(updated_filepath, store.file.path)

    # any non-empty update sets last_sync_revision to next global revision
    next_revision = Revision.get() + 1
    store.update_from_disk()
    assert store.last_sync_revision == next_revision

    # store.last_sync_revision is not changed after empty update (even if it
    # has unsynced units)
    item_index = 0
    next_unit_revision = Revision.get() + 1
    dbunit = _update_translation(store, item_index, {'target': u'first'},
                                 sync=False)
    assert dbunit.revision == next_unit_revision
    store.update_from_disk()
    assert store.last_sync_revision == next_revision

    # Non-empty update sets store.last_sync_revision to next global revision
    # (even the store has unsynced units).  There is only one unsynced unit in
    # this case so its revision should be set next to store.last_sync_revision
    next_revision = Revision.get() + 1
    shutil.move(copied_initial_filepath, store.file.path)
    store.update_from_disk()
    assert store.last_sync_revision == next_revision
    # Get unsynced unit in DB. Its revision should be greater
    # than store.last_sync_revision to allow to keep this change during
    # update from a file
    dbunit = store.getitem(item_index)
    assert dbunit.revision == store.last_sync_revision + 1
开发者ID:AshishNamdev,项目名称:pootle,代码行数:54,代码来源:store.py

示例7: _update

    def _update(self, store, user=None, store_revision=None,
                submission_type=None, resolve_conflict=POOTLE_WINS,
                allow_add_and_obsolete=True):
        logging.debug(u"Updating %s", self.target_store.pootle_path)
        old_state = self.target_store.state

        if user is None:
            User = get_user_model()
            user = User.objects.get_system_user()

        update_revision = None
        changes = {}
        try:
            diff = StoreDiff(self.target_store, store, store_revision).diff()
            if diff is not None:
                update_revision = Revision.incr()
                changes = self.update_from_diff(
                    store,
                    store_revision,
                    diff, update_revision,
                    user, submission_type,
                    resolve_conflict,
                    allow_add_and_obsolete)
        finally:
            if old_state < PARSED:
                self.target_store.state = PARSED
                self.target_store.save()
            has_changed = any(x > 0 for x in changes.values())
            if has_changed:
                log(u"[update] %s units in %s [revision: %d]"
                    % (get_change_str(changes),
                       self.target_store.pootle_path,
                       (self.target_store.data.max_unit_revision or 0)))
        return update_revision, changes
开发者ID:ta2-1,项目名称:pootle,代码行数:34,代码来源:updater.py

示例8: toggle_qualitycheck

    def toggle_qualitycheck(self, check_id, false_positive, user):
        check = self.qualitycheck_set.get(id=check_id)

        if check.false_positive == false_positive:
            return

        self.revision = Revision.incr()
        self.save(
            reviewed_by=user)
        check.false_positive = false_positive
        check.save()

        # create submission
        old_value = MUTED
        new_value = UNMUTED
        if false_positive:
            old_value = UNMUTED
            new_value = MUTED

        update_time = make_aware(timezone.now())
        sub = Submission(
            creation_time=update_time,
            translation_project=self.store.translation_project,
            submitter=user,
            field=SubmissionFields.NONE,
            unit=self,
            type=SubmissionTypes.WEB,
            old_value=old_value,
            new_value=new_value,
            quality_check=check)
        sub.save()
开发者ID:claudep,项目名称:pootle,代码行数:31,代码来源:models.py

示例9: revert_units_commented

    def revert_units_commented(self):
        """Revert comments made by user on units to previous comment or else
        just remove the comment.
        """
        stores = set()
        # Revert unit comments where self.user is latest commenter.
        for unit_change in self.user.commented.select_related("unit").iterator():
            unit = unit_change.unit
            stores.add(unit.store)

            # Find comments by other self.users
            comments = unit.get_comments().exclude(submitter=self.user)
            change = {}
            if comments.exists():
                # If there are previous comments by others update the
                # translator_comment, commented_by, and commented_on
                last_comment = comments.latest('pk')
                translator_comment = last_comment.new_value
                change["commented_by_id"] = last_comment.submitter_id
                change["commented_on"] = last_comment.creation_time
                logger.debug("Unit comment reverted: %s", repr(unit))
            else:
                translator_comment = ""
                change["commented_by"] = None
                change["commented_on"] = None
                logger.debug("Unit comment removed: %s", repr(unit))
            unit_change.__class__.objects.filter(id=unit_change.id).update(
                **change)
            unit.__class__.objects.filter(id=unit.id).update(
                translator_comment=translator_comment,
                revision=Revision.incr())
        return stores
开发者ID:ta2-1,项目名称:pootle,代码行数:32,代码来源:utils.py

示例10: _sync_to_pootle

 def _sync_to_pootle(self, merge=False, pootle_wins=None):
     """
     Update Pootle ``Store`` with the parsed FS file.
     """
     tmp_store = self.deserialize()
     if not tmp_store:
         logger.warn("File staged for sync has disappeared: %s", self.path)
         return
     if pootle_wins is None:
         resolve_conflict = (
             self.store_fs.resolve_conflict or SOURCE_WINS)
     elif pootle_wins:
         resolve_conflict = POOTLE_WINS
     else:
         resolve_conflict = SOURCE_WINS
     if merge:
         revision = self.store_fs.last_sync_revision or 0
     else:
         # We set the revision to *anything* higher than the Store's
         # This is analogous to the `overwrite` option in
         # Store.update_from_disk
         revision = Revision.get() + 1
     update_revision, __ = self.store.update(
         tmp_store,
         submission_type=SubmissionTypes.SYSTEM,
         user=self.latest_user,
         store_revision=revision,
         resolve_conflict=resolve_conflict)
     logger.debug("Pulled file: %s", self.path)
     return update_revision
开发者ID:arky,项目名称:pootle,代码行数:30,代码来源:files.py

示例11: test_update_upload_member_user

def test_update_upload_member_user(en_tutorial_po, member):
    update_store(
        en_tutorial_po,
        [("Hello, world", "Hello, world UPDATED")],
        user=member,
        store_revision=Revision.get() + 1)
    assert en_tutorial_po.units[0].submitted_by == member
开发者ID:AshishNamdev,项目名称:pootle,代码行数:7,代码来源:store.py

示例12: handle

    def handle(self, **options):
        last_known_revision = Revision.get()

        if options['after_revision'] is not None:
            after_revision = int(options['after_revision'])
        else:
            after_revision = Store.objects.all().aggregate(
                Max('last_sync_revision'))['last_sync_revision__max'] or -1

        self.stderr.write(
            'Will show languages changed between revisions %s (exclusive) '
            'and %s (inclusive)' %
            (after_revision, last_known_revision)
        )

        # if the requested revision is the same or is greater than the last
        # known one, return nothing
        if after_revision >= last_known_revision:
            self.stderr.write('(no known changes)')
            return

        q = Unit.objects.filter(
            revision__gt=after_revision
        ).values(
            'store__translation_project__language__code',
        ).order_by(
            'store__translation_project__language__code',
        ).distinct()

        languages = q.values_list('store__translation_project__language__code',
                                  flat=True)

        # list languages separated by comma for easy parsing
        print ','.join(languages)
开发者ID:haf,项目名称:pootle,代码行数:34,代码来源:changed_languages.py

示例13: handle

    def handle(self, **options):
        last_known_revision = Revision.get()

        if options["after_revision"] is not None:
            after_revision = int(options["after_revision"])
        else:
            after_revision = Store.objects.all().aggregate(Max("last_sync_revision"))["last_sync_revision__max"] or -1

        self.stderr.write(
            "Will show languages changed between revisions %s (exclusive) "
            "and %s (inclusive)" % (after_revision, last_known_revision)
        )

        # if the requested revision is the same or is greater than the last
        # known one, return nothing
        if after_revision >= last_known_revision:
            self.stderr.write("(no known changes)")
            return

        q = (
            Unit.objects.filter(revision__gt=after_revision)
            .values("store__translation_project__language__code")
            .order_by("store__translation_project__language__code")
            .distinct()
        )

        languages = q.values_list("store__translation_project__language__code", flat=True)

        # list languages separated by comma for easy parsing
        self.stdout.write(",".join(languages))
开发者ID:phlax,项目名称:pootle,代码行数:30,代码来源:changed_languages.py

示例14: revert_units_edited

    def revert_units_edited(self):
        """Revert unit edits made by a user to previous edit.
        """
        stores = set()
        # Revert unit target where user is the last submitter.
        for unit in self.user.submitted.iterator():
            stores.add(unit.store)

            # Find the last submission by different user that updated the
            # unit.target.
            edits = unit.get_edits().exclude(submitter=self.user)

            if edits.exists():
                last_edit = edits.latest("pk")
                unit.target_f = last_edit.new_value
                unit.submitted_by_id = last_edit.submitter_id
                unit.submitted_on = last_edit.creation_time
                logger.debug("Unit edit reverted: %s", repr(unit))
            else:
                # if there is no previous submissions set the target to "" and
                # set the unit.submitted_by to None
                unit.target_f = ""
                unit.submitted_by = None
                unit.submitted_on = unit.creation_time
                logger.debug("Unit edit removed: %s", repr(unit))

            # Increment revision
            unit.revision = Revision.incr()
            unit.save()
        return stores
开发者ID:claudep,项目名称:pootle,代码行数:30,代码来源:utils.py

示例15: revert_units_edited

    def revert_units_edited(self):
        """Revert unit edits made by a user to previous edit.
        """
        stores = set()
        # Revert unit target where user is the last submitter.
        for unit_change in self.user.submitted.select_related("unit").iterator():
            unit = unit_change.unit
            stores.add(unit.store)

            # Find the last submission by different user that updated the
            # unit.target.
            edits = unit.get_edits().exclude(submitter=self.user)
            updates = {}
            unit_updates = {}
            if edits.exists():
                last_edit = edits.latest("pk")
                unit_updates["target_f"] = last_edit.new_value
                updates["submitted_by_id"] = last_edit.submitter_id
                updates["submitted_on"] = last_edit.creation_time
                logger.debug("Unit edit reverted: %s", repr(unit))
            else:
                # if there is no previous submissions set the target to "" and
                # set the unit.change.submitted_by to None
                unit_updates["target_f"] = ""
                updates["submitted_by"] = None
                updates["submitted_on"] = unit.creation_time
                logger.debug("Unit edit removed: %s", repr(unit))

            # Increment revision
            unit_change.__class__.objects.filter(id=unit_change.id).update(
                **updates)
            unit.__class__.objects.filter(id=unit.id).update(
                revision=Revision.incr(),
                **unit_updates)
        return stores
开发者ID:ta2-1,项目名称:pootle,代码行数:35,代码来源:utils.py


注:本文中的pootle.core.models.Revision类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。