Example #1
0
    def resources(self):
        """Returns a list of :cls:`~pootle_app.models.Directory` and
        :cls:`~pootle_store.models.Store` resource paths available for
        this :cls:`~pootle_project.models.Project` across all languages.
        """
        from virtualfolder.models import VirtualFolderTreeItem

        cache_key = make_method_key(self, 'resources', self.code)
        resources = cache.get(cache_key, None)
        if resources is not None:
            return resources

        stores = Store.objects.live().order_by().filter(
            translation_project__project__pk=self.pk)
        dirs = Directory.objects.live().order_by().filter(
            pootle_path__regex=r"^/[^/]*/%s/" % self.code)
        vftis = (VirtualFolderTreeItem.objects.filter(
            vfolder__is_public=True,
            pootle_path__regex=r"^/[^/]*/%s/" %
            self.code) if 'virtualfolder' in settings.INSTALLED_APPS else [])
        resources = sorted(
            {
                to_tp_relative_path(pootle_path)
                for pootle_path in (
                    set(stores.values_list("pootle_path", flat=True))
                    | set(dirs.values_list("pootle_path", flat=True))
                    | set(
                        vftis.values_list("pootle_path", flat=True
                                          ) if vftis else []))
            },
            key=get_path_sortkey)
        cache.set(cache_key, resources, settings.POOTLE_CACHE_TIMEOUT)
        return resources
Example #2
0
    def resources(self):
        """Returns a list of :cls:`~pootle_app.models.Directory` and
        :cls:`~pootle_store.models.Store` resource paths available for
        this :cls:`~pootle_project.models.Project` across all languages.
        """
        from virtualfolder.models import VirtualFolderTreeItem

        cache_key = make_method_key(self, 'resources', self.code)
        resources = cache.get(cache_key, None)
        if resources is not None:
            return resources

        stores = Store.objects.live().order_by().filter(
            translation_project__project__pk=self.pk)
        dirs = Directory.objects.live().order_by().filter(
            pootle_path__regex=r"^/[^/]*/%s/" % self.code)
        vftis = (
            VirtualFolderTreeItem.objects.filter(
                vfolder__is_public=True,
                pootle_path__regex=r"^/[^/]*/%s/" % self.code)
            if 'virtualfolder' in settings.INSTALLED_APPS
            else [])
        resources = sorted(
            {to_tp_relative_path(pootle_path)
             for pootle_path
             in (set(stores.values_list("pootle_path", flat=True))
                 | set(dirs.values_list("pootle_path", flat=True))
                 | set(vftis.values_list("pootle_path", flat=True)
                       if vftis
                       else []))},
            key=get_path_sortkey)
        cache.set(cache_key, resources, settings.POOTLE_CACHE_TIMEOUT)
        return resources
Example #3
0
    def resources(self):
        """Returns a list of :cls:`~pootle_app.models.Directory` and
        :cls:`~pootle_store.models.Store` resource paths available for
        this :cls:`~pootle_project.models.Project` across all languages.
        """
        cache_key = make_method_key(self, 'resources', self.code)

        resources = cache.get(cache_key, None)
        if resources is not None:
            return resources

        logging.debug(u'Cache miss for %s', cache_key)

        resources_path = ''.join(['/%/', self.code, '/%'])

        sql_query = '''
        SELECT pootle_path
        FROM pootle_store_store
        WHERE pootle_path LIKE %s
          UNION
        SELECT pootle_path
        FROM pootle_app_directory
        WHERE pootle_path LIKE %s;
        '''
        cursor = connection.cursor()
        cursor.execute(sql_query, [resources_path, resources_path])
        results = cursor.fetchall()

        # Calculate TP-relative paths and sort them
        resources = sorted({to_tp_relative_path(result[0]) for result in results},
                           key=get_path_sortkey)

        cache.set(cache_key, resources, settings.OBJECT_CACHE_TIMEOUT)

        return resources
Example #4
0
    def resources(self):
        """Returns a list of :cls:`~pootle_app.models.Directory` and
        :cls:`~pootle_store.models.Store` resource paths available for
        this :cls:`~pootle_project.models.Project` across all languages.
        """
        cache_key = make_method_key(self, "resources", self.code)
        resources = cache.get(cache_key, None)
        if resources is not None:
            return resources

        stores = (
            Store.objects.live()
            .order_by()
            .filter(translation_project__project__pk=self.pk)
        )
        dirs = (
            Directory.objects.live()
            .order_by()
            .filter(pootle_path__regex=r"^/[^/]*/%s/" % self.code)
        )
        resources = sorted(
            {
                to_tp_relative_path(pootle_path)
                for pootle_path in (
                    set(stores.values_list("pootle_path", flat=True))
                    | set(dirs.values_list("pootle_path", flat=True))
                )
            },
            key=get_path_sortkey,
        )
        cache.set(cache_key, resources, CACHE_TIMEOUT)
        return resources
Example #5
0
    def path(self):
        """Returns just the path part omitting language and project codes.

        If the `pootle_path` of a :cls:`Store` object `store` is
        `/af/project/dir1/dir2/file.po`, `store.path` will return
        `dir1/dir2/file.po`.
        """
        return to_tp_relative_path(self.pootle_path)
Example #6
0
    def path(self):
        """Returns just the path part omitting language and project codes.

        If the `pootle_path` of a :cls:`Store` object `store` is
        `/af/project/dir1/dir2/file.po`, `store.path` will return
        `dir1/dir2/file.po`.
        """
        return to_tp_relative_path(self.pootle_path)
Example #7
0
    def resources(self):
        """Returns a list of :cls:`~pootle_app.models.Directory` and
        :cls:`~pootle_store.models.Store` resource paths available for
        this :cls:`~pootle_project.models.Project` across all languages.
        """
        cache_key = make_method_key(self, 'resources', self.code)
        resources = cache.get(cache_key, None)
        if resources is not None:
            return resources

        stores = Store.objects.live().order_by().filter(
            translation_project__project__pk=self.pk)
        dirs = Directory.objects.live().order_by().filter(
            pootle_path__regex=r"^/[^/]*/%s/" % self.code)
        resources = sorted(
            {to_tp_relative_path(pootle_path)
             for pootle_path
             in (set(stores.values_list("pootle_path", flat=True))
                 | set(dirs.values_list("pootle_path", flat=True)))},
            key=get_path_sortkey)
        cache.set(cache_key, resources, settings.POOTLE_CACHE_TIMEOUT)
        return resources
Example #8
0
    def resources(self):
        """Returns a list of :cls:`~pootle_app.models.Directory` and
        :cls:`~pootle_store.models.Store` resource paths available for
        this :cls:`~pootle_project.models.Project` across all languages.
        """
        cache_key = make_method_key(self, 'resources', self.code)

        resources = cache.get(cache_key, None)
        if resources is not None:
            return resources

        logging.debug(u'Cache miss for %s', cache_key)

        resources_path = ''.join(['/%/', self.code, '/%'])

        sql_query = '''
        SELECT pootle_path
        FROM pootle_store_store
        WHERE pootle_path LIKE %s
          UNION
        SELECT pootle_path
        FROM pootle_app_directory
        WHERE pootle_path LIKE %s;
        '''
        cursor = connection.cursor()
        cursor.execute(sql_query, [resources_path, resources_path])
        results = cursor.fetchall()

        # Calculate TP-relative paths and sort them
        resources = sorted(
            {to_tp_relative_path(result[0])
             for result in results},
            key=get_path_sortkey)

        cache.set(cache_key, resources, settings.OBJECT_CACHE_TIMEOUT)

        return resources
Example #9
0
 def filename(self):
     return to_tp_relative_path(self.pootle_path)
Example #10
0
def test_store_path(store0):
    assert store0.path == to_tp_relative_path(store0.pootle_path)
Example #11
0
 def path(self):
     """Returns just the path part omitting language and project codes."""
     return to_tp_relative_path(self.pootle_path)
Example #12
0
 def path(self):
     """Returns just the path part omitting language and project codes."""
     return to_tp_relative_path(self.pootle_path)
Example #13
0
def test_store_path(store0):
    assert store0.path == to_tp_relative_path(store0.pootle_path)