Changeset - a4e1b955fe07
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 15 years ago 2011-03-30 12:59:49
marcin@python-works.com
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Thank You googlebot :)
1 file changed with 31 insertions and 23 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/files.py
Show inline comments
 
@@ -71,12 +71,35 @@ class FilesController(BaseRepoController
 
            redirect(h.url('summary_home', repo_name=repo_name))
 

	
 
        except RepositoryError, e:
 
            h.flash(str(e), category='warning')
 
            redirect(h.url('files_home', repo_name=repo_name, revision='tip'))
 

	
 

	
 
    def __get_filenode_or_redirect(self, repo_name, cs, path):
 
        """
 
        Returns file_node, if error occurs or given path is directory,
 
        it'll redirect to top level path
 
        
 
        :param repo_name: repo_name
 
        :param cs: given changeset
 
        :param path: path to lookup
 
        """
 

	
 

	
 
        try:
 
            file_node = cs.get_node(path)
 
            if file_node.is_dir():
 
                raise RepositoryError('given path is a directory')
 
        except RepositoryError, e:
 
            h.flash(str(e), category='warning')
 
            redirect(h.url('files_home', repo_name=repo_name,
 
                           revision=cs.raw_id))
 

	
 
        return file_node
 

	
 
    def index(self, repo_name, revision, f_path):
 
        #reditect to given revision from form if given
 
        post_revision = request.POST.get('at_rev', None)
 
        if post_revision:
 
            cs = self.__get_cs_or_redirect(revision, repo_name)
 
            redirect(url('files_home', repo_name=c.repo_name,
 
@@ -106,13 +129,13 @@ class FilesController(BaseRepoController
 
                     revision=next_rev.raw_id, f_path=f_path)
 
            if c.branch:
 
                c.url_next += '?branch=%s' % c.branch
 
        except (ChangesetDoesNotExistError, VCSError):
 
            c.url_next = '#'
 

	
 
        #files
 
        #files or dirs
 
        try:
 
            c.files_list = c.changeset.get_node(f_path)
 
            c.file_history = self._get_history(c.rhodecode_repo,
 
                                               c.files_list, f_path)
 
        except RepositoryError, e:
 
            h.flash(str(e), category='warning')
 
@@ -121,45 +144,30 @@ class FilesController(BaseRepoController
 

	
 

	
 
        return render('files/files.html')
 

	
 
    def rawfile(self, repo_name, revision, f_path):
 
        cs = self.__get_cs_or_redirect(revision, repo_name)
 
        try:
 
            file_node = cs.get_node(f_path)
 
        except RepositoryError, e:
 
            h.flash(str(e), category='warning')
 
            redirect(h.url('files_home', repo_name=repo_name,
 
                           revision=cs.raw_id))
 
        file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path)
 

	
 
        fname = f_path.split('/')[-1].encode('utf8', 'replace')
 
        response.content_disposition = 'attachment; filename=%s' % \
 
            f_path.split('/')[-1].encode('utf8', 'replace')
 

	
 
        response.content_type = file_node.mimetype
 
        response.content_disposition = 'attachment; filename=%s' % fname
 
        return file_node.content
 

	
 
    def raw(self, repo_name, revision, f_path):
 
        cs = self.__get_cs_or_redirect(revision, repo_name)
 
        try:
 
            file_node = cs.get_node(f_path)
 
        except RepositoryError, e:
 
            h.flash(str(e), category='warning')
 
            redirect(h.url('files_home', repo_name=repo_name,
 
                           revision=cs.raw_id))
 
        file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path)
 

	
 
        response.content_type = 'text/plain'
 

	
 
        return file_node.content
 

	
 
    def annotate(self, repo_name, revision, f_path):
 
        cs = self.__get_cs_or_redirect(revision, repo_name)
 
        try:
 
            c.file = cs.get_node(f_path)
 
        except RepositoryError, e:
 
            h.flash(str(e), category='warning')
 
            redirect(h.url('files_home', repo_name=repo_name,
 
                           revision=cs.raw_id))
 
        c.file = self.__get_filenode_or_redirect(repo_name, cs, f_path)
 

	
 
        c.file_history = self._get_history(c.rhodecode_repo,
 
                                           c.file, f_path)
 
        c.cs = cs
 
        c.f_path = f_path
 

	
 
@@ -265,13 +273,13 @@ class FilesController(BaseRepoController
 

	
 
        if not c.cur_diff:
 
            c.no_changes = True
 
        return render('files/file_diff.html')
 

	
 
    def _get_history(self, repo, node, f_path):
 
        if not node.kind is NodeKind.FILE:
 
        if not node.is_file():
 
            return []
 
        changesets = node.history
 
        hist_l = []
 

	
 
        changesets_group = ([], _("Changesets"))
 
        branches_group = ([], _("Branches"))
0 comments (0 inline, 0 general)