def delete(request, name): """Handle deleting repositories, showing a confirmation dialog first. On GET, display a confirmation page. On POST, delete the repository. """ for repo in gitweb.get_repo_list(): if repo['name'] == name and 'clone_progress' not in repo: break else: raise Http404 if request.method == 'POST': try: gitweb.delete_repo(name) messages.success(request, _('{name} deleted.').format(name=name)) except actions.ActionError as error: messages.error( request, _('Could not delete {name}: {error}').format(name=name, error=error), ) gitweb.app.update_service_access() return redirect(reverse_lazy('gitweb:index')) return TemplateResponse(request, 'gitweb_delete.html', { 'title': gitweb.app.info.name, 'name': name })
def get_context_data(self, *args, **kwargs): """Add repositories to the context data.""" context = super().get_context_data(*args, **kwargs) repos = gitweb.get_repo_list() context['repos'] = repos context['cloning'] = any('clone_progress' in repo for repo in repos) context['refresh_page_sec'] = 3 if context['cloning'] else None return context
def get_initial(self): """Load information about repository being edited.""" name = self.kwargs['name'] for repo in gitweb.get_repo_list(): if repo['name'] == name and 'clone_progress' not in repo: break else: raise Http404 return gitweb.repo_info(name)
def clean_name(self): """Check if the name is valid.""" name = self.cleaned_data['name'] if 'name' in self.initial and name == self.initial['name']: return name if name.endswith('.git'): name = name[:-4] for repo in gitweb.get_repo_list(): if name == repo['name']: raise ValidationError( _('A repository with this name already exists.')) return name
def clean_name(self): """Check if the name is valid.""" name = self.cleaned_data['name'] repo_name = name if is_repo_url(name): repo_name = get_name_from_url(name) if repo_name.endswith('.git'): repo_name = repo_name[:-4] for repo in gitweb.get_repo_list(): if repo_name == repo['name']: raise ValidationError( _('A repository with this name already exists.')) if is_repo_url(name): if not gitweb.repo_exists(name): raise ValidationError('Remote repository is not available.') return name