示例#1
0
    def save(self, *args, **kwargs):
        '''
        Save wrapper which updates backend repository and regenerates
        translation data.
        '''
        self.set_default_branch()

        # Detect if VCS config has changed (so that we have to pull the repo)
        changed_git = True
        changed_setup = False
        if self.id:
            old = SubProject.objects.get(pk=self.id)
            changed_git = (
                (old.repo != self.repo) or
                (old.branch != self.branch) or
                (old.filemask != self.filemask)
            )
            changed_setup = (
                (old.file_format != self.file_format) or
                (old.edit_template != self.edit_template) or
                (old.template != self.template)
            )
            # Detect slug changes and rename git repo
            self.check_rename(old)

        # Remove leading ./ from paths
        self.filemask = cleanup_path(self.filemask)
        self.template = cleanup_path(self.template)
        extra_files = [
            cleanup_path(x.strip()) for x in self.extra_commit_file.split('\n')
        ]
        self.extra_commit_file = '\n'.join([x for x in extra_files if x])

        # Save/Create object
        super(SubProject, self).save(*args, **kwargs)

        # Configure git repo if there were changes
        if changed_git:
            self.sync_git_repo()

        # Rescan for possibly new translations if there were changes, needs to
        # be done after actual creating the object above
        if changed_setup:
            self.create_translations(force=True)
        elif changed_git:
            self.create_translations()
示例#2
0
    def save(self, *args, **kwargs):
        '''
        Save wrapper which updates backend repository and regenerates
        translation data.
        '''
        self.set_default_branch()

        # Detect if VCS config has changed (so that we have to pull the repo)
        changed_git = True
        changed_setup = False
        if self.id:
            old = SubProject.objects.get(pk=self.id)
            changed_git = (
                (old.repo != self.repo) or
                (old.branch != self.branch) or
                (old.filemask != self.filemask)
            )
            changed_setup = (
                (old.file_format != self.file_format) or
                (old.edit_template != self.edit_template) or
                (old.template != self.template)
            )
            # Detect slug changes and rename git repo
            self.check_rename(old)

        # Configure git repo if there were changes
        if changed_git:
            self.sync_git_repo()

        # Remove leading ./ from paths
        self.filemask = cleanup_path(self.filemask)
        self.template = cleanup_path(self.template)
        self.extra_commit_file = cleanup_path(self.extra_commit_file)

        # Save/Create object
        super(SubProject, self).save(*args, **kwargs)

        # Rescan for possibly new translations if there were changes, needs to
        # be done after actual creating the object above
        if changed_setup:
            self.create_translations(force=True)
        elif changed_git:
            self.create_translations()
示例#3
0
def validate_filename(value):
    if "../" in value or "..\\" in value:
        raise ValidationError(
            _("The filename can not contain reference to a parent directory."))
    if os.path.isabs(value):
        raise ValidationError(_("The filename can not be an absolute path."))

    cleaned = cleanup_path(value)
    if value != cleaned:
        raise ValidationError(
            _("The filename should be as simple as possible. "
              "Maybe you want to use: {}").format(cleaned))
示例#4
0
 def test_double_slash(self):
     self.assertEqual(cleanup_path("foo//*.po"), "foo/*.po")
示例#5
0
 def test_slash(self):
     self.assertEqual(cleanup_path("/*.po"), "*.po")
示例#6
0
 def test_mixed(self):
     self.assertEqual(cleanup_path("./../*.po"), "*.po")
示例#7
0
 def test_current(self):
     self.assertEqual(cleanup_path("./*.po"), "*.po")
示例#8
0
 def test_relative(self):
     self.assertEqual(cleanup_path("../*.po"), "*.po")