changeset 1547:fbc762ae3496 beta

unified generation of repo groups choices added on-the-fly conversion to new repository groups format (supporting path as a link)
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 11 Oct 2011 23:39:03 +0200
parents c363267bbec7
children cba42a9e9164
files rhodecode/controllers/admin/repos.py rhodecode/controllers/admin/repos_groups.py rhodecode/controllers/admin/settings.py rhodecode/lib/helpers.py rhodecode/lib/utils.py rhodecode/model/db.py rhodecode/templates/summary/summary.html
diffstat 7 files changed, 31 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/admin/repos.py	Tue Oct 11 21:38:27 2011 +0200
+++ b/rhodecode/controllers/admin/repos.py	Tue Oct 11 23:39:03 2011 +0200
@@ -64,20 +64,10 @@
         super(ReposController, self).__before__()
 
     def __load_defaults(self):
+        c.repo_groups = Group.groups_choices()
+        c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
+        
         repo_model = RepoModel()
-
-        c.repo_groups = [('', '')]
-        parents_link = lambda k: h.literal('&raquo;'.join(
-                                    map(lambda k: k.group_name,
-                                        k.parents + [k])
-                                    )
-                                )
-
-        c.repo_groups.extend([(x.group_id, parents_link(x)) for \
-                                            x in self.sa.query(Group).all()])
-        c.repo_groups = sorted(c.repo_groups,
-                               key=lambda t: t[1].split('&raquo;')[0])
-        c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
         c.users_array = repo_model.get_users_js()
         c.users_groups_array = repo_model.get_users_groups_js()
 
--- a/rhodecode/controllers/admin/repos_groups.py	Tue Oct 11 21:38:27 2011 +0200
+++ b/rhodecode/controllers/admin/repos_groups.py	Tue Oct 11 23:39:03 2011 +0200
@@ -32,15 +32,7 @@
         super(ReposGroupsController, self).__before__()
 
     def __load_defaults(self):
-
-        c.repo_groups = [('', '')]
-        parents_link = lambda k: h.literal('&raquo;'.join(k))
-
-        c.repo_groups.extend([(x.group_id, parents_link(x.full_path_splitted))
-                              for x in self.sa.query(Group).all()])
-
-        c.repo_groups = sorted(c.repo_groups,
-                               key=lambda t: t[1].split('&raquo;')[0])
+        c.repo_groups = Group.groups_choices()
         c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
 
     def __load_data(self, group_id):
--- a/rhodecode/controllers/admin/settings.py	Tue Oct 11 21:38:27 2011 +0200
+++ b/rhodecode/controllers/admin/settings.py	Tue Oct 11 23:39:03 2011 +0200
@@ -366,17 +366,7 @@
     def create_repository(self):
         """GET /_admin/create_repository: Form to create a new item"""
 
-        c.repo_groups = [('', '')]
-        parents_link = lambda k: h.literal('&raquo;'.join(
-                                    map(lambda k: k.group_name,
-                                        k.parents + [k])
-                                    )
-                                )
-
-        c.repo_groups.extend([(x.group_id, parents_link(x)) for \
-                                            x in self.sa.query(Group).all()])
-        c.repo_groups = sorted(c.repo_groups,
-                               key=lambda t: t[1].split('&raquo;')[0])
+        c.repo_groups = Group.groups_choices()
         c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
 
         new_repo = request.GET.get('repo', '')
--- a/rhodecode/lib/helpers.py	Tue Oct 11 21:38:27 2011 +0200
+++ b/rhodecode/lib/helpers.py	Tue Oct 11 23:39:03 2011 +0200
@@ -598,12 +598,11 @@
         return repo_name
     else:
         def make_link(group):
-            return link_to(group.group_name, url('repos_group',
-                                                 id=group.group_id))
+            return link_to(group.name, url('repos_group_home',
+                                           group_name=group.group_name))
         return literal(' &raquo; '.join(map(make_link, groups)) + \
                        " &raquo; " + repo_name)
 
-
 def fancy_file_stats(stats):
     """
     Displays a fancy two colored bar for number of added/deleted
--- a/rhodecode/lib/utils.py	Tue Oct 11 21:38:27 2011 +0200
+++ b/rhodecode/lib/utils.py	Tue Oct 11 23:39:03 2011 +0200
@@ -389,6 +389,11 @@
     rm = RepoModel()
     user = sa.query(User).filter(User.admin == True).first()
     added = []
+    # fixup groups paths to new format on the fly
+    # TODO: remove this in future
+    for g in Group.query().all():
+        g.group_name = g.get_new_name(g.name)
+        sa.add(g)    
     for name, repo in initial_repo_list.items():
         group = map_groups(name.split(os.sep))
         if not rm.get_by_repo_name(name, cache=False):
--- a/rhodecode/model/db.py	Tue Oct 11 21:38:27 2011 +0200
+++ b/rhodecode/model/db.py	Tue Oct 11 23:39:03 2011 +0200
@@ -744,6 +744,19 @@
                                   self.group_name)
 
     @classmethod
+    def groups_choices(cls):
+        from webhelpers.html import literal as _literal
+        repo_groups = [('', '')]
+        sep = ' &raquo; '
+        _name = lambda k: _literal(sep.join(k))
+
+        repo_groups.extend([(x.group_id, _name(x.full_path_splitted))
+                              for x in cls.query().all()])
+        
+        repo_groups = sorted(repo_groups,key=lambda t: t[1].split(sep)[0])        
+        return repo_groups
+    
+    @classmethod
     def url_sep(cls):
         return '/'
 
--- a/rhodecode/templates/summary/summary.html	Tue Oct 11 21:38:27 2011 +0200
+++ b/rhodecode/templates/summary/summary.html	Tue Oct 11 23:39:03 2011 +0200
@@ -45,17 +45,17 @@
                  
                  ##REPO TYPE
 		         %if c.dbrepo.repo_type =='hg':
-		           <img style="margin-bottom:2px" class="icon" title="${_('Mercurial repository')}" alt="${_('Mercurial repository')}" src="${h.url("/images/icons/hgicon.png")}"/>
+		           <img style="margin-bottom:2px" class="icon" title="${_('Mercurial repository')}" alt="${_('Mercurial repository')}" src="${h.url('/images/icons/hgicon.png')}"/>
 		         %endif
 		         %if c.dbrepo.repo_type =='git':
-		           <img style="margin-bottom:2px" class="icon" title="${_('Git repository')}" alt="${_('Git repository')}" src="${h.url("/images/icons/giticon.png")}"/>
+		           <img style="margin-bottom:2px" class="icon" title="${_('Git repository')}" alt="${_('Git repository')}" src="${h.url('/images/icons/giticon.png')}"/>
 		         %endif 
                             
                  ##PUBLIC/PRIVATE     			  
 	             %if c.dbrepo.private:
-	                <img style="margin-bottom:2px" class="icon" title="${_('private repository')}" alt="${_('private repository')}" src="${h.url("/images/icons/lock.png")}"/>
+	                <img style="margin-bottom:2px" class="icon" title="${_('private repository')}" alt="${_('private repository')}" src="${h.url('/images/icons/lock.png')}"/>
 	             %else:
-	                <img style="margin-bottom:2px" class="icon" title="${_('public repository')}" alt="${_('public repository')}" src="${h.url("/images/icons/lock_open.png")}"/>
+	                <img style="margin-bottom:2px" class="icon" title="${_('public repository')}" alt="${_('public repository')}" src="${h.url('/images/icons/lock_open.png')}"/>
 	             %endif
 	             
 	              ##REPO NAME
@@ -67,7 +67,7 @@
 	            	<a href="${h.url('summary_home',repo_name=c.dbrepo.fork.repo_name)}">
 	            	<img class="icon" alt="${_('public')}"
 	            	title="${_('Fork of')} ${c.dbrepo.fork.repo_name}" 
-	            	src="${h.url("/images/icons/arrow_divide.png")}"/>
+	            	src="${h.url('/images/icons/arrow_divide.png')}"/>
 	            	${_('Fork of')} ${c.dbrepo.fork.repo_name}
 	            	</a>
 	            	</div>
@@ -78,7 +78,7 @@
                     <a href="${h.url(str(h.hide_credentials(c.dbrepo.clone_uri)))}">
                     <img class="icon" alt="${_('remote clone')}"
                     title="${_('Clone from')} ${h.hide_credentials(c.dbrepo.clone_uri)}" 
-                    src="${h.url("/images/icons/connect.png")}"/>
+                    src="${h.url('/images/icons/connect.png')}"/>
                     ${_('Clone from')} ${h.hide_credentials(c.dbrepo.clone_uri)}
                     </a>
                     </div>