Changeset - 8d0858376163
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 15 years ago 2011-02-27 03:24:04
marcin@python-works.com
fixed problem with rawfile content_disposition attachment,
webob assumes that file is encoded with iso, and we use utf8 in rhodecode
1 file changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/files.py
Show inline comments
 
@@ -91,99 +91,99 @@ class FilesController(BaseRepoController
 
            #prev link
 
            try:
 
                prev_rev = c.rhodecode_repo.get_changeset(cur_rev).prev(c.branch).raw_id
 
                c.url_prev = url('files_home', repo_name=c.repo_name,
 
                             revision=prev_rev, f_path=f_path)
 
                if c.branch:
 
                    c.url_prev += '?branch=%s' % c.branch
 
            except (ChangesetDoesNotExistError, VCSError):
 
                c.url_prev = '#'
 

	
 
            #next link
 
            try:
 
                next_rev = c.rhodecode_repo.get_changeset(cur_rev).next(c.branch).raw_id
 
                c.url_next = url('files_home', repo_name=c.repo_name,
 
                         revision=next_rev, f_path=f_path)
 
                if c.branch:
 
                    c.url_next += '?branch=%s' % c.branch
 
            except (ChangesetDoesNotExistError, VCSError):
 
                c.url_next = '#'
 

	
 
            #files
 
            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')
 
                redirect(h.url('files_home', repo_name=repo_name, revision=revision))
 

	
 
        except EmptyRepositoryError, e:
 
            h.flash(_('There are no files yet'), category='warning')
 
            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'))
 

	
 

	
 

	
 
        return render('files/files.html')
 

	
 
    def rawfile(self, repo_name, revision, f_path):
 
        cs = self.__get_cs(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))
 

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

	
 
    def raw(self, repo_name, revision, f_path):
 
        cs = self.__get_cs(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))
 

	
 
        response.content_type = 'text/plain'
 

	
 
        return file_node.content
 

	
 
    def annotate(self, repo_name, revision, f_path):
 
        cs = self.__get_cs(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_history = self._get_history(c.rhodecode_repo, c.file, f_path)
 
        c.cs = cs
 
        c.f_path = f_path
 

	
 
        return render('files/files_annotate.html')
 

	
 
    def archivefile(self, repo_name, fname):
 

	
 
        fileformat = None
 
        revision = None
 
        ext = None
 

	
 
        for a_type, ext_data in ARCHIVE_SPECS.items():
 
            archive_spec = fname.split(ext_data[1])
 
            if len(archive_spec) == 2 and archive_spec[1] == '':
 
                fileformat = a_type or ext_data[1]
 
                revision = archive_spec[0]
 
                ext = ext_data[1]
 

	
 
        try:
 
            dbrepo = RepoModel().get_by_repo_name(repo_name)
 
            if dbrepo.enable_downloads is False:
 
                return _('downloads disabled')
 

	
 
            cs = c.rhodecode_repo.get_changeset(revision)
 
            content_type = ARCHIVE_SPECS[fileformat][0]
0 comments (0 inline, 0 general)