Пример #1
0
 def get_users_js(self):
     users = self.sa.query(User).filter(User.active == True).all()
     return json.dumps([
         {
             'id': u.user_id,
             'fname': h.escape(u.name),
             'lname': h.escape(u.lastname),
             'nname': u.username,
             'gravatar_lnk': h.gravatar_url(u.email, size=28),
             'gravatar_size': 14,
         } for u in users]
     )
Пример #2
0
 def get_users_js(self):
     users = User.query() \
         .filter(User.active == True) \
         .order_by(User.name, User.lastname) \
         .all()
     return [
         {
             'id': u.user_id,
             'fname': h.escape(u.name),
             'lname': h.escape(u.lastname),
             'nname': u.username,
             'gravatar_lnk': h.gravatar_url(u.email, size=28, default='default'),
             'gravatar_size': 14,
         } for u in users]
Пример #3
0
    def index(self, format='html'):
        """GET /users: All items in the collection"""
        # url('users')

        c.users_list = User.query().order_by(User.username) \
                        .filter(User.username != User.DEFAULT_USER) \
                        .order_by(func.lower(User.username)) \
                        .all()

        users_data = []
        total_records = len(c.users_list)
        _tmpl_lookup = kallithea.CONFIG['pylons.app_globals'].mako_lookup
        template = _tmpl_lookup.get_template('data_table/_dt_elements.html')

        grav_tmpl = '<div class="gravatar">%s</div>'

        username = lambda user_id, username: (
                template.get_def("user_name")
                .render(user_id, username, _=_, h=h, c=c))

        user_actions = lambda user_id, username: (
                template.get_def("user_actions")
                .render(user_id, username, _=_, h=h, c=c))

        for user in c.users_list:
            users_data.append({
                "gravatar": grav_tmpl % h.gravatar(user.email, size=20),
                "raw_name": user.username,
                "username": username(user.user_id, user.username),
                "firstname": h.escape(user.name),
                "lastname": h.escape(user.lastname),
                "last_login": h.fmt_date(user.last_login),
                "last_login_raw": datetime_to_time(user.last_login),
                "active": h.boolicon(user.active),
                "admin": h.boolicon(user.admin),
                "extern_type": user.extern_type,
                "extern_name": user.extern_name,
                "action": user_actions(user.user_id, user.username),
            })

        c.data = json.dumps({
            "totalRecords": total_records,
            "startIndex": 0,
            "sort": None,
            "dir": "asc",
            "records": users_data
        })

        return render('admin/users/users.html')
Пример #4
0
    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)
Пример #5
0
 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'))
Пример #6
0
    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'))
Пример #7
0
    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)
Пример #8
0
    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'))
Пример #9
0
    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)
Пример #10
0
    def index(self, format='html'):
        c.users_list = User.query().order_by(User.username) \
                        .filter_by(is_default_user=False) \
                        .order_by(func.lower(User.username)) \
                        .all()

        users_data = []
        total_records = len(c.users_list)
        _tmpl_lookup = app_globals.mako_lookup
        template = _tmpl_lookup.get_template('data_table/_dt_elements.html')

        grav_tmpl = '<div class="gravatar">%s</div>'

        username = lambda user_id, username: (
                template.get_def("user_name")
                .render(user_id, username, _=_, h=h, c=c))

        user_actions = lambda user_id, username: (
                template.get_def("user_actions")
                .render(user_id, username, _=_, h=h, c=c))

        for user in c.users_list:
            users_data.append({
                "gravatar": grav_tmpl % h.gravatar(user.email, size=20),
                "raw_name": user.username,
                "username": username(user.user_id, user.username),
                "firstname": h.escape(user.name),
                "lastname": h.escape(user.lastname),
                "last_login": h.fmt_date(user.last_login),
                "last_login_raw": datetime_to_time(user.last_login),
                "active": h.boolicon(user.active),
                "admin": h.boolicon(user.admin),
                "extern_type": user.extern_type,
                "extern_name": user.extern_name,
                "action": user_actions(user.user_id, user.username),
            })

        c.data = {
            "totalRecords": total_records,
            "startIndex": 0,
            "sort": None,
            "dir": "asc",
            "records": users_data
        }

        return render('admin/users/users.html')
Пример #11
0
def wrapped_diff(filenode_old,
                 filenode_new,
                 cut_off_limit=None,
                 ignore_whitespace=True,
                 line_context=3,
                 enable_comments=False):
    """
    returns a wrapped diff into a table, checks for cut_off_limit and presents
    proper message
    """

    if filenode_old is None:
        filenode_old = FileNode(filenode_new.path, '', EmptyChangeset())

    op = None
    a_path = filenode_old.path  # default, might be overriden by actual rename in diff
    if filenode_old.is_binary or filenode_new.is_binary:
        diff = wrap_to_table(_('Binary file'))
        stats = (0, 0)

    elif cut_off_limit != -1 and (cut_off_limit is None or
                                  (filenode_old.size < cut_off_limit
                                   and filenode_new.size < cut_off_limit)):

        f_gitdiff = get_gitdiff(filenode_old,
                                filenode_new,
                                ignore_whitespace=ignore_whitespace,
                                context=line_context)
        diff_processor = DiffProcessor(f_gitdiff, format='gitdiff')
        _parsed = diff_processor.prepare()
        if _parsed:  # there should be exactly one element, for the specified file
            f = _parsed[0]
            op = f['operation']
            a_path = f['old_filename']

        diff = diff_processor.as_html(enable_comments=enable_comments)
        stats = diff_processor.stat()

    else:
        diff = wrap_to_table(
            _('Changeset was too big and was cut off, use '
              'diff menu to display this diff'))
        stats = (0, 0)

    if not diff:
        submodules = filter(lambda o: isinstance(o, SubModuleNode),
                            [filenode_new, filenode_old])
        if submodules:
            diff = wrap_to_table(escape('Submodule %r' % submodules[0]))
        else:
            diff = wrap_to_table(_('No changes detected'))

    cs1 = filenode_old.changeset.raw_id
    cs2 = filenode_new.changeset.raw_id

    return cs1, cs2, a_path, diff, stats, op
Пример #12
0
 def get_users_js(self):
     users = User.query() \
         .filter(User.active == True) \
         .order_by(User.name, User.lastname) \
         .all()
     return [{
         'id':
         u.user_id,
         'fname':
         h.escape(u.name),
         'lname':
         h.escape(u.lastname),
         'nname':
         u.username,
         'gravatar_lnk':
         h.gravatar_url(u.email, size=28, default='default'),
         'gravatar_size':
         14,
     } for u in users]
Пример #13
0
    def index(self, format='html'):
        _list = RepoGroup.query(sorted=True).all()
        group_iter = RepoGroupList(_list, perm_level='admin')
        repo_groups_data = []
        total_records = len(group_iter)
        _tmpl_lookup = app_globals.mako_lookup
        template = _tmpl_lookup.get_template('data_table/_dt_elements.html')

        repo_group_name = lambda repo_group_name, children_groups: (
            template.get_def("repo_group_name").render(
                repo_group_name, children_groups, _=_, h=h, c=c))
        repo_group_actions = lambda repo_group_id, repo_group_name, gr_count: (
            template.get_def("repo_group_actions").render(repo_group_id,
                                                          repo_group_name,
                                                          gr_count,
                                                          _=_,
                                                          h=h,
                                                          c=c,
                                                          ungettext=ungettext))

        for repo_gr in group_iter:
            children_groups = map(
                h.safe_unicode,
                itertools.chain((g.name for g in repo_gr.parents),
                                (x.name for x in [repo_gr])))
            repo_count = repo_gr.repositories.count()
            repo_groups_data.append({
                "raw_name":
                repo_gr.group_name,
                "group_name":
                repo_group_name(repo_gr.group_name, children_groups),
                "desc":
                h.escape(repo_gr.group_description),
                "repos":
                repo_count,
                "owner":
                h.person(repo_gr.owner),
                "action":
                repo_group_actions(repo_gr.group_id, repo_gr.group_name,
                                   repo_count)
            })

        c.data = {
            "totalRecords": total_records,
            "startIndex": 0,
            "sort": None,
            "dir": "asc",
            "records": repo_groups_data
        }

        return render('admin/repo_groups/repo_groups.html')
Пример #14
0
def wrapped_diff(filenode_old, filenode_new, cut_off_limit=None,
                ignore_whitespace=True, line_context=3,
                enable_comments=False):
    """
    returns a wrapped diff into a table, checks for cut_off_limit and presents
    proper message
    """

    if filenode_old is None:
        filenode_old = FileNode(filenode_new.path, '', EmptyChangeset())

    op = None
    a_path = filenode_old.path # default, might be overriden by actual rename in diff
    if filenode_old.is_binary or filenode_new.is_binary:
        diff = wrap_to_table(_('Binary file'))
        stats = (0, 0)

    elif cut_off_limit != -1 and (
            cut_off_limit is None or
            (filenode_old.size < cut_off_limit and filenode_new.size < cut_off_limit)):

        f_gitdiff = get_gitdiff(filenode_old, filenode_new,
                                ignore_whitespace=ignore_whitespace,
                                context=line_context)
        diff_processor = DiffProcessor(f_gitdiff, format='gitdiff')
        _parsed = diff_processor.prepare()
        if _parsed: # there should be exactly one element, for the specified file
            f = _parsed[0]
            op = f['operation']
            a_path = f['old_filename']

        diff = diff_processor.as_html(enable_comments=enable_comments)
        stats = diff_processor.stat()

    else:
        diff = wrap_to_table(_('Changeset was too big and was cut off, use '
                               'diff menu to display this diff'))
        stats = (0, 0)

    if not diff:
        submodules = filter(lambda o: isinstance(o, SubModuleNode),
                            [filenode_new, filenode_old])
        if submodules:
            diff = wrap_to_table(escape('Submodule %r' % submodules[0]))
        else:
            diff = wrap_to_table(_('No changes detected'))

    cs1 = filenode_old.changeset.raw_id
    cs2 = filenode_new.changeset.raw_id

    return cs1, cs2, a_path, diff, stats, op
Пример #15
0
def wrapped_diff(filenode_old,
                 filenode_new,
                 cut_off_limit=None,
                 ignore_whitespace=True,
                 line_context=3,
                 enable_comments=False):
    """
    returns a wrapped diff into a table, checks for cut_off_limit and presents
    proper message
    """

    if filenode_old is None:
        filenode_old = FileNode(filenode_new.path, '', EmptyChangeset())

    if filenode_old.is_binary or filenode_new.is_binary:
        diff = wrap_to_table(_('Binary file'))
        stats = (0, 0)
        size = 0

    elif cut_off_limit != -1 and (cut_off_limit is None or
                                  (filenode_old.size < cut_off_limit
                                   and filenode_new.size < cut_off_limit)):

        f_gitdiff = get_gitdiff(filenode_old,
                                filenode_new,
                                ignore_whitespace=ignore_whitespace,
                                context=line_context)
        diff_processor = DiffProcessor(f_gitdiff, format='gitdiff')

        diff = diff_processor.as_html(enable_comments=enable_comments)
        stats = diff_processor.stat()
        size = len(diff or '')
    else:
        diff = wrap_to_table(
            _('Changeset was too big and was cut off, use '
              'diff menu to display this diff'))
        stats = (0, 0)
        size = 0
    if not diff:
        submodules = filter(lambda o: isinstance(o, SubModuleNode),
                            [filenode_new, filenode_old])
        if submodules:
            diff = wrap_to_table(escape('Submodule %r' % submodules[0]))
        else:
            diff = wrap_to_table(_('No changes detected'))

    cs1 = filenode_old.changeset.raw_id
    cs2 = filenode_new.changeset.raw_id

    return size, cs1, cs2, diff, stats
Пример #16
0
def wrapped_diff(filenode_old, filenode_new, diff_limit=None,
                ignore_whitespace=True, line_context=3,
                enable_comments=False):
    """
    Returns a file diff wrapped into a table.
    Checks for diff_limit and presents a message if the diff is too big.
    """
    if filenode_old is None:
        filenode_old = FileNode(filenode_new.path, '', EmptyChangeset())

    op = None
    a_path = filenode_old.path # default, might be overriden by actual rename in diff
    if filenode_old.is_binary or filenode_new.is_binary:
        html_diff = wrap_to_table(_('Binary file'))
        stats = (0, 0)

    elif diff_limit != -1 and (
            diff_limit is None or
            (filenode_old.size < diff_limit and filenode_new.size < diff_limit)):

        raw_diff = get_gitdiff(filenode_old, filenode_new,
                                ignore_whitespace=ignore_whitespace,
                                context=line_context)
        diff_processor = DiffProcessor(raw_diff)
        if diff_processor.parsed: # there should be exactly one element, for the specified file
            f = diff_processor.parsed[0]
            op = f['operation']
            a_path = f['old_filename']

        html_diff = as_html(parsed_lines=diff_processor.parsed, enable_comments=enable_comments)
        stats = diff_processor.stat()

    else:
        html_diff = wrap_to_table(_('Changeset was too big and was cut off, use '
                               'diff menu to display this diff'))
        stats = (0, 0)

    if not html_diff:
        submodules = [o for o in [filenode_new, filenode_old] if isinstance(o, SubModuleNode)]
        if submodules:
            html_diff = wrap_to_table(h.escape('Submodule %r' % submodules[0]))
        else:
            html_diff = wrap_to_table(_('No changes detected'))

    cs1 = filenode_old.changeset.raw_id
    cs2 = filenode_new.changeset.raw_id

    return cs1, cs2, a_path, html_diff, stats, op
Пример #17
0
    def index(self, format='html'):
        """GET /repo_groups: All items in the collection"""
        # url('repos_groups')
        _list = RepoGroup.query()\
                    .order_by(func.lower(RepoGroup.group_name))\
                    .all()
        group_iter = RepoGroupList(_list, perm_set=['group.admin'])
        repo_groups_data = []
        total_records = len(group_iter)
        _tmpl_lookup = kallithea.CONFIG['pylons.app_globals'].mako_lookup
        template = _tmpl_lookup.get_template('data_table/_dt_elements.html')

        repo_group_name = lambda repo_group_name, children_groups: (
            template.get_def("repo_group_name")
            .render(repo_group_name, children_groups, _=_, h=h, c=c)
        )
        repo_group_actions = lambda repo_group_id, repo_group_name, gr_count: (
            template.get_def("repo_group_actions")
            .render(repo_group_id, repo_group_name, gr_count, _=_, h=h, c=c,
                    ungettext=ungettext)
        )

        for repo_gr in group_iter:
            children_groups = map(h.safe_unicode,
                itertools.chain((g.name for g in repo_gr.parents),
                                (x.name for x in [repo_gr])))
            repo_count = repo_gr.repositories.count()
            repo_groups_data.append({
                "raw_name": repo_gr.group_name,
                "group_name": repo_group_name(repo_gr.group_name, children_groups),
                "desc": h.escape(repo_gr.group_description),
                "repos": repo_count,
                "owner": h.person(repo_gr.user),
                "action": repo_group_actions(repo_gr.group_id, repo_gr.group_name,
                                             repo_count)
            })

        c.data = json.dumps({
            "totalRecords": total_records,
            "startIndex": 0,
            "sort": None,
            "dir": "asc",
            "records": repo_groups_data
        })

        return render('admin/repo_groups/repo_groups.html')
Пример #18
0
    def index(self, format='html'):
        _list = UserGroup.query() \
                        .order_by(func.lower(UserGroup.users_group_name)) \
                        .all()
        group_iter = UserGroupList(_list, perm_level='admin')
        user_groups_data = []
        total_records = len(group_iter)
        _tmpl_lookup = app_globals.mako_lookup
        template = _tmpl_lookup.get_template('data_table/_dt_elements.html')

        user_group_name = lambda user_group_id, user_group_name: (
            template.get_def("user_group_name").render(
                user_group_id, user_group_name, _=_, h=h, c=c))
        user_group_actions = lambda user_group_id, user_group_name: (
            template.get_def("user_group_actions").render(
                user_group_id, user_group_name, _=_, h=h, c=c))
        for user_gr in group_iter:

            user_groups_data.append({
                "raw_name":
                user_gr.users_group_name,
                "group_name":
                user_group_name(user_gr.users_group_id,
                                user_gr.users_group_name),
                "desc":
                h.escape(user_gr.user_group_description),
                "members":
                len(user_gr.members),
                "active":
                h.boolicon(user_gr.users_group_active),
                "owner":
                h.person(user_gr.owner.username),
                "action":
                user_group_actions(user_gr.users_group_id,
                                   user_gr.users_group_name)
            })

        c.data = {
            "totalRecords": total_records,
            "startIndex": 0,
            "sort": None,
            "dir": "asc",
            "records": user_groups_data
        }

        return render('admin/user_groups/user_groups.html')
Пример #19
0
def wrapped_diff(filenode_old, filenode_new, cut_off_limit=None,
                ignore_whitespace=True, line_context=3,
                enable_comments=False):
    """
    returns a wrapped diff into a table, checks for cut_off_limit and presents
    proper message
    """

    if filenode_old is None:
        filenode_old = FileNode(filenode_new.path, '', EmptyChangeset())

    if filenode_old.is_binary or filenode_new.is_binary:
        diff = wrap_to_table(_('Binary file'))
        stats = (0, 0)
        size = 0

    elif cut_off_limit != -1 and (cut_off_limit is None or
    (filenode_old.size < cut_off_limit and filenode_new.size < cut_off_limit)):

        f_gitdiff = get_gitdiff(filenode_old, filenode_new,
                                ignore_whitespace=ignore_whitespace,
                                context=line_context)
        diff_processor = DiffProcessor(f_gitdiff, format='gitdiff')

        diff = diff_processor.as_html(enable_comments=enable_comments)
        stats = diff_processor.stat()
        size = len(diff or '')
    else:
        diff = wrap_to_table(_('Changeset was too big and was cut off, use '
                               'diff menu to display this diff'))
        stats = (0, 0)
        size = 0
    if not diff:
        submodules = filter(lambda o: isinstance(o, SubModuleNode),
                            [filenode_new, filenode_old])
        if submodules:
            diff = wrap_to_table(escape('Submodule %r' % submodules[0]))
        else:
            diff = wrap_to_table(_('No changes detected'))

    cs1 = filenode_old.changeset.raw_id
    cs2 = filenode_new.changeset.raw_id

    return size, cs1, cs2, diff, stats
Пример #20
0
    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)
Пример #21
0
    def index(self, format='html'):
        _list = RepoGroup.query(sorted=True).all()
        group_iter = RepoGroupList(_list, perm_level='admin')
        repo_groups_data = []
        total_records = len(group_iter)
        _tmpl_lookup = app_globals.mako_lookup
        template = _tmpl_lookup.get_template('data_table/_dt_elements.html')

        repo_group_name = lambda repo_group_name, children_groups: (
            template.get_def("repo_group_name")
            .render(repo_group_name, children_groups, _=_, h=h, c=c)
        )
        repo_group_actions = lambda repo_group_id, repo_group_name, gr_count: (
            template.get_def("repo_group_actions")
            .render(repo_group_id, repo_group_name, gr_count, _=_, h=h, c=c,
                    ungettext=ungettext)
        )

        for repo_gr in group_iter:
            children_groups = map(h.safe_unicode,
                itertools.chain((g.name for g in repo_gr.parents),
                                (x.name for x in [repo_gr])))
            repo_count = repo_gr.repositories.count()
            repo_groups_data.append({
                "raw_name": repo_gr.group_name,
                "group_name": repo_group_name(repo_gr.group_name, children_groups),
                "desc": h.escape(repo_gr.group_description),
                "repos": repo_count,
                "owner": h.person(repo_gr.owner),
                "action": repo_group_actions(repo_gr.group_id, repo_gr.group_name,
                                             repo_count)
            })

        c.data = {
            "totalRecords": total_records,
            "startIndex": 0,
            "sort": None,
            "dir": "asc",
            "records": repo_groups_data
        }

        return render('admin/repo_groups/repo_groups.html')
Пример #22
0
    def index(self, format='html'):
        _list = UserGroup.query() \
                        .order_by(func.lower(UserGroup.users_group_name)) \
                        .all()
        group_iter = UserGroupList(_list, perm_level='admin')
        user_groups_data = []
        total_records = len(group_iter)
        _tmpl_lookup = app_globals.mako_lookup
        template = _tmpl_lookup.get_template('data_table/_dt_elements.html')

        user_group_name = lambda user_group_id, user_group_name: (
            template.get_def("user_group_name")
            .render(user_group_id, user_group_name, _=_, h=h, c=c)
        )
        user_group_actions = lambda user_group_id, user_group_name: (
            template.get_def("user_group_actions")
            .render(user_group_id, user_group_name, _=_, h=h, c=c)
        )
        for user_gr in group_iter:

            user_groups_data.append({
                "raw_name": user_gr.users_group_name,
                "group_name": user_group_name(user_gr.users_group_id,
                                              user_gr.users_group_name),
                "desc": h.escape(user_gr.user_group_description),
                "members": len(user_gr.members),
                "active": h.boolicon(user_gr.users_group_active),
                "owner": h.person(user_gr.owner.username),
                "action": user_group_actions(user_gr.users_group_id, user_gr.users_group_name)
            })

        c.data = {
            "totalRecords": total_records,
            "startIndex": 0,
            "sort": None,
            "dir": "asc",
            "records": user_groups_data
        }

        return render('admin/user_groups/user_groups.html')
Пример #23
0
 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)
Пример #24
0
    def index(self, format='html'):
        _list = RepoGroup.query(sorted=True).all()
        group_iter = RepoGroupList(_list, perm_level='admin')
        repo_groups_data = []
        _tmpl_lookup = app_globals.mako_lookup
        template = _tmpl_lookup.get_template('data_table/_dt_elements.html')

        def repo_group_name(repo_group_name, children_groups):
            return template.get_def("repo_group_name") \
                .render_unicode(repo_group_name, children_groups, _=_, h=h, c=c)

        def repo_group_actions(repo_group_id, repo_group_name, gr_count):
            return template.get_def("repo_group_actions") \
                .render_unicode(repo_group_id, repo_group_name, gr_count, _=_, h=h, c=c,
                        ungettext=ungettext)

        for repo_gr in group_iter:
            children_groups = [g.name for g in repo_gr.parents] + [repo_gr.name]
            repo_count = repo_gr.repositories.count()
            repo_groups_data.append({
                "raw_name": repo_gr.group_name,
                "group_name": repo_group_name(repo_gr.group_name, children_groups),
                "desc": h.escape(repo_gr.group_description),
                "repos": repo_count,
                "owner": h.person(repo_gr.owner),
                "action": repo_group_actions(repo_gr.group_id, repo_gr.group_name,
                                             repo_count)
            })

        c.data = {
            "sort": None,
            "dir": "asc",
            "records": repo_groups_data
        }

        return render('admin/repo_groups/repo_groups.html')
Пример #25
0
 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)
Пример #26
0
 def desc(desc):
     if c.visual.stylify_metatags:
         return h.urlify_text(h.desc_stylize(h.escape(h.truncate(desc, 60))))
     else:
         return h.urlify_text(h.escape(h.truncate(desc, 60)))