Changeset - b3c93efd1c97
[Not reviewed]
default
0 4 0
Marcin Kuzminski - 16 years ago 2010-05-12 10:29:41
marcin@python-works.com
Updated template for summary (archives links)
added nex prev revision to file browser.
updated logic in files to implement next and prev revison switch
4 files changed with 38 insertions and 18 deletions:
0 comments (0 inline, 0 general)
pylons_app/config/routing.py
Show inline comments
 
@@ -20,34 +20,37 @@ def make_map(config):
 

	
 
    # CUSTOM ROUTES HERE
 
    map.connect('hg_home', '/', controller='hg', action='index')
 
    
 
    
 
    #REST controllers
 
    map.resource('repo', 'repos', path_prefix='/_admin')
 
    map.resource('user', 'users', path_prefix='/_admin')
 
    
 
    #ADMIN
 
    with map.submapper(path_prefix='/_admin', controller='admin') as m:
 
        m.connect('admin_home', '/', action='index')#main page
 
        m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', action='add_repo')
 
        m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}',
 
                  action='add_repo')
 
    
 
    
 
    map.connect('changeset_home', '/{repo_name}/changeset/{revision}',
 
                controller='changeset', revision='tip')
 
    map.connect('summary_home', '/{repo_name}/summary',
 
                controller='summary')
 
    map.connect('shortlog_home', '/{repo_name}/shortlog/{revision}',
 
                controller='shortlog', revision='tip')
 
    map.connect('branches_home', '/{repo_name}/branches',
 
                controller='branches')
 
    map.connect('tags_home', '/{repo_name}/tags',
 
                controller='tags')
 
    map.connect('changelog_home', '/{repo_name}/changelog/{revision}',
 
                controller='changelog', revision='tip')    
 
    map.connect('files_home', '/{repo_name}/files/{revision}/{f_path:.*}',
 
                controller='files', revision='tip', f_path='')
 
    map.connect('files_diff_home', '/{repo_name}/diff/{f_path:.*}',
 
                controller='files', action='diff', revision='tip', f_path='')
 
    map.connect('files_raw_home', '/{repo_name}/rawfile/{revision}/{f_path:.*}',
 
                controller='files', action='rawfile', revision='tip', f_path='')
 
    map.connect('files_archive_home', '/{repo_name}/archive/{revision}/{fileformat}',
 
                controller='files', action='archivefile', revision='tip')
 
    return map
pylons_app/controllers/files.py
Show inline comments
 
@@ -11,63 +11,78 @@ from pylons_app.lib.differ import render
 
from vcs.exceptions import RepositoryError, ChangesetError
 
        
 
log = logging.getLogger(__name__)
 

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

	
 
    def index(self, repo_name, revision, f_path):
 
        hg_model = HgModel()
 
        c.repo = repo = hg_model.get_repo(c.repo_name)
 
        revision = request.POST.get('at_rev', None) or revision
 
        
 
        revision = request.POST.get('at_rev', None) or revision
 
        if request.POST.get('view_low'):
 
            revision = int(revision) - 1
 
        if request.POST.get('view_high'):
 
            revision = int(revision) + 1
 
        def get_next_rev(cur):
 
            max_rev = len(c.repo.revisions) - 1
 
            if revision > max_rev:
 
                revision = max_rev
 
                
 
            r = cur + 1
 
            if r > max_rev:
 
                r = max_rev
 
            return r
 
            
 
        def get_prev_rev(cur):
 
            r = cur - 1
 
            return r
 

	
 
        c.f_path = f_path
 

	
 
     
 
        
 
        try:
 
            c.changeset = repo.get_changeset(repo._get_revision(revision))
 
            cur_rev = repo.get_changeset(revision).revision
 
            prev_rev = repo.get_changeset(get_prev_rev(cur_rev)).raw_id
 
            next_rev = repo.get_changeset(get_next_rev(cur_rev)).raw_id
 
                    
 
            c.url_prev = url('files_home', repo_name=c.repo_name,
 
                             revision=prev_rev, f_path=f_path) 
 
            c.url_next = url('files_home', repo_name=c.repo_name,
 
                             revision=next_rev, f_path=f_path)   
 
                    
 
            c.changeset = repo.get_changeset(revision)
 
            try:
 
                c.file_msg = c.changeset.get_file_message(f_path)
 
            except:
 
                c.file_msg = None
 
                        
 
            c.cur_rev = c.changeset.raw_id
 
            c.rev_nr = c.changeset.revision
 
            c.files_list = c.changeset.get_node(f_path)
 
            c.file_history = self._get_history(repo, c.files_list, f_path)
 
            
 
        except (RepositoryError, ChangesetError):
 
            c.files_list = None
 
        
 
        return render('files/files.html')
 

	
 
    def rawfile(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.headers['Content-type'] = file_node.mimetype
 
        response.headers['Content-disposition'] = 'attachment; filename=%s' \
 
                                                    % f_path.split('/')[-1] 
 
        return file_node.content
 
    
 
    def archivefile(self, repo_name, revision, fileformat):
 
        return '%s %s %s' % (repo_name, revision, fileformat)
 
    
 
    def diff(self, repo_name, f_path):
 
        hg_model = HgModel()
 
        diff1 = request.GET.get('diff1')
 
        diff2 = request.GET.get('diff2')
 
        c.no_changes = diff1 == diff2
 
        c.f_path = f_path
 
        c.repo = hg_model.get_repo(c.repo_name)
 
        c.changeset_1 = c.repo.get_changeset(diff1)
 
        c.changeset_2 = c.repo.get_changeset(diff2)
 
        
 
        c.file_1 = c.changeset_1.get_file_content(f_path)
 
        c.file_2 = c.changeset_2.get_file_content(f_path)
pylons_app/templates/files/files_browser.html
Show inline comments
 
<%def name="file_class(node)">
 
	%if node.is_file():
 
		<%return "browser-file" %>
 
	%else:
 
		<%return "browser-dir"%>
 
	%endif
 
</%def>
 
<div id="body" class="browserblock">
 
	<div class="browser-header">
 
		${h.form(h.url.current())}
 
		<span>${_('view')}@rev ${h.submit('view_low','-')}${h.text('at_rev',value=c.rev_nr,size='5')}${h.submit('view_high','+')}</span>
 
		<span>${_('view')}@rev <a style="font-size: 1.3em"  href="${c.url_prev}">&laquo;</a>${h.text('at_rev',value=c.rev_nr,size='5')}<a style="font-size: 1.3em" href="${c.url_next}">&raquo;</a></span>
 
		${h.submit('view','view')}
 
		${h.end_form()}
 
	</div>
 
	<div class="browser-body">		
 
	<div class="browser-body">
 
		<table class="code-browser">
 
		         <thead>
 
		             <tr>
 
		                 <th>${_('Name')}</th>
 
		                 <th>${_('Size')}</th>
 
		                 <th>${_('Revision')}</th>
 
		                 <th>${_('Last modified')}</th>
 
		                 <th>${_('Last commiter')}</th>
 
		             </tr>
 
		         </thead>
 
		         	<tr class="parity0">
 
		          		<td>
pylons_app/templates/summary.html
Show inline comments
 
@@ -29,30 +29,32 @@ from pylons_app.lib import filters
 
        <dt>${_('name')}</dt>
 
        <dd>${c.repo_info.name}</dd>
 
        <dt>${_('description')}</dt>
 
        <dd>${c.repo_info.description}</dd>
 
        <dt>${_('contact')}</dt>
 
        <dd>${c.repo_info.contact}</dd>
 
        <dt>${_('last change')}</dt>
 
        <dd>${c.repo_info.last_change|n,filters.rfc822date} - ${c.repo_info.last_change|n,filters.age}</dd>
 
        <dt>${_('url')}</dt>
 
        <dd><pre>hg clone <a href="${c.clone_repo_url}">${c.clone_repo_url}</a></pre></dd>
 
        <dt>${_('Download')}</dt>
 
        <dd>
 
       	%for archive in c.repo_info._get_archives():
 
				| <a href="/${c.repo_info.name}/archive/${archive['node']}${archive['extension']}">
 
				${c.repo_info.name}.${archive['type']}
 
				</a>
 
       	%for cnt,archive in enumerate(c.repo_info._get_archives()):
 
       		 %if cnt >=1:
 
       		 |
 
       		 %endif
 
       		 ${h.link_to(c.repo_info.name+'.'+archive['type'],
 
       			h.url('files_archive_home',repo_name=c.repo_info.name,
 
       			revision='tip',fileformat=archive['extension']))}
 
		%endfor
 
		| 
 
        </dd>
 
    </dl>
 

	
 
    <h2>${h.link_to(_('Changes'),h.url('changelog_home',repo_name=c.repo_name))}</h2>
 
    <table>
 
	<%def name="message_slug(msg)">
 
		<%
 
		limit = 60
 
		if len(msg) > limit:
 
			return msg[:limit]+'...'
 
		else:
 
			return msg
0 comments (0 inline, 0 general)