Changeset - 87d80c84df09
[Not reviewed]
default
0 5 1
Marcin Kuzminski - 15 years ago 2010-09-29 22:38:54
marcin@python-works.com
added search in specific repository
added delete to my page view handled by separate controller for deleting users own repos, added fork draft
6 files changed with 163 insertions and 24 deletions:
0 comments (0 inline, 0 general)
pylons_app/config/routing.py
Show inline comments
 
@@ -105,13 +105,14 @@ def make_map(config):
 
    #ADMIN
 
    with map.submapper(path_prefix='/_admin', controller='admin/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')
 
    #SEARCH
 
    map.connect('search', '/_admin/search', controller='search')
 
    map.connect('search', '/_admin/search', controller='search',)
 
    map.connect('search_repo', '/_admin/search/{search_repo:.*}', controller='search')
 
    
 
    #LOGIN/LOGOUT/REGISTER/SIGN IN
 
    map.connect('login_home', '/_admin/login', controller='login')
 
    map.connect('logout_home', '/_admin/logout', controller='login', action='logout')
 
    map.connect('register', '/_admin/register', controller='login', action='register')
 
    map.connect('reset_password', '/_admin/password_reset', controller='login', action='password_reset')
 
@@ -156,16 +157,21 @@ def make_map(config):
 
                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))    
 
    map.connect('files_archive_home', '/{repo_name:.*}/archive/{revision}/{fileformat}',
 
                controller='files', action='archivefile', revision='tip',
 
                conditions=dict(function=check_repo))
 
                conditions=dict(function=check_repo))   
 
    map.connect('repo_settings_delete', '/{repo_name:.*}/settings',
 
                controller='settings', action="delete",
 
                conditions=dict(method=["DELETE"], function=check_repo))
 
    map.connect('repo_settings_update', '/{repo_name:.*}/settings',
 
                controller='settings', action="update",
 
                conditions=dict(method=["PUT"], function=check_repo))
 
    map.connect('repo_settings_home', '/{repo_name:.*}/settings',
 
                controller='settings', action='index',
 
                conditions=dict(function=check_repo))
 

	
 
    
 
    map.connect('repo_fork_home', '/{repo_name:.*}/fork',
 
                controller='settings', action='fork',
 
                conditions=dict(function=check_repo))    
 
    return map
pylons_app/controllers/search.py
Show inline comments
 
@@ -41,13 +41,14 @@ log = logging.getLogger(__name__)
 
class SearchController(BaseController):
 

	
 
    @LoginRequired()
 
    def __before__(self):
 
        super(SearchController, self).__before__()    
 

	
 
    def index(self):
 
    def index(self, search_repo=None):
 
        c.repo_name = search_repo
 
        c.formated_results = []
 
        c.runtime = ''
 
        c.cur_query = request.GET.get('q', None)
 
        if c.cur_query:
 
            cur_query = c.cur_query.lower()
 
        
 
@@ -56,12 +57,14 @@ class SearchController(BaseController):
 
            highlight_items = set()
 
            try:
 
                idx = open_dir(IDX_LOCATION, indexname=IDX_NAME)
 
                searcher = idx.searcher()
 

	
 
                qp = QueryParser("content", schema=SCHEMA)
 
                if c.repo_name:
 
                    cur_query = u'repository:%s %s' % (c.repo_name, cur_query)
 
                try:
 
                    query = qp.parse(unicode(cur_query))
 
                    
 
                    if isinstance(query, Phrase):
 
                        highlight_items.update(query.words)
 
                    else:
pylons_app/controllers/settings.py
Show inline comments
 
@@ -52,13 +52,13 @@ class SettingsController(BaseController)
 
            h.flash(_('%s repository is not mapped to db perhaps' 
 
                      ' it was created or renamed from the filesystem'
 
                      ' please run the application again'
 
                      ' in order to rescan repositories') % repo_name,
 
                      category='error')
 
        
 
            return redirect(url('repos'))        
 
            return redirect(url('hg_home'))        
 
        defaults = c.repo_info.__dict__
 
        defaults.update({'user':c.repo_info.user.username})
 
        c.users_array = repo_model.get_users_js()
 
        
 
        for p in c.repo_info.repo_to_perm:
 
            defaults.update({'perm_%s' % p.user.username: 
 
@@ -95,6 +95,50 @@ class SettingsController(BaseController)
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            h.flash(_('error occured during update of repository %s') \
 
                    % repo_name, category='error')
 
                    
 
        return redirect(url('repo_settings_home', repo_name=changed_name))
 

	
 

	
 

	
 
    def delete(self, repo_name):    
 
        """DELETE /repos/repo_name: Delete an existing item"""
 
        # Forms posted to this method should contain a hidden field:
 
        #    <input type="hidden" name="_method" value="DELETE" />
 
        # Or using helpers:
 
        #    h.form(url('repo_settings_delete', repo_name=ID),
 
        #           method='delete')
 
        # url('repo_settings_delete', repo_name=ID)
 
        
 
        repo_model = RepoModel()
 
        repo = repo_model.get(repo_name)
 
        if not repo:
 
            h.flash(_('%s repository is not mapped to db perhaps' 
 
                      ' it was moved or renamed  from the filesystem'
 
                      ' please run the application again'
 
                      ' in order to rescan repositories') % repo_name,
 
                      category='error')
 
        
 
            return redirect(url('hg_home'))
 
        try:
 
            repo_model.delete(repo)            
 
            invalidate_cache('cached_repo_list')
 
            h.flash(_('deleted repository %s') % repo_name, category='success')
 
        except Exception:
 
            h.flash(_('An error occured during deletion of %s') % repo_name,
 
                    category='error')
 
        
 
        return redirect(url('hg_home'))
 
    
 
    def fork(self, repo_name):
 
        repo_model = RepoModel()
 
        c.repo_info = repo = repo_model.get(repo_name)
 
        if not repo:
 
            h.flash(_('%s repository is not mapped to db perhaps' 
 
                      ' it was created or renamed from the filesystem'
 
                      ' please run the application again'
 
                      ' in order to rescan repositories') % repo_name,
 
                      category='error')
 
        
 
            return redirect(url('hg_home'))         
 
        return render('settings/repo_fork.html')
pylons_app/templates/admin/users/user_edit_my_account.html
Show inline comments
 
@@ -85,27 +85,39 @@
 
        <h5>${_('My repositories')}</h5>   
 
    </div>
 
    <!-- end box / title -->
 
    <div class="table">
 
	    <table>
 
	     <tbody>
 
	     %for repo in c.user_repos:
 
	        <tr>
 
	            <td>
 
	             %if repo.dbrepo.private:
 
	                <img class="icon" alt="${_('private')}" src="/images/icons/lock.png"/>
 
	             %else:
 
	                <img class="icon" alt="${_('public')}" src="/images/icons/lock_open.png"/>
 
	             %endif
 
	                                             
 
	            ${h.link_to(repo.name, h.url('summary_home',repo_name=repo.name))}</td> 
 
	            <td>${_('revision')}: ${h.get_changeset_safe(repo,'tip').revision}</td>
 
	            <td>${_('last changed')}: ${h.age(repo.last_change)}</td>
 
	            <td><img class="icon" alt="${_('private')}" src="/images/icons/application_form_edit.png"/> ${h.link_to(_('edit'),h.url('edit_repo',repo_name=repo.name))}</td>
 
	        </tr>
 
	     %endfor
 
	     %if c.user_repos:
 
		     %for repo in c.user_repos:
 
		        <tr>
 
		            <td>
 
		             %if repo.dbrepo.private:
 
		                <img class="icon" alt="${_('private')}" src="/images/icons/lock.png"/>
 
		             %else:
 
		                <img class="icon" alt="${_('public')}" src="/images/icons/lock_open.png"/>
 
		             %endif
 
		                                             
 
		            ${h.link_to(repo.name, h.url('summary_home',repo_name=repo.name))}</td> 
 
		            <td>${_('revision')}: ${h.get_changeset_safe(repo,'tip').revision}</td>
 
		            <td>${_('last changed')}: ${h.age(repo.last_change)}</td>
 
		            <td><img class="icon" alt="${_('private')}" src="/images/icons/application_form_edit.png"/> ${h.link_to(_('edit'),h.url('repo_settings_home',repo_name=repo.name))}</td>
 
		            <td>
 
	                  ${h.form(url('repo_settings_delete', repo_name=repo.name),method='delete')}
 
	                    ${h.submit('remove_%s' % repo.name,'delete',class_="delete_icon action_button",onclick="return confirm('Confirm to delete this repository');")}
 
	                  ${h.end_form()}	            
 
		            </td>
 
		        </tr>
 
		     %endfor
 
	     %else:
 
	     	${_('No repositories yet')} 
 
	     	%if h.HasPermissionAny('hg.admin','hg.create.repository')():
 
	     		${h.link_to(_('create one now'),h.url('admin_settings_create_repository'))}
 
	     	%endif
 
	     %endif
 
	     </tbody>
 
	     </table>
 
    </div>
 
    
 
</div>
 
</%def>  
 
\ No newline at end of file
pylons_app/templates/search/search.html
Show inline comments
 
## -*- coding: utf-8 -*-
 
<%inherit file="/base/base.html"/>
 
<%def name="title()">
 
   ${_('Search')}: ${c.cur_query}
 
   ${_('Search')} 
 
	%if c.repo_name:
 
		${_('in repository: ') + c.repo_name}
 
	%else:
 
		${_('in all repositories')}		
 
	%endif
 
	:${c.cur_query}
 
</%def>
 
<%def name="breadcrumbs()">
 
	${c.hg_app_name}
 
</%def>
 
<%def name="page_nav()">
 
	${self.menu('home')}
 
</%def>
 
<%def name="main()">
 

	
 
<div class="box">
 
	<!-- box / title -->
 
	<div class="title">
 
		<h5>${_('Search')}</h5>
 
		<h5>${_('Search')}
 
		%if c.repo_name:
 
			${_('in repository: ') + c.repo_name}
 
		%else:
 
			${_('in all repositories')}
 
		%endif		
 
		</h5>
 
	</div>
 
	<!-- end box / title -->
 
	${h.form('search',method='get')}
 
	%if c.repo_name:
 
		${h.form(h.url('search_repo',search_repo=c.repo_name),method='get')}	
 
	%else:
 
		${h.form(h.url('search'),method='get')}
 
	%endif
 
	<div class="form">
 
		<div class="fields">
 
		
 
			<div class="field ">
 
				<div class="label">
 
					<label for="q">${_('Search:')}</label>
 
					<label for="q">${_('Search')}:</label>
 
				</div>
 
				<div class="input">
 
					${h.text('q',c.cur_query,class_="small")}
 
					<div class="button highlight">
 
						<input type="submit" value="${_('Search')}" class="ui-button ui-widget ui-state-default ui-corner-all"/>
 
					</div>		
pylons_app/templates/settings/repo_fork.html
Show inline comments
 
new file 100644
 
## -*- coding: utf-8 -*-
 
<%inherit file="/base/base.html"/>
 

	
 
<%def name="title()">
 
    ${_('Fork repository')} ${c.repo_info.repo_name}
 
</%def>
 

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

	
 
<%def name="page_nav()">
 
	${self.menu('')}
 
</%def>
 
<%def name="main()">
 
<div class="box">
 
    <!-- box / title -->
 
    <div class="title">
 
        ${self.breadcrumbs()}      
 
    </div>
 
    ${h.form(url('repos'))}
 
    <div class="form">
 
        <!-- fields -->
 
        <div class="fields">
 
            <div class="field">
 
	            <div class="label">
 
	                <label for="repo_name">${_('Fork name')}:</label>
 
	            </div>
 
	            <div class="input">
 
	                ${h.text('fork_name')}
 
	            </div>
 
             </div>
 
            <div class="field">
 
                <div class="label label-textarea">
 
                    <label for="description">${_('Description')}:</label>
 
                </div>
 
                <div class="textarea text-area editor">
 
                    ${h.textarea('description',cols=23,rows=5)}
 
                </div>
 
             </div>
 
            <div class="field">
 
                <div class="label label-checkbox">
 
                    <label for="private">${_('Private')}:</label>
 
                </div>
 
                <div class="checkboxes">
 
                    ${h.checkbox('private',value="True")}
 
                </div>
 
             </div>
 
	        <div class="buttons">
 
	          ${h.submit('fork','fork this repository',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
	        </div>                                                          
 
        </div>
 
    </div>    
 
    ${h.end_form()}    
 
</div>
 
</%def>   
0 comments (0 inline, 0 general)