changeset 485:9836541b0509 celery

added limit for showing pygemntized source codes larger than 250kb.
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 18 Sep 2010 00:50:54 +0200
parents d3f701d912bd
children 5c376ac2d4c9
files pylons_app/config/routing.py pylons_app/controllers/files.py pylons_app/templates/files/files_annotate.html pylons_app/templates/files/files_source.html
diffstat 4 files changed, 34 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/config/routing.py	Fri Sep 17 23:57:22 2010 +0200
+++ b/pylons_app/config/routing.py	Sat Sep 18 00:50:54 2010 +0200
@@ -130,7 +130,7 @@
                 controller='changeset', revision='tip',
                 conditions=dict(function=check_repo))
     map.connect('raw_changeset_home', '/{repo_name:.*}/raw-changeset/{revision}',
-                controller='changeset',action='raw_changeset', revision='tip',
+                controller='changeset', action='raw_changeset', revision='tip',
                 conditions=dict(function=check_repo))
     map.connect('summary_home', '/{repo_name:.*}/summary',
                 controller='summary', conditions=dict(function=check_repo))
@@ -148,9 +148,12 @@
     map.connect('files_diff_home', '/{repo_name:.*}/diff/{f_path:.*}',
                 controller='files', action='diff', revision='tip', f_path='',
                 conditions=dict(function=check_repo))
-    map.connect('files_raw_home', '/{repo_name:.*}/rawfile/{revision}/{f_path:.*}',
+    map.connect('files_rawfile_home', '/{repo_name:.*}/rawfile/{revision}/{f_path:.*}',
                 controller='files', action='rawfile', revision='tip', f_path='',
                 conditions=dict(function=check_repo))
+    map.connect('files_raw_home', '/{repo_name:.*}/raw/{revision}/{f_path:.*}',
+                controller='files', action='raw', revision='tip', f_path='',
+                conditions=dict(function=check_repo))
     map.connect('files_annotate_home', '/{repo_name:.*}/annotate/{revision}/{f_path:.*}',
                 controller='files', action='annotate', revision='tip', f_path='',
                 conditions=dict(function=check_repo))    
--- a/pylons_app/controllers/files.py	Fri Sep 17 23:57:22 2010 +0200
+++ b/pylons_app/controllers/files.py	Sat Sep 18 00:50:54 2010 +0200
@@ -45,6 +45,7 @@
                                    'repository.admin')       
     def __before__(self):
         super(FilesController, self).__before__()
+        c.file_size_limit = 250 * 1024 #limit of file size to display
 
     def index(self, repo_name, revision, f_path):
         hg_model = HgModel()
@@ -76,7 +77,6 @@
                              revision=next_rev, f_path=f_path)   
                     
             c.changeset = repo.get_changeset(revision)
-
                         
             c.cur_rev = c.changeset.raw_id
             c.rev_nr = c.changeset.revision
@@ -96,6 +96,14 @@
         response.content_disposition = 'attachment; filename=%s' \
                                                     % f_path.split('/')[-1] 
         return file_node.content
+
+    def raw(self, repo_name, revision, f_path):
+        hg_model = HgModel()
+        c.repo = hg_model.get_repo(c.repo_name)
+        file_node = c.repo.get_changeset(revision).get_node(f_path)
+        response.content_type = 'text/plain'
+        
+        return file_node.content
     
     def annotate(self, repo_name, revision, f_path):
         hg_model = HgModel()
--- a/pylons_app/templates/files/files_annotate.html	Fri Sep 17 23:57:22 2010 +0200
+++ b/pylons_app/templates/files/files_annotate.html	Sat Sep 18 00:50:54 2010 +0200
@@ -23,7 +23,7 @@
     </div>
     <div class="table">
 		<div id="files_data">
-			<h2>${_('Location')}: ${h.files_breadcrumbs(c.repo_name,c.cur_rev,c.file.path)}</h2>
+			<h3 class="files_location">${_('Location')}: ${h.files_breadcrumbs(c.repo_name,c.cur_rev,c.file.path)}</h3>
 			<dl class="overview">
 				<dt>${_('Last revision')}</dt>
 				<dd>${h.link_to("r%s:%s" % (c.file.last_changeset.revision,c.file.last_changeset._short),
@@ -33,8 +33,10 @@
 				<dt>${_('Options')}</dt>
 				<dd>${h.link_to(_('show source'),
 						h.url('files_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}  
+					/ ${h.link_to(_('show as raw'),
+						h.url('files_raw_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}
 					/ ${h.link_to(_('download as raw'),
-						h.url('files_raw_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}
+						h.url('files_rawfile_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}
 				</dd>				
 			</dl>
 			<div id="body" class="codeblock">
@@ -43,7 +45,12 @@
 					<div class="commit">"${c.file_msg}"</div>
 				</div>
 				<div class="code-body">
-					${h.pygmentize_annotation(c.file,linenos=True,anchorlinenos=True,lineanchors='S',cssclass="code-highlight")}
+					% if c.file.size < c.file_size_limit:
+						${h.pygmentize_annotation(c.file,linenos=True,anchorlinenos=True,lineanchors='S',cssclass="code-highlight")}
+					%else:
+						${_('File is to big to display')} ${h.link_to(_('show as raw'),
+						h.url('files_raw_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}
+					%endif				
 				</div>
 			</div>
 		</div>    
--- a/pylons_app/templates/files/files_source.html	Fri Sep 17 23:57:22 2010 +0200
+++ b/pylons_app/templates/files/files_source.html	Sat Sep 18 00:50:54 2010 +0200
@@ -8,9 +8,11 @@
 	<dd>${h.format_byte_size(c.files_list.size,binary=True)}</dd>
 	<dt>${_('Options')}</dt>
 	<dd>${h.link_to(_('show annotation'),
-			h.url('files_annotate_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}  
+			h.url('files_annotate_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}
+		 / ${h.link_to(_('show as raw'),
+			h.url('files_raw_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}			
 		 / ${h.link_to(_('download as raw'),
-			h.url('files_raw_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}
+			h.url('files_rawfile_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}
 	</dd>
 	<dt>${_('History')}</dt>
 	<dd>
@@ -32,7 +34,12 @@
 		<div class="commit">"${c.files_list.last_changeset.message}"</div>
 	</div>
 	<div class="code-body">
-		${h.pygmentize(c.files_list,linenos=True,anchorlinenos=True,lineanchors='S',cssclass="code-highlight")}
+		% if c.files_list.size < c.file_size_limit:
+			${h.pygmentize(c.files_list,linenos=True,anchorlinenos=True,lineanchors='S',cssclass="code-highlight")}
+		%else:
+			${_('File is to big to display')} ${h.link_to(_('show as raw'),
+			h.url('files_raw_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.f_path))}
+		%endif
 	</div>
 </div>