def repo_check(self, repo_name): c.repo = repo_name task_id = request.GET.get('task_id') if task_id and task_id not in ['None']: from kallithea import CELERY_ON from celery.result import AsyncResult if CELERY_ON: task = AsyncResult(task_id) if task.failed(): raise HTTPInternalServerError(task.traceback) repo = Repository.get_by_repo_name(repo_name) if repo and repo.repo_state == Repository.STATE_CREATED: if repo.clone_uri: clone_uri = repo.clone_uri_hidden h.flash(_('Created repository %s from %s') % (repo.repo_name, clone_uri), category='success') else: repo_url = h.link_to(repo.repo_name, h.url('summary_home', repo_name=repo.repo_name)) fork = repo.fork if fork: fork_name = fork.repo_name h.flash(h.literal(_('Forked repository %s as %s') % (fork_name, repo_url)), category='success') else: h.flash(h.literal(_('Created repository %s') % repo_url), category='success') return {'result': True} return {'result': False}
def repo_check(self, repo_name): c.repo = repo_name task_id = request.GET.get('task_id') if task_id and task_id not in ['None']: from kallithea import CELERY_ON from kallithea.lib import celerypylons if CELERY_ON: task = celerypylons.result.AsyncResult(task_id) if task.failed(): raise HTTPInternalServerError(task.traceback) repo = Repository.get_by_repo_name(repo_name) if repo and repo.repo_state == Repository.STATE_CREATED: if repo.clone_uri: h.flash(_('Created repository %s from %s') % (repo.repo_name, repo.clone_uri_hidden), category='success') else: repo_url = h.link_to( repo.repo_name, h.url('summary_home', repo_name=repo.repo_name)) fork = repo.fork if fork is not None: fork_name = fork.repo_name h.flash(h.literal( _('Forked repository %s as %s') % (fork_name, repo_url)), category='success') else: h.flash(h.literal(_('Created repository %s') % repo_url), category='success') return {'result': True} return {'result': False}
def create(self): """POST /users: Create a new item""" # url('users') c.default_extern_type = auth_internal.KallitheaAuthPlugin.name c.default_extern_name = auth_internal.KallitheaAuthPlugin.name user_model = UserModel() user_form = UserForm()() try: form_result = user_form.to_python(dict(request.POST)) user = user_model.create(form_result) usr = form_result['username'] action_logger(self.authuser, 'admin_created_user:%s' % usr, None, self.ip_addr, self.sa) h.flash(h.literal(_('Created user %s') % h.link_to(h.escape(usr), url('edit_user', id=user.user_id))), category='success') Session().commit() except formencode.Invalid as errors: return htmlfill.render( render('admin/users/user_add.html'), defaults=errors.value, errors=errors.error_dict or {}, prefix_error=False, encoding="UTF-8", force_defaults=False) except UserCreationError as e: h.flash(e, 'error') except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during creation of user %s') \ % request.POST.get('username'), category='error') raise HTTPFound(location=url('users'))
def __get_cs(self, rev, silent_empty=False): """ Safe way to get changeset if error occur it redirects to tip with proper message :param rev: revision to fetch :silent_empty: return None if repository is empty """ try: return c.db_repo_scm_instance.get_changeset(rev) except EmptyRepositoryError as e: if silent_empty: return None url_ = url('files_add_home', repo_name=c.repo_name, revision=0, f_path='', anchor='edit') add_new = h.link_to(_('Click here to add new file'), url_, class_="alert-link") h.flash(h.literal(_('There are no files yet. %s') % add_new), category='warning') raise HTTPNotFound() except (ChangesetDoesNotExistError, LookupError): msg = _('Such revision does not exist for this repository') h.flash(msg, category='error') raise HTTPNotFound() except RepositoryError as e: h.flash(safe_str(e), category='error') raise HTTPNotFound()
def create(self): """POST /users_groups: Create a new item""" # url('users_groups') users_group_form = UserGroupForm()() try: form_result = users_group_form.to_python(dict(request.POST)) ug = UserGroupModel().create( name=form_result['users_group_name'], description=form_result['user_group_description'], owner=self.authuser.user_id, active=form_result['users_group_active']) gr = form_result['users_group_name'] action_logger(self.authuser, 'admin_created_users_group:%s' % gr, None, self.ip_addr, self.sa) h.flash(h.literal( _('Created user group %s') % h.link_to(h.escape(gr), url('edit_users_group', id=ug.users_group_id))), category='success') Session().commit() except formencode.Invalid, errors: return htmlfill.render( render('admin/user_groups/user_group_add.html'), defaults=errors.value, errors=errors.error_dict or {}, prefix_error=False, encoding="UTF-8", force_defaults=False)
def _ignorews_url(GET, fileid=None): fileid = str(fileid) if fileid else None params = defaultdict(list) _update_with_GET(params, GET) lbl = _('Show whitespace') ig_ws = get_ignore_ws(fileid, GET) ln_ctx = get_line_ctx(fileid, GET) # global option if fileid is None: if ig_ws is None: params['ignorews'] += [1] lbl = _('Ignore whitespace') ctx_key = 'context' ctx_val = ln_ctx # per file options else: if ig_ws is None: params[fileid] += ['WS:1'] lbl = _('Ignore whitespace') ctx_key = fileid ctx_val = 'C:%s' % ln_ctx # if we have passed in ln_ctx pass it along to our params if ln_ctx: params[ctx_key] += [ctx_val] params['anchor'] = fileid icon = h.literal('<i class="icon-strike"></i>') return h.link_to(icon, h.url.current(**params), title=lbl, **{'data-toggle': 'tooltip'})
def create(self): users_group_form = UserGroupForm()() try: form_result = users_group_form.to_python(dict(request.POST)) ug = UserGroupModel().create(name=form_result['users_group_name'], description=form_result['user_group_description'], owner=request.authuser.user_id, active=form_result['users_group_active']) gr = form_result['users_group_name'] action_logger(request.authuser, 'admin_created_users_group:%s' % gr, None, request.ip_addr) h.flash(h.literal(_('Created user group %s') % h.link_to(h.escape(gr), url('edit_users_group', id=ug.users_group_id))), category='success') Session().commit() except formencode.Invalid as errors: return htmlfill.render( render('admin/user_groups/user_group_add.html'), defaults=errors.value, errors=errors.error_dict or {}, prefix_error=False, encoding="UTF-8", force_defaults=False) except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during creation of user group %s') \ % request.POST.get('users_group_name'), category='error') raise HTTPFound(location=url('users_groups'))
def create(self): """POST /users_groups: Create a new item""" # url('users_groups') users_group_form = UserGroupForm()() try: form_result = users_group_form.to_python(dict(request.POST)) ug = UserGroupModel().create(name=form_result['users_group_name'], description=form_result['user_group_description'], owner=self.authuser.user_id, active=form_result['users_group_active']) gr = form_result['users_group_name'] action_logger(self.authuser, 'admin_created_users_group:%s' % gr, None, self.ip_addr, self.sa) h.flash(h.literal(_('Created user group %s') % h.link_to(h.escape(gr), url('edit_users_group', id=ug.users_group_id))), category='success') Session().commit() except formencode.Invalid, errors: return htmlfill.render( render('admin/user_groups/user_group_add.html'), defaults=errors.value, errors=errors.error_dict or {}, prefix_error=False, encoding="UTF-8", force_defaults=False)
def settings_mapping(self): """GET /admin/settings/mapping: All items in the collection""" # url('admin_settings_mapping') c.active = 'mapping' if request.POST: rm_obsolete = request.POST.get('destroy', False) install_git_hooks = request.POST.get('hooks', False) invalidate_cache = request.POST.get('invalidate', False) log.debug('rescanning repo location with destroy obsolete=%s and ' 'install git hooks=%s' % (rm_obsolete,install_git_hooks)) if invalidate_cache: log.debug('invalidating all repositories cache') for repo in Repository.get_all(): ScmModel().mark_for_invalidation(repo.repo_name, delete=True) filesystem_repos = ScmModel().repo_scan() added, removed = repo2db_mapper(filesystem_repos, rm_obsolete, install_git_hook=install_git_hooks, user=c.authuser.username) h.flash(h.literal(_('Repositories successfully rescanned. Added: %s. Removed: %s.') % (', '.join(h.link_to(safe_unicode(repo_name), h.url('summary_home', repo_name=repo_name)) for repo_name in added) or '-', ', '.join(h.escape(safe_unicode(repo_name)) for repo_name in removed) or '-')), category='success') return redirect(url('admin_settings_mapping')) defaults = Setting.get_app_settings() defaults.update(self._get_hg_ui_settings()) return htmlfill.render( render('admin/settings/settings.html'), defaults=defaults, encoding="UTF-8", force_defaults=False)
def create(self): users_group_form = UserGroupForm()() try: form_result = users_group_form.to_python(dict(request.POST)) ug = UserGroupModel().create( name=form_result['users_group_name'], description=form_result['user_group_description'], owner=request.authuser.user_id, active=form_result['users_group_active']) gr = form_result['users_group_name'] action_logger(request.authuser, 'admin_created_users_group:%s' % gr, None, request.ip_addr) h.flash(h.literal( _('Created user group %s') % h.link_to(h.escape(gr), url('edit_users_group', id=ug.users_group_id))), category='success') Session().commit() except formencode.Invalid as errors: return htmlfill.render( render('admin/user_groups/user_group_add.html'), defaults=errors.value, errors=errors.error_dict or {}, prefix_error=False, encoding="UTF-8", force_defaults=False) except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during creation of user group %s') \ % request.POST.get('users_group_name'), category='error') raise HTTPFound(location=url('users_groups'))
def _ignorews_url(GET, fileid=None): fileid = str(fileid) if fileid else None params = defaultdict(list) _update_with_GET(params, GET) lbl = _('Show whitespace') ig_ws = get_ignore_ws(fileid, GET) ln_ctx = get_line_ctx(fileid, GET) # global option if fileid is None: if ig_ws is None: params['ignorews'] += [1] lbl = _('Ignore whitespace') ctx_key = 'context' ctx_val = ln_ctx # per file options else: if ig_ws is None: params[fileid] += ['WS:1'] lbl = _('Ignore whitespace') ctx_key = fileid ctx_val = 'C:%s' % ln_ctx # if we have passed in ln_ctx pass it along to our params if ln_ctx: params[ctx_key] += [ctx_val] params['anchor'] = fileid icon = h.literal('<i class="icon-strike"></i>') return h.link_to(icon, h.url.current(**params), title=lbl, class_='tooltip')
def index(self): org_repo = c.db_repo org_scm_instance = org_repo.scm_instance try: org_scm_instance.get_changeset() except EmptyRepositoryError, e: h.flash(h.literal(_('There are no changesets yet')), category='warning') redirect(url('summary_home', repo_name=org_repo.repo_name))
def _redirect_to_login(message=None): """Return an exception that must be raised. It will redirect to the login page which will redirect back to the current URL after authentication. The optional message will be shown in a flash message.""" from kallithea.lib import helpers as h if message: h.flash(h.literal(message), category='warning') p = request.path_qs log.debug('Redirecting to login page, origin: %s', p) return HTTPFound(location=url('login_home', came_from=p))
def __wrapper(self, func, *fargs, **fkwargs): cls = fargs[0] user = cls.authuser loc = "%s:%s" % (cls.__class__.__name__, func.__name__) # check if our IP is allowed ip_access_valid = True if not user.ip_allowed: from kallithea.lib import helpers as h h.flash(h.literal(_('IP %s not allowed' % (user.ip_addr))), category='warning') ip_access_valid = False # check if we used an APIKEY and it's a valid one # defined whitelist of controllers which API access will be enabled _api_key = request.GET.get('api_key', '') api_access_valid = allowed_api_access(loc, api_key=_api_key) # explicit controller is enabled or API is in our whitelist if self.api_access or api_access_valid: log.debug('Checking API KEY access for %s' % cls) if _api_key and _api_key in user.api_keys: api_access_valid = True log.debug('API KEY ****%s is VALID' % _api_key[-4:]) else: api_access_valid = False if not _api_key: log.debug("API KEY *NOT* present in request") else: log.warning("API KEY ****%s *NOT* valid" % _api_key[-4:]) # CSRF protection - POSTs with session auth must contain correct token if request.POST and user.is_authenticated and not api_access_valid: token = request.POST.get(secure_form.token_key) if not token or token != secure_form.authentication_token(): log.error('CSRF check failed') return abort(403) log.debug('Checking if %s is authenticated @ %s' % (user.username, loc)) reason = 'RegularAuth' if user.is_authenticated else 'APIAuth' if ip_access_valid and (user.is_authenticated or api_access_valid): log.info('user %s authenticating with:%s IS authenticated on func %s ' % (user, reason, loc) ) return func(*fargs, **fkwargs) else: log.warning('user %s authenticating with:%s NOT authenticated on func: %s: ' 'IP_ACCESS:%s API_ACCESS:%s' % (user, reason, loc, ip_access_valid, api_access_valid) ) p = url.current() log.debug('redirecting to login page with %s' % p) return redirect(url('login_home', came_from=p))
def _get_ref_rev(repo, ref_type, ref_name, returnempty=False): """ Safe way to get changeset. If error occurs show error. """ from kallithea.lib import helpers as h try: return repo.scm_instance.get_ref_revision(ref_type, ref_name) except EmptyRepositoryError as e: if returnempty: return repo.scm_instance.EMPTY_CHANGESET h.flash(h.literal(_('There are no changesets yet')), category='error') raise webob.exc.HTTPNotFound() except ChangesetDoesNotExistError as e: h.flash(h.literal(_('Changeset not found')), category='error') raise webob.exc.HTTPNotFound() except RepositoryError as e: log.error(traceback.format_exc()) h.flash(safe_str(e), category='error') raise webob.exc.HTTPBadRequest()
def index(self): org_repo = c.db_repo org_scm_instance = org_repo.scm_instance try: org_scm_instance.get_changeset() except EmptyRepositoryError as e: h.flash(h.literal(_('There are no changesets yet')), category='warning') raise HTTPFound(location=url('summary_home', repo_name=org_repo.repo_name)) org_rev = request.GET.get('rev_end') # rev_start is not directly useful - its parent could however be used # as default for other and thus give a simple compare view rev_start = request.GET.get('rev_start') other_rev = None if rev_start: starters = org_repo.get_changeset(rev_start).parents if starters: other_rev = starters[0].raw_id else: other_rev = org_repo.scm_instance.EMPTY_CHANGESET branch = request.GET.get('branch') c.cs_repos = [(org_repo.repo_name, org_repo.repo_name)] c.default_cs_repo = org_repo.repo_name c.cs_refs, c.default_cs_ref = self._get_repo_refs(org_scm_instance, rev=org_rev, branch=branch) default_cs_ref_type, default_cs_branch, default_cs_rev = c.default_cs_ref.split(':') if default_cs_ref_type != 'branch': default_cs_branch = org_repo.get_changeset(default_cs_rev).branch # add org repo to other so we can open pull request against peer branches on itself c.a_repos = [(org_repo.repo_name, '%s (self)' % org_repo.repo_name)] if org_repo.parent: # add parent of this fork also and select it. # use the same branch on destination as on source, if available. c.a_repos.append((org_repo.parent.repo_name, '%s (parent)' % org_repo.parent.repo_name)) c.a_repo = org_repo.parent c.a_refs, c.default_a_ref = self._get_repo_refs( org_repo.parent.scm_instance, branch=default_cs_branch, rev=other_rev) else: c.a_repo = org_repo c.a_refs, c.default_a_ref = self._get_repo_refs(org_scm_instance, rev=other_rev) # gather forks and add to this list ... even though it is rare to # request forks to pull from their parent for fork in org_repo.forks: c.a_repos.append((fork.repo_name, fork.repo_name)) return render('/pullrequests/pullrequest.html')
def __get_cs(rev, repo): """ Safe way to get changeset. If error occur fail with error message. :param rev: revision to fetch :param repo: repo instance """ try: return c.db_repo_scm_instance.get_changeset(rev) except EmptyRepositoryError, e: h.flash(h.literal(_('There are no changesets yet')), category='error')
def __wrapper(self, func, *fargs, **fkwargs): cls = fargs[0] user = cls.authuser loc = "%s:%s" % (cls.__class__.__name__, func.__name__) # check if our IP is allowed ip_access_valid = True if not user.ip_allowed: from kallithea.lib import helpers as h h.flash(h.literal(_('IP %s not allowed' % (user.ip_addr))), category='warning') ip_access_valid = False # check if we used an APIKEY and it's a valid one # defined whitelist of controllers which API access will be enabled _api_key = request.GET.get('api_key', '') api_access_valid = allowed_api_access(loc, api_key=_api_key) # explicit controller is enabled or API is in our whitelist if self.api_access or api_access_valid: log.debug('Checking API KEY access for %s' % cls) if _api_key and _api_key in user.api_keys: api_access_valid = True log.debug('API KEY ****%s is VALID' % _api_key[-4:]) else: api_access_valid = False if not _api_key: log.debug("API KEY *NOT* present in request") else: log.warning("API KEY ****%s *NOT* valid" % _api_key[-4:]) log.debug('Checking if %s is authenticated @ %s' % (user.username, loc)) reason = 'RegularAuth' if user.is_authenticated else 'APIAuth' if ip_access_valid and (user.is_authenticated or api_access_valid): log.info( 'user %s authenticating with:%s IS authenticated on func %s ' % (user, reason, loc)) return func(*fargs, **fkwargs) else: log.warning( 'user %s authenticating with:%s NOT authenticated on func: %s: ' 'IP_ACCESS:%s API_ACCESS:%s' % (user, reason, loc, ip_access_valid, api_access_valid)) p = url.current() log.debug('redirecting to login page with %s' % p) return redirect(url('login_home', came_from=p))
def __get_cs(rev, repo): """ Safe way to get changeset. If error occur fail with error message. :param rev: revision to fetch :param repo: repo instance """ try: return c.db_repo_scm_instance.get_changeset(rev) except EmptyRepositoryError as e: h.flash(h.literal(_('There are no changesets yet')), category='error') except RepositoryError as e: log.error(traceback.format_exc()) h.flash(safe_str(e), category='error') raise HTTPBadRequest()
def settings_mapping(self): c.active = 'mapping' if request.POST: rm_obsolete = request.POST.get('destroy', False) install_git_hooks = request.POST.get('hooks', False) overwrite_git_hooks = request.POST.get('hooks_overwrite', False); invalidate_cache = request.POST.get('invalidate', False) log.debug('rescanning repo location with destroy obsolete=%s, ' 'install git hooks=%s and ' 'overwrite git hooks=%s' % (rm_obsolete, install_git_hooks, overwrite_git_hooks)) filesystem_repos = ScmModel().repo_scan() added, removed = repo2db_mapper(filesystem_repos, rm_obsolete, install_git_hooks=install_git_hooks, user=request.authuser.username, overwrite_git_hooks=overwrite_git_hooks) h.flash(h.literal(_('Repositories successfully rescanned. Added: %s. Removed: %s.') % (', '.join(h.link_to(safe_unicode(repo_name), h.url('summary_home', repo_name=repo_name)) for repo_name in added) or '-', ', '.join(h.escape(safe_unicode(repo_name)) for repo_name in removed) or '-')), category='success') if invalidate_cache: log.debug('invalidating all repositories cache') i = 0 for repo in Repository.query(): try: ScmModel().mark_for_invalidation(repo.repo_name) i += 1 except VCSError as e: log.warning('VCS error invalidating %s: %s', repo.repo_name, e) h.flash(_('Invalidated %s repositories') % i, category='success') raise HTTPFound(location=url('admin_settings_mapping')) defaults = Setting.get_app_settings() defaults.update(self._get_hg_ui_settings()) return htmlfill.render( render('admin/settings/settings.html'), defaults=defaults, encoding="UTF-8", force_defaults=False)
def _context_url(GET, fileid=None): """ Generates url for context lines :param fileid: """ fileid = str(fileid) if fileid else None ig_ws = get_ignore_ws(fileid, GET) ln_ctx = (get_line_ctx(fileid, GET) or 3) * 2 params = defaultdict(list) _update_with_GET(params, GET) # global option if fileid is None: if ln_ctx > 0: params['context'] += [ln_ctx] if ig_ws: ig_ws_key = 'ignorews' ig_ws_val = 1 # per file option else: params[fileid] += ['C:%s' % ln_ctx] ig_ws_key = fileid ig_ws_val = 'WS:%s' % 1 if ig_ws: params[ig_ws_key] += [ig_ws_val] lbl = _('increase diff context to %(num)s lines') % {'num': ln_ctx} params['anchor'] = fileid icon = h.literal('<i class="icon-sort"></i>') return h.link_to(icon, h.url.current(**params), title=lbl, class_='tooltip')
def __before__(self): super(BaseRepoController, self).__before__() if c.repo_name: # extracted from routes _dbr = Repository.get_by_repo_name(c.repo_name) if not _dbr: return log.debug('Found repository in database %s with state `%s`' % (safe_unicode(_dbr), safe_unicode(_dbr.repo_state))) route = getattr(request.environ.get('routes.route'), 'name', '') # allow to delete repos that are somehow damages in filesystem if route in ['delete_repo']: return if _dbr.repo_state in [Repository.STATE_PENDING]: if route in ['repo_creating_home']: return check_url = url('repo_creating_home', repo_name=c.repo_name) return redirect(check_url) dbr = c.db_repo = _dbr c.db_repo_scm_instance = c.db_repo.scm_instance if c.db_repo_scm_instance is None: log.error( '%s this repository is present in database but it ' 'cannot be created as an scm instance', c.repo_name) from kallithea.lib import helpers as h h.flash(h.literal(_('Repository not found in the filesystem')), category='error') raise paste.httpexceptions.HTTPNotFound() # some globals counter for menu c.repository_followers = self.scm_model.get_followers(dbr) c.repository_forks = self.scm_model.get_forks(dbr) c.repository_pull_requests = self.scm_model.get_pull_requests(dbr) c.repository_following = self.scm_model.is_following_repo( c.repo_name, self.authuser.user_id)
def create(self): """POST /users: Create a new item""" # url('users') c.default_extern_type = auth_modules.auth_internal.KallitheaAuthPlugin.name user_model = UserModel() user_form = UserForm()() try: form_result = user_form.to_python(dict(request.POST)) user = user_model.create(form_result) usr = form_result['username'] action_logger(self.authuser, 'admin_created_user:%s' % usr, None, self.ip_addr, self.sa) h.flash(h.literal(_('Created user %s') % h.link_to(h.escape(usr), url('edit_user', id=user.user_id))), category='success') Session().commit() except formencode.Invalid, errors: return htmlfill.render( render('admin/users/user_add.html'), defaults=errors.value, errors=errors.error_dict or {}, prefix_error=False, encoding="UTF-8", force_defaults=False)
def __before__(self): super(BaseRepoController, self).__before__() if c.repo_name: # extracted from routes _dbr = Repository.get_by_repo_name(c.repo_name) if not _dbr: return log.debug('Found repository in database %s with state `%s`', safe_unicode(_dbr), safe_unicode(_dbr.repo_state)) route = getattr(request.environ.get('routes.route'), 'name', '') # allow to delete repos that are somehow damages in filesystem if route in ['delete_repo']: return if _dbr.repo_state in [Repository.STATE_PENDING]: if route in ['repo_creating_home']: return check_url = url('repo_creating_home', repo_name=c.repo_name) raise webob.exc.HTTPFound(location=check_url) dbr = c.db_repo = _dbr c.db_repo_scm_instance = c.db_repo.scm_instance if c.db_repo_scm_instance is None: log.error('%s this repository is present in database but it ' 'cannot be created as an scm instance', c.repo_name) from kallithea.lib import helpers as h h.flash(h.literal(_('Repository not found in the filesystem')), category='error') raise paste.httpexceptions.HTTPNotFound() # some globals counter for menu c.repository_followers = self.scm_model.get_followers(dbr) c.repository_forks = self.scm_model.get_forks(dbr) c.repository_pull_requests = self.scm_model.get_pull_requests(dbr) c.repository_following = self.scm_model.is_following_repo( c.repo_name, self.authuser.user_id)
def _context_url(GET, fileid=None): """ Generates url for context lines :param fileid: """ fileid = str(fileid) if fileid else None ig_ws = get_ignore_ws(fileid, GET) ln_ctx = (get_line_ctx(fileid, GET) or 3) * 2 params = defaultdict(list) _update_with_GET(params, GET) # global option if fileid is None: if ln_ctx > 0: params['context'] += [ln_ctx] if ig_ws: ig_ws_key = 'ignorews' ig_ws_val = 1 # per file option else: params[fileid] += ['C:%s' % ln_ctx] ig_ws_key = fileid ig_ws_val = 'WS:%s' % 1 if ig_ws: params[ig_ws_key] += [ig_ws_val] lbl = _('Increase diff context to %(num)s lines') % {'num': ln_ctx} params['anchor'] = fileid icon = h.literal('<i class="icon-sort"></i>') return h.link_to(icon, h.url.current(**params), title=lbl, **{'data-toggle': 'tooltip'})
def create(self): """POST /users: Create a new item""" # url('users') c.default_extern_type = auth_modules.auth_internal.KallitheaAuthPlugin.name user_model = UserModel() user_form = UserForm()() try: form_result = user_form.to_python(dict(request.POST)) user = user_model.create(form_result) usr = form_result['username'] action_logger(self.authuser, 'admin_created_user:%s' % usr, None, self.ip_addr, self.sa) h.flash(h.literal( _('Created user %s') % h.link_to(h.escape(usr), url('edit_user', id=user.user_id))), category='success') Session().commit() except formencode.Invalid, errors: return htmlfill.render(render('admin/users/user_add.html'), defaults=errors.value, errors=errors.error_dict or {}, prefix_error=False, encoding="UTF-8", force_defaults=False)