##// END OF EJS Templates
#109, added optional clone uri when creating repo....
marcink -
r1112:6d0a7284 beta
parent child Browse files
Show More
@@ -42,12 +42,11 b' from rhodecode.lib.auth import LoginRequ'
42 from rhodecode.lib.base import BaseController, render
42 from rhodecode.lib.base import BaseController, render
43 from rhodecode.lib.utils import invalidate_cache, action_logger, repo_name_slug
43 from rhodecode.lib.utils import invalidate_cache, action_logger, repo_name_slug
44 from rhodecode.lib.helpers import get_token
44 from rhodecode.lib.helpers import get_token
45 from rhodecode.model.db import User, Repository, UserFollowing
45 from rhodecode.model.db import User, Repository, UserFollowing, Group
46 from rhodecode.model.forms import RepoForm
46 from rhodecode.model.forms import RepoForm
47 from rhodecode.model.scm import ScmModel
47 from rhodecode.model.scm import ScmModel
48 from rhodecode.model.repo import RepoModel
48 from rhodecode.model.repo import RepoModel
49
49
50
51 log = logging.getLogger(__name__)
50 log = logging.getLogger(__name__)
52
51
53 class ReposController(BaseController):
52 class ReposController(BaseController):
@@ -64,6 +63,82 b' class ReposController(BaseController):'
64 c.admin_username = session.get('admin_username')
63 c.admin_username = session.get('admin_username')
65 super(ReposController, self).__before__()
64 super(ReposController, self).__before__()
66
65
66
67
68 def __load_data(self, repo_name):
69 """
70 Load defaults settings for edit, and update
71
72 :param repo_name:
73 """
74 repo, dbrepo = ScmModel().get(repo_name, retval='repo')
75
76 repo_model = RepoModel()
77 c.repo_info = repo_model.get_by_repo_name(repo_name)
78
79 if c.repo_info is None:
80 h.flash(_('%s repository is not mapped to db perhaps'
81 ' it was created or renamed from the filesystem'
82 ' please run the application again'
83 ' in order to rescan repositories') % repo_name,
84 category='error')
85
86 return redirect(url('repos'))
87
88
89
90 c.repo_groups = [('', '')]
91 c.repo_groups.extend([(x.group_id, x.group_name) for x in self.sa.query(Group).all()])
92
93 c.default_user_id = User.by_username('default').user_id
94 c.in_public_journal = self.sa.query(UserFollowing)\
95 .filter(UserFollowing.user_id == c.default_user_id)\
96 .filter(UserFollowing.follows_repository == c.repo_info).scalar()
97
98 if c.repo_info.stats:
99 last_rev = c.repo_info.stats.stat_on_revision
100 else:
101 last_rev = 0
102 c.stats_revision = last_rev
103
104 c.repo_last_rev = repo.count() - 1 if repo.revisions else 0
105
106 if last_rev == 0 or c.repo_last_rev == 0:
107 c.stats_percentage = 0
108 else:
109 c.stats_percentage = '%.2f' % ((float((last_rev)) /
110 c.repo_last_rev) * 100)
111
112 c.users_array = repo_model.get_users_js()
113 c.users_groups_array = repo_model.get_users_groups_js()
114
115 defaults = c.repo_info.get_dict()
116 group, repo_name = c.repo_info.groups_and_repo
117 defaults['repo_name'] = repo_name
118 defaults['repo_group'] = getattr(group, 'group_id', None)
119 #fill owner
120 if c.repo_info.user:
121 defaults.update({'user':c.repo_info.user.username})
122 else:
123 replacement_user = self.sa.query(User)\
124 .filter(User.admin == True).first().username
125 defaults.update({'user':replacement_user})
126
127
128 #fill repository users
129 for p in c.repo_info.repo_to_perm:
130 defaults.update({'u_perm_%s' % p.user.username:
131 p.permission.permission_name})
132
133 #fill repository groups
134 for p in c.repo_info.users_group_to_perm:
135 defaults.update({'g_perm_%s' % p.users_group.users_group_name:
136 p.permission.permission_name})
137
138
139 return defaults
140
141
67 @HasPermissionAllDecorator('hg.admin')
142 @HasPermissionAllDecorator('hg.admin')
68 def index(self, format='html'):
143 def index(self, format='html'):
69 """GET /repos: All items in the collection"""
144 """GET /repos: All items in the collection"""
@@ -78,12 +153,18 b' class ReposController(BaseController):'
78 POST /repos: Create a new item"""
153 POST /repos: Create a new item"""
79 # url('repos')
154 # url('repos')
80 repo_model = RepoModel()
155 repo_model = RepoModel()
81 _form = RepoForm()()
156 c.repo_groups = [('', '')]
157 c.repo_groups.extend([(x.group_id, x.group_name) for x in self.sa.query(Group).all()])
82 form_result = {}
158 form_result = {}
83 try:
159 try:
84 form_result = _form.to_python(dict(request.POST))
160 form_result = RepoForm()(repo_groups=c.repo_groups).to_python(dict(request.POST))
85 repo_model.create(form_result, c.rhodecode_user)
161 repo_model.create(form_result, c.rhodecode_user)
86 h.flash(_('created repository %s') % form_result['repo_name'],
162 if form_result['clone_uri']:
163 h.flash(_('created repository %s from %s') \
164 % (form_result['repo_name'], form_result['clone_uri']),
165 category='success')
166 else:
167 h.flash(_('created repository %s') % form_result['repo_name'],
87 category='success')
168 category='success')
88
169
89 if request.POST.get('user_created'):
170 if request.POST.get('user_created'):
@@ -94,7 +175,10 b' class ReposController(BaseController):'
94 form_result['repo_name'], '', self.sa)
175 form_result['repo_name'], '', self.sa)
95
176
96 except formencode.Invalid, errors:
177 except formencode.Invalid, errors:
178
97 c.new_repo = errors.value['repo_name']
179 c.new_repo = errors.value['repo_name']
180 c.repo_groups = [('', '')]
181 c.repo_groups.extend([(x.group_id, x.group_name) for x in self.sa.query(Group).all()])
98
182
99 if request.POST.get('user_created'):
183 if request.POST.get('user_created'):
100 r = render('admin/repos/repo_add_create_repository.html')
184 r = render('admin/repos/repo_add_create_repository.html')
@@ -122,7 +206,8 b' class ReposController(BaseController):'
122 """GET /repos/new: Form to create a new item"""
206 """GET /repos/new: Form to create a new item"""
123 new_repo = request.GET.get('repo', '')
207 new_repo = request.GET.get('repo', '')
124 c.new_repo = repo_name_slug(new_repo)
208 c.new_repo = repo_name_slug(new_repo)
125
209 c.repo_groups = [('', '')]
210 c.repo_groups.extend([(x.group_id, x.group_name) for x in self.sa.query(Group).all()])
126 return render('admin/repos/repo_add.html')
211 return render('admin/repos/repo_add.html')
127
212
128 @HasPermissionAllDecorator('hg.admin')
213 @HasPermissionAllDecorator('hg.admin')
@@ -138,7 +223,6 b' class ReposController(BaseController):'
138 repo_model = RepoModel()
223 repo_model = RepoModel()
139 changed_name = repo_name
224 changed_name = repo_name
140 _form = RepoForm(edit=True, old_data={'repo_name':repo_name})()
225 _form = RepoForm(edit=True, old_data={'repo_name':repo_name})()
141
142 try:
226 try:
143 form_result = _form.to_python(dict(request.POST))
227 form_result = _form.to_python(dict(request.POST))
144 repo_model.update(repo_name, form_result)
228 repo_model.update(repo_name, form_result)
@@ -150,34 +234,11 b' class ReposController(BaseController):'
150 changed_name, '', self.sa)
234 changed_name, '', self.sa)
151
235
152 except formencode.Invalid, errors:
236 except formencode.Invalid, errors:
153 c.repo_info = repo_model.get_by_repo_name(repo_name)
237 defaults = self.__load_data(repo_name)
154
238 defaults.update(errors.value)
155 if c.repo_info.stats:
156 last_rev = c.repo_info.stats.stat_on_revision
157 else:
158 last_rev = 0
159 c.stats_revision = last_rev
160 repo, dbrepo = ScmModel().get(repo_name, retval='repo')
161 c.repo_last_rev = repo.count() - 1 if repo.revisions else 0
162
163 c.default_user_id = User.by_username('default').user_id
164 c.in_public_journal = self.sa.query(UserFollowing)\
165 .filter(UserFollowing.user_id == c.default_user_id)\
166 .filter(UserFollowing.follows_repository == c.repo_info).scalar()
167
168 if last_rev == 0:
169 c.stats_percentage = 0
170 else:
171 c.stats_percentage = '%.2f' % ((float((last_rev)) /
172 c.repo_last_rev) * 100)
173
174 c.users_array = repo_model.get_users_js()
175 c.users_groups_array = repo_model.get_users_groups_js()
176
177 errors.value.update({'user':c.repo_info.user.username})
178 return htmlfill.render(
239 return htmlfill.render(
179 render('admin/repos/repo_edit.html'),
240 render('admin/repos/repo_edit.html'),
180 defaults=errors.value,
241 defaults=defaults,
181 errors=errors.error_dict or {},
242 errors=errors.error_dict or {},
182 prefix_error=False,
243 prefix_error=False,
183 encoding="UTF-8")
244 encoding="UTF-8")
@@ -186,7 +247,6 b' class ReposController(BaseController):'
186 log.error(traceback.format_exc())
247 log.error(traceback.format_exc())
187 h.flash(_('error occurred during update of repository %s') \
248 h.flash(_('error occurred during update of repository %s') \
188 % repo_name, category='error')
249 % repo_name, category='error')
189
190 return redirect(url('edit_repo', repo_name=changed_name))
250 return redirect(url('edit_repo', repo_name=changed_name))
191
251
192 @HasPermissionAllDecorator('hg.admin')
252 @HasPermissionAllDecorator('hg.admin')
@@ -325,62 +385,7 b' class ReposController(BaseController):'
325 def edit(self, repo_name, format='html'):
385 def edit(self, repo_name, format='html'):
326 """GET /repos/repo_name/edit: Form to edit an existing item"""
386 """GET /repos/repo_name/edit: Form to edit an existing item"""
327 # url('edit_repo', repo_name=ID)
387 # url('edit_repo', repo_name=ID)
328 repo, dbrepo = ScmModel().get(repo_name, retval='repo')
388 defaults = self.__load_data(repo_name)
329
330 repo_model = RepoModel()
331 c.repo_info = repo_model.get_by_repo_name(repo_name)
332
333 if c.repo_info is None:
334 h.flash(_('%s repository is not mapped to db perhaps'
335 ' it was created or renamed from the filesystem'
336 ' please run the application again'
337 ' in order to rescan repositories') % repo_name,
338 category='error')
339
340 return redirect(url('repos'))
341
342 c.default_user_id = User.by_username('default').user_id
343 c.in_public_journal = self.sa.query(UserFollowing)\
344 .filter(UserFollowing.user_id == c.default_user_id)\
345 .filter(UserFollowing.follows_repository == c.repo_info).scalar()
346
347 if c.repo_info.stats:
348 last_rev = c.repo_info.stats.stat_on_revision
349 else:
350 last_rev = 0
351 c.stats_revision = last_rev
352
353 c.repo_last_rev = repo.count() - 1 if repo.revisions else 0
354
355 if last_rev == 0 or c.repo_last_rev == 0:
356 c.stats_percentage = 0
357 else:
358 c.stats_percentage = '%.2f' % ((float((last_rev)) /
359 c.repo_last_rev) * 100)
360
361 c.users_array = repo_model.get_users_js()
362 c.users_groups_array = repo_model.get_users_groups_js()
363
364 defaults = c.repo_info.get_dict()
365
366 #fill owner
367 if c.repo_info.user:
368 defaults.update({'user':c.repo_info.user.username})
369 else:
370 replacement_user = self.sa.query(User)\
371 .filter(User.admin == True).first().username
372 defaults.update({'user':replacement_user})
373
374
375 #fill repository users
376 for p in c.repo_info.repo_to_perm:
377 defaults.update({'u_perm_%s' % p.user.username:
378 p.permission.permission_name})
379
380 #fill repository groups
381 for p in c.repo_info.users_group_to_perm:
382 defaults.update({'g_perm_%s' % p.users_group.users_group_name:
383 p.permission.permission_name})
384
389
385 return htmlfill.render(
390 return htmlfill.render(
386 render('admin/repos/repo_edit.html'),
391 render('admin/repos/repo_edit.html'),
@@ -42,7 +42,7 b' from rhodecode.lib.base import BaseContr'
42 from rhodecode.lib.celerylib import tasks, run_task
42 from rhodecode.lib.celerylib import tasks, run_task
43 from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \
43 from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \
44 set_rhodecode_config, repo_name_slug
44 set_rhodecode_config, repo_name_slug
45 from rhodecode.model.db import RhodeCodeUi, Repository
45 from rhodecode.model.db import RhodeCodeUi, Repository, Group
46 from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \
46 from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \
47 ApplicationUiSettingsForm
47 ApplicationUiSettingsForm
48 from rhodecode.model.scm import ScmModel
48 from rhodecode.model.scm import ScmModel
@@ -321,7 +321,8 b' class SettingsController(BaseController)'
321 """GET /_admin/create_repository: Form to create a new item"""
321 """GET /_admin/create_repository: Form to create a new item"""
322 new_repo = request.GET.get('repo', '')
322 new_repo = request.GET.get('repo', '')
323 c.new_repo = repo_name_slug(new_repo)
323 c.new_repo = repo_name_slug(new_repo)
324
324 c.repo_groups = [('', '')]
325 c.repo_groups.extend([(x.group_id, x.group_name) for x in self.sa.query(Group).all()])
325 return render('admin/repos/repo_add_create_repository.html')
326 return render('admin/repos/repo_add_create_repository.html')
326
327
327 def get_hg_ui_settings(self):
328 def get_hg_ui_settings(self):
@@ -450,17 +450,21 b' def PasswordResetForm():'
450 email = All(ValidSystemEmail(), Email(not_empty=True))
450 email = All(ValidSystemEmail(), Email(not_empty=True))
451 return _PasswordResetForm
451 return _PasswordResetForm
452
452
453 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
453 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
454 repo_groups=[]):
454 class _RepoForm(formencode.Schema):
455 class _RepoForm(formencode.Schema):
455 allow_extra_fields = True
456 allow_extra_fields = True
456 filter_extra_fields = False
457 filter_extra_fields = False
457 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True),
458 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True),
458 ValidRepoName(edit, old_data))
459 ValidRepoName(edit, old_data))
460 clone_uri = UnicodeString(strip=True, min=1, not_empty=False)
461 repo_group = OneOf(repo_groups)
462 repo_type = OneOf(supported_backends)
459 description = UnicodeString(strip=True, min=1, not_empty=True)
463 description = UnicodeString(strip=True, min=1, not_empty=True)
460 private = StringBoolean(if_missing=False)
464 private = StringBoolean(if_missing=False)
461 enable_statistics = StringBoolean(if_missing=False)
465 enable_statistics = StringBoolean(if_missing=False)
462 enable_downloads = StringBoolean(if_missing=False)
466 enable_downloads = StringBoolean(if_missing=False)
463 repo_type = OneOf(supported_backends)
467
464 if edit:
468 if edit:
465 #this is repo owner
469 #this is repo owner
466 user = All(Int(not_empty=True), ValidRepoUser)
470 user = All(Int(not_empty=True), ValidRepoUser)
@@ -234,7 +234,8 b' class RepoModel(BaseModel):'
234 self.sa.add(repo_to_perm)
234 self.sa.add(repo_to_perm)
235
235
236 if not just_db:
236 if not just_db:
237 self.__create_repo(repo_name, form_data['repo_type'])
237 self.__create_repo(repo_name, form_data['repo_type'],
238 form_data['clone_uri'])
238
239
239 self.sa.commit()
240 self.sa.commit()
240
241
@@ -299,7 +300,7 b' class RepoModel(BaseModel):'
299 raise
300 raise
300
301
301
302
302 def __create_repo(self, repo_name, alias):
303 def __create_repo(self, repo_name, alias, clone_uri=False):
303 """
304 """
304 makes repository on filesystem
305 makes repository on filesystem
305 :param repo_name:
306 :param repo_name:
@@ -308,9 +309,10 b' class RepoModel(BaseModel):'
308 from rhodecode.lib.utils import check_repo
309 from rhodecode.lib.utils import check_repo
309 repo_path = os.path.join(self.repos_path, repo_name)
310 repo_path = os.path.join(self.repos_path, repo_name)
310 if check_repo(repo_name, self.repos_path):
311 if check_repo(repo_name, self.repos_path):
311 log.info('creating repo %s in %s', repo_name, repo_path)
312 log.info('creating repo %s in %s @ %s', repo_name, repo_path,
313 clone_uri)
312 backend = get_backend(alias)
314 backend = get_backend(alias)
313 backend(repo_path, create=True)
315 backend(repo_path, create=True, src_url=clone_uri)
314
316
315 def __rename_repo(self, old, new):
317 def __rename_repo(self, old, new):
316 """
318 """
@@ -14,12 +14,21 b''
14 </div>
14 </div>
15 <div class="field">
15 <div class="field">
16 <div class="label">
16 <div class="label">
17 <label for="repo_name">${_('Clone from')}:</label>
17 <label for="clone_uri">${_('Clone from')}:</label>
18 </div>
18 </div>
19 <div class="input">
19 <div class="input">
20 ${h.text('clone_uri',c.new_repo,class_="small")}
20 ${h.text('clone_uri',class_="small")}
21 </div>
21 </div>
22 </div>
22 </div>
23 <div class="field">
24 <div class="label">
25 <label for="repo_group">${_('Repository group')}:</label>
26 </div>
27 <div class="input">
28 ${h.select('repo_group','',c.repo_groups,class_="medium")}
29 <span>${h.link_to(_('add new group'),h.url(''))}</span>
30 </div>
31 </div>
23 <div class="field">
32 <div class="field">
24 <div class="label">
33 <div class="label">
25 <label for="repo_type">${_('Type')}:</label>
34 <label for="repo_type">${_('Type')}:</label>
@@ -34,7 +34,24 b''
34 <div class="input">
34 <div class="input">
35 ${h.text('repo_name',class_="medium")}
35 ${h.text('repo_name',class_="medium")}
36 </div>
36 </div>
37 </div>
37 </div>
38 <div class="field">
39 <div class="label">
40 <label for="clone_uri">${_('Clone uri')}:</label>
41 </div>
42 <div class="input">
43 ${h.text('clone_uri',class_="small")}
44 </div>
45 </div>
46 <div class="field">
47 <div class="label">
48 <label for="repo_group">${_('Repository group')}:</label>
49 </div>
50 <div class="input">
51 ${h.select('repo_group','',c.repo_groups,class_="medium")}
52 <span>${h.link_to(_('add new group'),h.url(''))}</span>
53 </div>
54 </div>
38 <div class="field">
55 <div class="field">
39 <div class="label">
56 <div class="label">
40 <label for="repo_type">${_('Type')}:</label>
57 <label for="repo_type">${_('Type')}:</label>
@@ -42,7 +59,7 b''
42 <div class="input">
59 <div class="input">
43 ${h.select('repo_type','hg',c.backends,class_="medium")}
60 ${h.select('repo_type','hg',c.backends,class_="medium")}
44 </div>
61 </div>
45 </div>
62 </div>
46 <div class="field">
63 <div class="field">
47 <div class="label label-textarea">
64 <div class="label label-textarea">
48 <label for="description">${_('Description')}:</label>
65 <label for="description">${_('Description')}:</label>
@@ -65,7 +65,17 b''
65 ${_('Fork of')} ${c.dbrepo.fork.repo_name}
65 ${_('Fork of')} ${c.dbrepo.fork.repo_name}
66 </a>
66 </a>
67 </span>
67 </span>
68 %endif
68 %endif
69 %if c.dbrepo.clone_uri:
70 <span style="margin-top:5px">
71 <a href="${h.url(str(c.dbrepo.clone_uri))}">
72 <img class="icon" alt="${_('remote clone')}"
73 title="${_('Clone from')} ${c.dbrepo.clone_uri}"
74 src="${h.url("/images/icons/connect.png")}"/>
75 ${_('Clone from')} ${c.dbrepo.clone_uri}
76 </a>
77 </span>
78 %endif
69 </div>
79 </div>
70 </div>
80 </div>
71
81
General Comments 0
You need to be logged in to leave comments. Login now