Changeset - 7e75af301842
[Not reviewed]
beta
0 4 3
Marcin Kuzminski - 15 years ago 2011-05-02 13:02:58
marcin@python-works.com
Added simple forks page, resolves issue #179
7 files changed with 141 insertions and 2 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/routing.py
Show inline comments
 
@@ -338,7 +338,11 @@ def make_map(config):
 
                controller='settings', action='fork',
 
                conditions=dict(function=check_repo))
 

	
 
    rmap.connect('repo_followers_home', '/{repo_name:.*}/followers',
 
                 controller='followers', action='followers',
 
                 conditions=dict(function=check_repo))
 

	
 
    rmap.connect('repo_forks_home', '/{repo_name:.*}/forks',
 
                 controller='forks', action='forks',
 
                 conditions=dict(function=check_repo))
 
    return rmap
rhodecode/controllers/followers.py
Show inline comments
 
@@ -41,13 +41,13 @@ class FollowersController(BaseRepoContro
 
                                   'repository.admin')
 
    def __before__(self):
 
        super(FollowersController, self).__before__()
 

	
 
    def followers(self, repo_name):
 
        p = int(request.params.get('page', 1))
 
        repo_id = getattr(Repository.by_repo_name(repo_name), 'repo_id')
 
        repo_id = Repository.by_repo_name(repo_name).repo_id
 
        d = UserFollowing.get_repo_followers(repo_id)\
 
            .order_by(UserFollowing.follows_from)
 
        c.followers_pager = Page(d, page=p, items_per_page=20)
 

	
 
        c.followers_data = render('/followers/followers_data.html')
 

	
rhodecode/controllers/forks.py
Show inline comments
 
new file 100644
 
# -*- coding: utf-8 -*-
 
"""
 
    rhodecode.controllers.forks
 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
    forks controller for rhodecode
 

	
 
    :created_on: Apr 23, 2011
 
    :author: marcink
 
    :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
 
    :license: GPLv3, see COPYING for more details.
 
"""
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
import logging
 

	
 
from pylons import tmpl_context as c, request
 

	
 
from rhodecode.lib.helpers import Page
 
from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
 
from rhodecode.lib.base import BaseRepoController, render
 
from rhodecode.model.db import Repository, User, UserFollowing
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class ForksController(BaseRepoController):
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def __before__(self):
 
        super(ForksController, self).__before__()
 

	
 
    def forks(self, repo_name):
 
        p = int(request.params.get('page', 1))
 
        repo_id = Repository.by_repo_name(repo_name).repo_id
 
        d = Repository.get_repo_forks(repo_id)
 
        c.forks_pager = Page(d, page=p, items_per_page=20)
 

	
 
        c.forks_data = render('/forks/forks_data.html')
 

	
 
        if request.params.get('partial'):
 
            return c.forks_data
 

	
 
        return render('/forks/forks.html')
rhodecode/model/db.py
Show inline comments
 
@@ -234,12 +234,14 @@ class Repository(Base):
 
    repo_type = Column("repo_type", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg')
 
    user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
 
    private = Column("private", Boolean(), nullable=True, unique=None, default=None)
 
    enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
 
    enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True)
 
    description = Column("description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
 
    created_on = Column('created_on', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now)
 

	
 
    fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
 
    group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None)
 

	
 

	
 
    user = relationship('User')
 
    fork = relationship('Repository', remote_side=repo_id)
 
@@ -257,12 +259,17 @@ class Repository(Base):
 
                                  self.repo_id, self.repo_name)
 

	
 
    @classmethod
 
    def by_repo_name(cls, repo_name):
 
        return Session.query(cls).filter(cls.repo_name == repo_name).one()
 

	
 

	
 
    @classmethod
 
    def get_repo_forks(cls, repo_id):
 
        return Session.query(cls).filter(Repository.fork_id == repo_id)
 

	
 
    @property
 
    def just_name(self):
 
        return self.repo_name.split(os.sep)[-1]
 

	
 
    @property
 
    def groups_with_parents(self):
rhodecode/templates/base/base.html
Show inline comments
 
@@ -295,13 +295,13 @@
 
                        <img src="${h.url("/images/icons/heart.png")}" alt="${_('Followers')}" />
 
                    </span>
 
                    <span id="current_followers_count" class="short">${c.repository_followers}</span>
 
                    </a>
 
                </li>
 
                <li>
 
                    <a title="${_('Forks')}" href="#">
 
                    <a title="${_('Forks')}" href="${h.url('repo_forks_home',repo_name=c.repo_name)}">
 
                    <span class="icon_short">
 
                        <img src="${h.url("/images/icons/arrow_divide.png")}" alt="${_('Forks')}" />
 
                    </span>
 
                    <span class="short">${c.repository_forks}</span>
 
                    </a>
 
                </li>                
rhodecode/templates/forks/forks.html
Show inline comments
 
new file 100644
 
## -*- coding: utf-8 -*-
 
<%inherit file="/base/base.html"/>
 

	
 
<%def name="title()">
 
    ${c.repo_name} ${_('Forks')} - ${c.rhodecode_name}
 
</%def>
 

	
 
<%def name="breadcrumbs_links()">
 
    ${h.link_to(u'Home',h.url('/'))}
 
    &raquo; 
 
    ${h.link_to(c.repo_name,h.url('summary_home',repo_name=c.repo_name))}
 
    &raquo;
 
    ${_('forks')}
 
</%def>
 

	
 
<%def name="page_nav()">
 
    ${self.menu('forks')}
 
</%def>
 
<%def name="main()">
 
<div class="box">
 
    <!-- box / title -->
 
    <div class="title">
 
        ${self.breadcrumbs()}
 
    </div>
 
    <!-- end box / title -->
 
    <div class="table">
 
        <div id="forks">
 
            ${c.forks_data}
 
        </div>   
 
    </div>
 
</div>    
 
</%def> 
 
\ No newline at end of file
rhodecode/templates/forks/forks_data.html
Show inline comments
 
new file 100644
 
## -*- coding: utf-8 -*-
 

	
 
% for f in c.forks_pager:
 
    <div>
 
        <div class="fork_user">
 
            <div class="gravatar">
 
                <img alt="gravatar" src="${h.gravatar_url(f.user.email,24)}"/>
 
            </div>
 
            <span style="font-size: 20px">
 
             <b>${f.user.username}</b> (${f.user.name} ${f.user.lastname}) / 
 
              ${h.link_to(f.repo_name,h.url('summary_home',repo_name=f.repo_name))}
 
             </span>
 
             <div style="padding:5px 3px 3px 42px;">${f.description}</div>
 
        </div>
 
        <div style="clear:both;padding-top: 10px"></div>
 
        <div class="follower_date">${_('forked')} - 
 
        <span class="tooltip" title="${f.created_on}"> ${h.age(f.created_on)}</span></div>
 
        <div style="border-bottom: 1px solid #DDD;margin:10px 0px 10px 0px"></div>            
 
    </div>                
 
% endfor 
 

	
 
<div class="pagination-wh pagination-left">
 
<script type="text/javascript">
 
  var data_div = 'forks';
 
  YAHOO.util.Event.onDOMReady(function(){
 
    YAHOO.util.Event.addListener(
 
    		YUD.getElementsByClassName('pager_link'),"click",
 
    		function(){
 
            YAHOO.util.Dom.setStyle(data_div,'opacity','0.3');
 
            });
 
    });
 
</script>
 

	
 
${c.forks_pager.pager('$link_previous ~2~ $link_next',     
 
onclick="""YAHOO.util.Connect.asyncRequest('GET','$partial_url',{
 
success:function(o){YAHOO.util.Dom.get(data_div).innerHTML=o.responseText;
 
YUE.on(YAHOO.util.Dom.getElementsByClassName('pager_link'),"click",function(){
 
        YAHOO.util.Dom.setStyle(data_div,'opacity','0.3');});       
 
YAHOO.util.Dom.setStyle(data_div,'opacity','1');}},null); return false;""")}
 
</div>
 
\ No newline at end of file
0 comments (0 inline, 0 general)