Changeset - 5b57295601b6
[Not reviewed]
default
0 2 1
Marcin Kuzminski - 16 years ago 2010-04-25 01:19:21
marcin@python-works.com
Updated basic files browser with, pygments
3 files changed with 114 insertions and 8 deletions:
0 comments (0 inline, 0 general)
pylons_app/config/routing.py
Show inline comments
 
@@ -37,7 +37,7 @@ def make_map(config):
 
    map.connect('branches_home', '/{repo_name}/branches', controller='branches')
 
    map.connect('tags_home', '/{repo_name}/tags', controller='tags')
 
    map.connect('graph_home', '/{repo_name}/graph/{revision}', controller='graph', revision='tip')    
 
    map.connect('files_home', '/{repo_name}/files/{revision}/{path_info:.*}', controller='files', revision='tip', path_info='')
 
    map.connect('files_home', '/{repo_name}/files/{revision}/{f_path:.*}', controller='files', revision='tip', f_path='')
 
    
 

	
 
    return map
pylons_app/controllers/files.py
Show inline comments
 
import logging
 

	
 
from pylons import request, response, session, tmpl_context as c, url
 
from pylons import request, response, session, tmpl_context as c, url, config, app_globals as g
 
from pylons.controllers.util import abort, redirect
 

	
 
from pylons_app.lib.base import BaseController, render
 

	
 
from pylons_app.lib.utils import get_repo_slug
 
from pylons_app.model.hg_model import HgModel
 
log = logging.getLogger(__name__)
 

	
 
class FilesController(BaseController):
 
    def __before__(self):
 
        c.repos_prefix = config['repos_name']
 
        c.staticurl = g.statics
 
        c.repo_name = get_repo_slug(request)
 

	
 
    def index(self):
 
        # Return a rendered template
 
        #return render('/files.mako')
 
        # or, return a string
 
        return 'Hello World'
 
    def index(self, repo_name, revision, f_path):
 
        hg_model = HgModel()
 
        c.repo = repo = hg_model.get_repo(c.repo_name)
 
        c.cur_rev = revision
 
        c.f_path = f_path
 
        c.changeset = repo.get_changeset(repo._get_revision('tip'))
 
        
 
        
 
        c.files_list = c.changeset.get_node(f_path)
 
        
 
        return render('/files.html')
pylons_app/templates/files.html
Show inline comments
 
new file 100644
 
<%inherit file="base/base.html"/>
 

	
 
<%def name="title()">
 
    ${_('Repository managment')}
 
</%def>
 
<%def name="breadcrumbs()">
 
    ${h.link_to(u'Home',h.url('/'))}
 
    / 
 
    ${h.link_to(c.repo_name,h.url('files_home',repo_name=c.repo_name))}
 
    /
 
    ${_('files')}
 
</%def>
 
<%def name="page_nav()">
 
        <form action="log">
 
            <dl class="search">
 
                <dt><label>Search: </label></dt>
 
                <dd><input type="text" name="rev" /></dd>
 
            </dl>
 
        </form>
 

	
 
		${self.menu('files')}     
 
</%def>
 
<%def name="css()">
 
<link rel="stylesheet" href="/css/style-monoblue_custom.css" type="text/css" />
 
<link rel="stylesheet" href="/css/pygments.css" type="text/css" />
 
</%def>
 
<%def name="main()">
 

	
 
    <h2 class="no-link no-border">${_('Files')}</h2>
 
	<div id="files_data">
 
		<h2>${_('File')}: ${c.repo_name}/${c.f_path}</h2>
 
		%if c.files_list.is_dir():
 
        <table class="code-browser">
 
            <thead>
 
                <tr>
 
                    <th class="width-50 lefted">${_('Name')}</th>
 
                    <th class="width-10 righted">${_('Size')}</th>
 
                    <th class="width-10 righted">${_('Revision')}</th>
 
                    <th class="width-15 righted">${_('Last modified')}</th>
 
                    <th class="width-15 righted">${_('Last commiter')}</th>
 
                </tr>
 
            </thead>
 
            	<tr>
 
            		% if c.files_list.parent:
 
            		<td colspan="5" class="browser-dir">
 
            		${h.link_to('..',h.url('files_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.files_list.parent))}
 
            		</td>
 
            		%endif
 
            	</tr>
 
					<%def name="file_class(node)">
 
						%if node.is_file():
 
							browser-file
 
						%else:
 
							browser-dir
 
						%endif
 
					</%def>
 
			
 

	
 
	            %for cnt,node in enumerate(c.files_list):
 
					<tr class="parity${cnt%2}">
 
	
 
	                    <td class="${file_class(node)}">
 
							${h.link_to(node.name,h.url('files_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=node.path),class_='file or dir')}
 
	                    </td>
 
	                    <td>
 
	                        %if node.is_file():
 
	                    		${h.filesizeformat(node.size)}
 
	                    	%endif
 
	                    </td>
 
	                    <td>
 
	                    	%if node.is_file():
 
	                    		${node.last_changeset.revision}
 
	                    	%endif
 
	                    </td>
 
	                    <td>
 
	                    	%if node.is_file():
 
	                    		${node.last_changeset.date}
 
	                    	%endif
 
	                    </td>
 
	                    <td>
 
	                    	%if node.is_file():
 
	                    		${node.last_changeset.author}
 
	                    	%endif                    
 
	                    	
 
	                    </td>
 
					</tr>
 
				%endfor
 
			</table>
 
			%else:
 
				<div id="body" class="codeblock">
 
				${h.pygmentize(c.files_list.content,linenos=True,anchorlinenos=True,cssclass="code-highlight")}
 
				</div>				
 
			%endif
 
	</div>
 
</%def>    
 
\ No newline at end of file
0 comments (0 inline, 0 general)