Ejemplo n.º 1
0
 def xtle_path(self):
     (language_code, project_code, dir_path,
      filename) = split_xtle_path(self.path)
     if language_code and project_code:
         return ("/%s/%s/" % (language_code, project_code))
     elif language_code:
         return "/%s/" % language_code
     elif project_code:
         return "/projects/%s/" % project_code
Ejemplo n.º 2
0
    def get_search_locations_url(self):
        (proj_code, dir_path,
         filename) = split_xtle_path(self.store.xtle_path)[1:]

        return u''.join([
            reverse('xtle-project-translate',
                    args=[proj_code, dir_path, filename]),
            get_editor_filter(search=self.locations, sfields='locations'),
        ])
Ejemplo n.º 3
0
 def unit_translate_url(self):
     if not self.unit:
         return
     store_url = u''.join([
         reverse("xtle-tp-store-translate",
                 args=split_xtle_path(self.unit_xtle_path)),
         get_editor_filter()
     ])
     # eek: unicode mangling
     return ("%s%s" % (store_url, '#unit=%s' % str(self.unit)))
Ejemplo n.º 4
0
 def score_context(self):
     (language_code, project_code, dir_path,
      filename) = split_xtle_path(self.path)
     if language_code and project_code:
         return self.object.translationproject
     elif language_code:
         return Language.objects.get(code=language_code)
     elif project_code:
         return Project.objects.get(code=project_code)
     return ProjectSet(
         Project.objects.for_user(self.user).select_related("directory"))
Ejemplo n.º 5
0
 def reverse_match(self, xtle_path):
     lang_code, __, dir_path, filename = split_xtle_path(xtle_path)
     lang_code = self.lang_mapper.get_upstream_code(lang_code)
     fileparts = os.path.splitext(filename)
     fs_path = self.get_finder().reverse_match(
         lang_code,
         filename=fileparts[0],
         extension=fileparts[1].lstrip("."),
         dir_path=dir_path.strip("/"))
     if fs_path:
         return "/%s" % self.relative_path(fs_path).lstrip("/")
Ejemplo n.º 6
0
    def get_absolute_url(self):
        proj_code = split_xtle_path(self.xtle_path)[1]

        if proj_code is not None:
            pattern_name = 'xtle-project-browse'
            pattern_args = [proj_code, '']
        else:
            pattern_name = 'xtle-projects-browse'
            pattern_args = []

        return reverse(pattern_name, args=pattern_args)
Ejemplo n.º 7
0
 def get_parent_paths(self, xtle_paths):
     paths = set(["/projects/"])
     projects = set()
     for xtle_path in xtle_paths:
         lang_code, proj_code, dir_path, __ = split_xtle_path(xtle_path)
         paths.add("/projects/%s/" % proj_code)
         projects.add(proj_code)
     tps = TranslationProject.objects.filter(
         project__code__in=projects).values_list("language__code",
                                                 flat=True)
     for lang_code in tps.iterator():
         paths.add("/%s/" % lang_code)
     return paths
Ejemplo n.º 8
0
    def get_translate_url(self, **kwargs):
        proj_code, dir_path, filename = split_xtle_path(self.xtle_path)[1:]

        if proj_code is not None:
            pattern_name = 'xtle-project-translate'
            pattern_args = [proj_code, dir_path, filename]
        else:
            pattern_name = 'xtle-projects-translate'
            pattern_args = []

        return u''.join([
            reverse(pattern_name, args=pattern_args),
            get_editor_filter(**kwargs),
        ])
Ejemplo n.º 9
0
    def create_by_path(self,
                       xtle_path,
                       project=None,
                       create_tp=True,
                       create_directory=True,
                       **kwargs):
        from xtle.language.models import Language
        from xtle.project.models import Project

        (lang_code, proj_code, dir_path, filename) = split_xtle_path(xtle_path)

        ext = filename.split(".")[-1]

        if project is None:
            project = Project.objects.get(code=proj_code)
        elif project.code != proj_code:
            raise ValueError("Project must match xtle_path when provided")
        if ext not in project.filetype_tool.valid_extensions:
            raise ValueError("'%s' is not a valid extension for this Project" %
                             ext)
        if create_tp:
            tp, created = (project.translationproject_set.get_or_create(
                language=Language.objects.get(code=lang_code)))
        elif create_directory or not dir_path:
            tp = project.translationproject_set.get(language__code=lang_code)
        if dir_path:
            if not create_directory:
                parent = Directory.objects.get(
                    xtle_path="/".join(["", lang_code, proj_code, dir_path]))
            else:
                parent = tp.directory
                for child in dir_path.strip("/").split("/"):
                    parent, created = Directory.objects.get_or_create(
                        tp=tp, name=child, parent=parent)
        else:
            parent = tp.directory

        store, created = self.get_or_create(name=filename,
                                            parent=parent,
                                            translation_project=tp,
                                            **kwargs)
        return store
Ejemplo n.º 10
0
 def get_parent_paths(self, xtle_paths):
     if set(xtle_paths) == set(["/"]):
         return xtle_paths
     paths = set(["/projects/"])
     for xtle_path in xtle_paths:
         lang_code, proj_code, dir_path, __ = split_xtle_path(xtle_path)
         if proj_code:
             paths.add("/projects/%s/" % proj_code)
         if lang_code:
             paths.add("/%s/" % lang_code)
         if lang_code and proj_code:
             paths.add("/%s/%s/" % (lang_code, proj_code))
         dir_path_parts = dir_path.split("/")
         for i, name in enumerate(dir_path_parts):
             if not name:
                 continue
             paths.add(
                 "/%s/%s/%s/" %
                 (lang_code, proj_code, "/".join(dir_path_parts[:i + 1])))
     return paths
Ejemplo n.º 11
0
 def clean_path(self):
     lang_code, proj_code = split_xtle_path(self.cleaned_data["path"])[:2]
     if not (lang_code or proj_code):
         permission_context = Directory.objects.projects
     elif proj_code and not lang_code:
         try:
             permission_context = Project.objects.select_related(
                 "directory").get(code=proj_code).directory
         except Project.DoesNotExist:
             raise forms.ValidationError("Unrecognized path")
     else:
         # no permission checking on lang translate views
         return self.cleaned_data["path"]
     if self.request_user.is_superuser:
         return self.cleaned_data["path"]
     can_view_path = check_user_permission(self.request_user,
                                           "administrate",
                                           permission_context)
     if can_view_path:
         return self.cleaned_data["path"]
     raise forms.ValidationError("Unrecognized path")
Ejemplo n.º 12
0
 def project_code(self):
     return split_xtle_path(self.context.xtle_path)[1]
Ejemplo n.º 13
0
 def filename(self):
     return split_xtle_path(self.context.xtle_path)[3]
Ejemplo n.º 14
0
 def dir_path(self):
     return split_xtle_path(self.context.xtle_path)[2]
Ejemplo n.º 15
0
 def get_absolute_url(self):
     return reverse('xtle-tp-browse',
                    args=split_xtle_path(self.xtle_path)[:-1])
Ejemplo n.º 16
0
 def get_translate_url(self, **kwargs):
     return u''.join([
         reverse("xtle-tp-translate",
                 args=split_xtle_path(self.xtle_path)[:-1]),
         get_editor_filter(**kwargs)
     ])
Ejemplo n.º 17
0
 def translate_url(self):
     return (u'%s%s' % (reverse(
         "xtle-tp-store-translate", args=split_xtle_path(
             self.xtle_path)), '#unit=%s' % str(self.id)))