def get_repo_groups_as_dict(self, repo_group_list=None, admin=False, super_user_actions=False): from rhodecode.lib.utils import PartialRenderer _render = PartialRenderer('data_table/_dt_elements.html') c = _render.c h = _render.h def quick_menu(repo_group_name): return _render('quick_repo_group_menu', repo_group_name) def repo_group_lnk(repo_group_name): return _render('repo_group_name', repo_group_name) def desc(desc): if c.visual.stylify_metatags: return h.urlify_text(h.escaped_stylize(h.truncate(desc, 60))) else: return h.urlify_text(h.html_escape(h.truncate(desc, 60))) def repo_group_actions(repo_group_id, repo_group_name, gr_count): return _render( 'repo_group_actions', repo_group_id, repo_group_name, gr_count) def repo_group_name(repo_group_name, children_groups): return _render("repo_group_name", repo_group_name, children_groups) def user_profile(username): return _render('user_profile', username) repo_group_data = [] for group in repo_group_list: row = { "menu": quick_menu(group.group_name), "name": repo_group_lnk(group.group_name), "name_raw": group.group_name, "desc": desc(group.group_description), "top_level_repos": 0, "owner": user_profile(group.user.username) } if admin: repo_count = group.repositories.count() children_groups = map( h.safe_unicode, itertools.chain((g.name for g in group.parents), (x.name for x in [group]))) row.update({ "action": repo_group_actions( group.group_id, group.group_name, repo_count), "top_level_repos": repo_count, "name": repo_group_name(group.group_name, children_groups), }) repo_group_data.append(row) return repo_group_data
def _get_description(self, commit): _renderer = PartialRenderer('feed/atom_feed_entry.mako') parsed_diff, limited_diff = self.__changes(commit) return _renderer( 'body', commit=commit, parsed_diff=parsed_diff, limited_diff=limited_diff, feed_include_diff=self.feed_include_diff, )
def index(self): _render = PartialRenderer(self.partials_template) _data = [] pre_load = ["author", "date", "message"] repo = c.rhodecode_repo is_svn = h.is_svn(repo) format_ref_id = utils.get_format_ref_id(repo) for ref_name, commit_id in self._get_reference_items(repo): commit = repo.get_commit(commit_id=commit_id, pre_load=pre_load) # TODO: johbo: Unify generation of reference links use_commit_id = '/' in ref_name or is_svn files_url = h.url( 'files_home', repo_name=c.repo_name, f_path=ref_name if is_svn else '', revision=commit_id if use_commit_id else ref_name, at=ref_name) _data.append({ "name": _render('name', ref_name, files_url), "name_raw": ref_name, "date": _render('date', commit.date), "date_raw": datetime_to_time(commit.date), "author": _render('author', commit.author), "commit": _render('commit', commit.message, commit.raw_id, commit.idx), "commit_raw": commit.idx, "compare": _render('compare', format_ref_id(ref_name, commit.raw_id)), }) c.has_references = bool(_data) c.data = json.dumps(_data) return render(self.template)
def index(self): """GET /users_groups: All items in the collection""" # url('users_groups') from rhodecode.lib.utils import PartialRenderer _render = PartialRenderer('data_table/_dt_elements.html') def user_group_name(user_group_id, user_group_name): return _render("user_group_name", user_group_id, user_group_name) def user_group_actions(user_group_id, user_group_name): return _render("user_group_actions", user_group_id, user_group_name) ## json generate group_iter = UserGroupList(UserGroup.query().all(), perm_set=['usergroup.admin']) user_groups_data = [] for user_gr in group_iter: user_groups_data.append({ "group_name": user_group_name(user_gr.users_group_id, h.escape(user_gr.users_group_name)), "group_name_raw": user_gr.users_group_name, "desc": h.escape(user_gr.user_group_description), "members": len(user_gr.members), "active": h.bool2icon(user_gr.users_group_active), "owner": h.escape(h.link_to_user(user_gr.user.username)), "action": user_group_actions(user_gr.users_group_id, user_gr.users_group_name) }) c.data = json.dumps(user_groups_data) return render('admin/user_groups/user_groups.html')
def get_repos_as_dict(self, repo_list=None, admin=False, super_user_actions=False): from rhodecode.lib.utils import PartialRenderer _render = PartialRenderer('data_table/_dt_elements.html') c = _render.c def quick_menu(repo_name): return _render('quick_menu', repo_name) def repo_lnk(name, rtype, rstate, private, fork_of): return _render('repo_name', name, rtype, rstate, private, fork_of, short_name=not admin, admin=False) def last_change(last_change): return _render("last_change", last_change) def rss_lnk(repo_name): return _render("rss", repo_name) def atom_lnk(repo_name): return _render("atom", repo_name) def last_rev(repo_name, cs_cache): return _render('revision', repo_name, cs_cache.get('revision'), cs_cache.get('raw_id'), cs_cache.get('author'), cs_cache.get('message')) def desc(desc): if c.visual.stylify_metatags: return h.urlify_text(h.escaped_stylize(h.truncate(desc, 60))) else: return h.urlify_text(h.html_escape(h.truncate(desc, 60))) def state(repo_state): return _render("repo_state", repo_state) def repo_actions(repo_name): return _render('repo_actions', repo_name, super_user_actions) def user_profile(username): return _render('user_profile', username) repos_data = [] for repo in repo_list: cs_cache = repo.changeset_cache row = { "menu": quick_menu(repo.repo_name), "name": repo_lnk(repo.repo_name, repo.repo_type, repo.repo_state, repo.private, repo.fork), "name_raw": repo.repo_name.lower(), "last_change": last_change(repo.last_db_change), "last_change_raw": datetime_to_time(repo.last_db_change), "last_changeset": last_rev(repo.repo_name, cs_cache), "last_changeset_raw": cs_cache.get('revision'), "desc": desc(repo.description), "owner": user_profile(repo.user.username), "state": state(repo.repo_state), "rss": rss_lnk(repo.repo_name), "atom": atom_lnk(repo.repo_name), } if admin: row.update({ "action": repo_actions(repo.repo_name), }) repos_data.append(row) return repos_data
def get_renderer(self, type_): template_name = self.email_types[type_] return PartialRenderer(template_name)
def index(self): """GET /users: All items in the collection""" # url('users') from rhodecode.lib.utils import PartialRenderer _render = PartialRenderer('data_table/_dt_elements.html') def grav_tmpl(user_email, size): return _render("user_gravatar", user_email, size) def username(user_id, username): return _render("user_name", user_id, username) def user_actions(user_id, username): return _render("user_actions", user_id, username) # json generate c.users_list = User.query()\ .filter(User.username != User.DEFAULT_USER) \ .all() users_data = [] for user in c.users_list: users_data.append({ "gravatar": grav_tmpl(user.email, 20), "username": h.link_to(user.username, h.url('user_profile', username=user.username)), "username_raw": user.username, "email": user.email, "first_name": h.escape(user.name), "last_name": h.escape(user.lastname), "last_login": h.format_date(user.last_login), "last_login_raw": datetime_to_time(user.last_login), "last_activity": h.format_date( h.time_to_datetime(user.user_data.get('last_activity', 0))), "last_activity_raw": user.user_data.get('last_activity', 0), "active": h.bool2icon(user.active), "active_raw": user.active, "admin": h.bool2icon(user.admin), "admin_raw": user.admin, "extern_type": user.extern_type, "extern_name": user.extern_name, "action": user_actions(user.user_id, user.username), }) c.data = json.dumps(users_data) return render('admin/users/users.html')
def index(self): """GET /admin/gists: All items in the collection""" # url('gists') not_default_user = c.rhodecode_user.username != User.DEFAULT_USER c.show_private = request.GET.get('private') and not_default_user c.show_public = request.GET.get('public') and not_default_user c.show_all = request.GET.get('all') and c.rhodecode_user.admin gists = _gists = Gist().query()\ .filter(or_(Gist.gist_expires == -1, Gist.gist_expires >= time.time()))\ .order_by(Gist.created_on.desc()) c.active = 'public' # MY private if c.show_private and not c.show_public: gists = _gists.filter(Gist.gist_type == Gist.GIST_PRIVATE)\ .filter(Gist.gist_owner == c.rhodecode_user.user_id) c.active = 'my_private' # MY public elif c.show_public and not c.show_private: gists = _gists.filter(Gist.gist_type == Gist.GIST_PUBLIC)\ .filter(Gist.gist_owner == c.rhodecode_user.user_id) c.active = 'my_public' # MY public+private elif c.show_private and c.show_public: gists = _gists.filter(or_(Gist.gist_type == Gist.GIST_PUBLIC, Gist.gist_type == Gist.GIST_PRIVATE))\ .filter(Gist.gist_owner == c.rhodecode_user.user_id) c.active = 'my_all' # Show all by super-admin elif c.show_all: c.active = 'all' gists = _gists # default show ALL public gists if not c.show_public and not c.show_private and not c.show_all: gists = _gists.filter(Gist.gist_type == Gist.GIST_PUBLIC) c.active = 'public' from rhodecode.lib.utils import PartialRenderer _render = PartialRenderer('data_table/_dt_elements.html') data = [] for gist in gists: data.append({ 'created_on': _render('gist_created', gist.created_on), 'created_on_raw': gist.created_on, 'type': _render('gist_type', gist.gist_type), 'access_id': _render('gist_access_id', gist.gist_access_id, gist.owner.full_contact), 'author': _render('gist_author', gist.owner.full_contact, gist.created_on, gist.gist_expires), 'author_raw': h.escape(gist.owner.full_contact), 'expires': _render('gist_expires', gist.gist_expires), 'description': _render('gist_description', gist.gist_description) }) c.data = json.dumps(data) return render('admin/gists/index.html')
def _get_pull_requests_list(self, repo_name, opened_by, statuses): # pagination start = safe_int(request.GET.get('start'), 0) length = safe_int(request.GET.get('length'), c.visual.dashboard_items) order_by, order_dir = self._extract_ordering(request) if c.awaiting_review: pull_requests = PullRequestModel().get_awaiting_review( repo_name, source=c.source, opened_by=opened_by, statuses=statuses, offset=start, length=length, order_by=order_by, order_dir=order_dir) pull_requests_total_count = PullRequestModel( ).count_awaiting_review(repo_name, source=c.source, statuses=statuses, opened_by=opened_by) elif c.awaiting_my_review: pull_requests = PullRequestModel().get_awaiting_my_review( repo_name, source=c.source, opened_by=opened_by, user_id=c.rhodecode_user.user_id, statuses=statuses, offset=start, length=length, order_by=order_by, order_dir=order_dir) pull_requests_total_count = PullRequestModel( ).count_awaiting_my_review(repo_name, source=c.source, user_id=c.rhodecode_user.user_id, statuses=statuses, opened_by=opened_by) else: pull_requests = PullRequestModel().get_all(repo_name, source=c.source, opened_by=opened_by, statuses=statuses, offset=start, length=length, order_by=order_by, order_dir=order_dir) pull_requests_total_count = PullRequestModel().count_all( repo_name, source=c.source, statuses=statuses, opened_by=opened_by) from rhodecode.lib.utils import PartialRenderer _render = PartialRenderer('data_table/_dt_elements.html') data = [] for pr in pull_requests: comments = ChangesetCommentsModel().get_all_comments( c.rhodecode_db_repo.repo_id, pull_request=pr) data.append({ 'name': _render('pullrequest_name', pr.pull_request_id, pr.target_repo.repo_name), 'name_raw': pr.pull_request_id, 'status': _render('pullrequest_status', pr.calculated_review_status()), 'title': _render('pullrequest_title', pr.title, pr.description), 'description': h.escape(pr.description), 'updated_on': _render('pullrequest_updated_on', h.datetime_to_time(pr.updated_on)), 'updated_on_raw': h.datetime_to_time(pr.updated_on), 'created_on': _render('pullrequest_updated_on', h.datetime_to_time(pr.created_on)), 'created_on_raw': h.datetime_to_time(pr.created_on), 'author': _render( 'pullrequest_author', pr.author.full_contact, ), 'author_raw': pr.author.full_name, 'comments': _render('pullrequest_comments', len(comments)), 'comments_raw': len(comments), 'closed': pr.is_closed(), }) # json used to render the grid data = ({ 'data': data, 'recordsTotal': pull_requests_total_count, 'recordsFiltered': pull_requests_total_count, }) return data