def __get_desc(self, cs): desc_msg = [] desc_msg.append((_('%s committed on %s') % (h.person(cs.author), h.fmt_date(cs.date))) + '<br/>') #branches, tags, bookmarks if cs.branch: desc_msg.append('branch: %s<br/>' % cs.branch) if h.is_hg(c.rhodecode_repo): for book in cs.bookmarks: desc_msg.append('bookmark: %s<br/>' % book) for tag in cs.tags: desc_msg.append('tag: %s<br/>' % tag) diff_processor, changes = self.__changes(cs) # rev link _url = url('changeset_home', repo_name=cs.repository.name, revision=cs.raw_id, qualified=True) desc_msg.append('changeset: <a href="%s">%s</a>' % (_url, cs.raw_id[:8])) desc_msg.append('<pre>') desc_msg.append(cs.message) desc_msg.append('\n') desc_msg.extend(changes) if self.include_diff: desc_msg.append('\n\n') desc_msg.append(diff_processor.as_raw()) desc_msg.append('</pre>') return map(safe_unicode, desc_msg)
def __get_desc(self, cs): desc_msg = [(_('%s committed on %s') % (h.person(cs.author), h.fmt_date(cs.date))) + '<br/>'] #branches, tags, bookmarks if cs.branch: desc_msg.append('branch: %s<br/>' % cs.branch) if h.is_hg(c.rhodecode_repo): for book in cs.bookmarks: desc_msg.append('bookmark: %s<br/>' % book) for tag in cs.tags: desc_msg.append('tag: %s<br/>' % tag) diff_processor, changes = self.__changes(cs) # rev link _url = url('changeset_home', repo_name=cs.repository.name, revision=cs.raw_id, qualified=True) desc_msg.append('changeset: <a href="%s">%s</a>' % (_url, cs.raw_id[:8])) desc_msg.append('<pre>') desc_msg.append(cs.message) desc_msg.append('\n') desc_msg.extend(changes) if self.include_diff: desc_msg.append('\n\n') desc_msg.append(diff_processor.as_raw()) desc_msg.append('</pre>') return map(safe_unicode, desc_msg)
def make_description(self, notification, show_age=True): """ Creates a human readable description based on properties of notification object """ #alias _n = notification _map = { _n.TYPE_CHANGESET_COMMENT: _('%(user)s commented on changeset at %(when)s'), _n.TYPE_MESSAGE: _('%(user)s sent message at %(when)s'), _n.TYPE_MENTION: _('%(user)s mentioned you at %(when)s'), _n.TYPE_REGISTRATION: _('%(user)s registered in RhodeCode at %(when)s'), _n.TYPE_PULL_REQUEST: _('%(user)s opened new pull request at %(when)s'), _n.TYPE_PULL_REQUEST_COMMENT: _('%(user)s commented on pull request at %(when)s') } tmpl = _map[notification.type_] if show_age: when = h.age(notification.created_on) else: when = h.fmt_date(notification.created_on) return tmpl % dict( user=notification.created_by_user.username, when=when, )
def make_description(self, notification, show_age=True): """ Creates a human readable description based on properties of notification object """ #alias _n = notification _map = { _n.TYPE_CHANGESET_COMMENT: _('commented on commit at %(when)s'), _n.TYPE_MESSAGE: _('sent message at %(when)s'), _n.TYPE_MENTION: _('mentioned you at %(when)s'), _n.TYPE_REGISTRATION: _('registered in RhodeCode at %(when)s'), _n.TYPE_PULL_REQUEST: _('opened new pull request at %(when)s'), _n.TYPE_PULL_REQUEST_COMMENT: _('commented on pull request at %(when)s') } # action == _map string tmpl = "%(user)s %(action)s " if show_age: when = h.age(notification.created_on) else: when = h.fmt_date(notification.created_on) data = dict( user=notification.created_by_user.username, action=_map[notification.type_] ) return (tmpl % data) % {'when': when}
def add(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name, redirect_after=False) if c.cs is None: c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias) c.f_path = f_path if r_post: unix_mode = 0 content = convert_line_endings(r_post.get('content'), unix_mode) message = r_post.get('message') or (_('Added %s via RhodeCode') % (f_path)) location = r_post.get('location') filename = r_post.get('filename') file_obj = r_post.get('upload_file', None) if file_obj is not None and hasattr(file_obj, 'filename'): filename = file_obj.filename content = file_obj.file node_path = os.path.join(location, filename) author = self.rhodecode_user.full_contact if not content: h.flash(_('No content'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) if not filename: h.flash(_('No filename'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) try: self.scm_model.create_node(repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, user=self.rhodecode_user, author=author, message=message, content=content, f_path=node_path) h.flash(_('Successfully committed to %s') % node_path, category='success') except NodeAlreadyExistsError, e: h.flash(_(e), category='error') except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during commit'), category='error')
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)\ .all() users_data = [] total_records = len(c.users_list) _tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup template = _tmpl_lookup.get_template('data_table/_dt_elements.html') grav_tmpl = lambda user_email, size: (template.get_def( "user_gravatar").render(user_email, size, _=_, h=h, c=c)) user_lnk = 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(user.email, 24), "raw_username": user.username, "username": user_lnk(user.user_id, user.username), "firstname": user.name, "lastname": 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), "ldap": h.boolicon(bool(user.ldap_dn)), "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')
def edit(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name) c.file = self.__get_filenode_or_redirect(repo_name, c.cs, f_path) if c.file.is_binary: return redirect(url('files_home', repo_name=c.repo_name, revision=c.cs.raw_id, f_path=f_path)) c.f_path = f_path if r_post: old_content = c.file.content sl = old_content.splitlines(1) first_line = sl[0] if sl else '' # modes: 0 - Unix, 1 - Mac, 2 - DOS mode = detect_mode(first_line, 0) content = convert_line_endings(r_post.get('content'), mode) message = r_post.get('message') or (_('Edited %s via RhodeCode') % (f_path)) author = self.rhodecode_user.full_contact if content == old_content: h.flash(_('No changes'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) try: self.scm_model.commit_change(repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, user=self.rhodecode_user, author=author, message=message, content=content, f_path=f_path) h.flash(_('Successfully committed to %s') % f_path, category='success') except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during commit'), category='error') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) return render('files/files_edit.html')
def __get_desc(self, cs): desc_msg = [] desc_msg.append('%s %s %s:<br/>' % (cs.author, _('commited on'), h.fmt_date(cs.date))) desc_msg.append('<pre>') desc_msg.append(cs.message) desc_msg.append('\n') desc_msg.extend(self.__changes(cs)) desc_msg.append('</pre>') return desc_msg
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)\ .all() users_data = [] total_records = len(c.users_list) _tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup template = _tmpl_lookup.get_template('data_table/_dt_elements.html') grav_tmpl = lambda user_email, size: ( template.get_def("user_gravatar") .render(user_email, size, _=_, h=h, c=c)) user_lnk = 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(user. email, 24), "raw_username": user.username, "username": user_lnk(user.user_id, user.username), "firstname": user.name, "lastname": 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), "ldap": h.boolicon(bool(user.ldap_dn)), "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')
def add(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name, redirect_after=False) if c.cs is None: c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias) c.default_message = (_('Added file via RhodeCode')) c.f_path = f_path if r_post: unix_mode = 0 content = convert_line_endings(r_post.get('content'), unix_mode) message = r_post.get('message') or c.default_message filename = r_post.get('filename') location = r_post.get('location') file_obj = r_post.get('upload_file', None) if file_obj is not None and hasattr(file_obj, 'filename'): filename = file_obj.filename content = file_obj.file if not content: h.flash(_('No content'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) if not filename: h.flash(_('No filename'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) if location.startswith('/') or location.startswith('.') or '../' in location: h.flash(_('Location must be relative path and must not ' 'contain .. in path'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) if location: location = os.path.normpath(location) filename = os.path.basename(filename) node_path = os.path.join(location, filename) author = self.rhodecode_user.full_contact try: self.scm_model.create_node(repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, user=self.rhodecode_user.user_id, author=author, message=message, content=content, f_path=node_path) h.flash(_('Successfully committed to %s') % node_path, category='success') except (NodeError, NodeAlreadyExistsError), e: h.flash(_(e), category='error') except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during commit'), category='error')
def edit(self, repo_name, revision, f_path): repo = c.rhodecode_db_repo if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) # check if revision is a branch identifier- basically we cannot # create multiple heads via file editing _branches = repo.scm_instance.branches # check if revision is a branch name or branch hash if revision not in _branches.keys() + _branches.values(): h.flash(_('You can only edit files with revision ' 'being a valid branch '), category='warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip', f_path=f_path)) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name) c.file = self.__get_filenode_or_redirect(repo_name, c.cs, f_path) if c.file.is_binary: return redirect(url('files_home', repo_name=c.repo_name, revision=c.cs.raw_id, f_path=f_path)) c.default_message = _('Edited file %s via RhodeCode') % (f_path) c.f_path = f_path if r_post: old_content = c.file.content sl = old_content.splitlines(1) first_line = sl[0] if sl else '' # modes: 0 - Unix, 1 - Mac, 2 - DOS mode = detect_mode(first_line, 0) content = convert_line_endings(r_post.get('content'), mode) message = r_post.get('message') or c.default_message author = self.rhodecode_user.full_contact if content == old_content: h.flash(_('No changes'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) try: self.scm_model.commit_change(repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, user=self.rhodecode_user.user_id, author=author, message=message, content=content, f_path=f_path) h.flash(_('Successfully committed to %s') % f_path, category='success') except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during commit'), category='error') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) return render('files/files_edit.html')
def add(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash( _('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect( h.url('files_home', repo_name=repo_name, revision='tip')) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name, redirect_after=False) if c.cs is None: c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias) c.default_message = (_('Added file via RhodeCode')) c.f_path = f_path if r_post: unix_mode = 0 content = convert_line_endings(r_post.get('content', ''), unix_mode) message = r_post.get('message') or c.default_message filename = r_post.get('filename') location = r_post.get('location', '') file_obj = r_post.get('upload_file', None) if file_obj is not None and hasattr(file_obj, 'filename'): filename = file_obj.filename content = file_obj.file if hasattr(content, 'file'): # non posix systems store real file under file attr content = content.file if not content: h.flash(_('No content'), category='warning') return redirect( url('changeset_home', repo_name=c.repo_name, revision='tip')) if not filename: h.flash(_('No filename'), category='warning') return redirect( url('changeset_home', repo_name=c.repo_name, revision='tip')) #strip all crap out of file, just leave the basename filename = os.path.basename(filename) node_path = os.path.join(location, filename) author = self.rhodecode_user.full_contact try: nodes = {node_path: {'content': content}} self.scm_model.create_nodes( user=c.rhodecode_user.user_id, repo=c.rhodecode_db_repo, message=message, nodes=nodes, parent_cs=c.cs, author=author, ) h.flash(_('Successfully committed to %s') % node_path, category='success') except NonRelativePathError, e: h.flash(_('Location must be relative path and must not ' 'contain .. in path'), category='warning') return redirect( url('changeset_home', repo_name=c.repo_name, revision='tip')) except (NodeError, NodeAlreadyExistsError), e: h.flash(_(e), category='error')
def add(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name, redirect_after=False) if c.cs is None: c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias) c.default_message = (_('Added file via RhodeCode')) c.f_path = f_path if r_post: unix_mode = 0 content = convert_line_endings(r_post.get('content', ''), unix_mode) message = r_post.get('message') or c.default_message filename = r_post.get('filename') location = r_post.get('location', '') file_obj = r_post.get('upload_file', None) if file_obj is not None and hasattr(file_obj, 'filename'): filename = file_obj.filename content = file_obj.file if hasattr(content, 'file'): # non posix systems store real file under file attr content = content.file if not content: h.flash(_('No content'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) if not filename: h.flash(_('No filename'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) #strip all crap out of file, just leave the basename filename = os.path.basename(filename) node_path = os.path.join(location, filename) author = self.rhodecode_user.full_contact try: nodes = { node_path: { 'content': content } } self.scm_model.create_nodes( user=c.rhodecode_user.user_id, repo=c.rhodecode_db_repo, message=message, nodes=nodes, parent_cs=c.cs, author=author, ) h.flash(_('Successfully committed to %s') % node_path, category='success') except NonRelativePathError, e: h.flash(_('Location must be relative path and must not ' 'contain .. in path'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) except (NodeError, NodeAlreadyExistsError), e: h.flash(_(e), category='error')
def edit(self, repo_name, revision, f_path): repo = c.rhodecode_db_repo if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) # check if revision is a branch identifier- basically we cannot # create multiple heads via file editing _branches = repo.scm_instance.branches # check if revision is a branch name or branch hash if revision not in _branches.keys() + _branches.values(): h.flash(_('You can only edit files with revision ' 'being a valid branch '), category='warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip', f_path=f_path)) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name) c.file = self.__get_filenode_or_redirect(repo_name, c.cs, f_path) if c.file.is_binary: return redirect(url('files_home', repo_name=c.repo_name, revision=c.cs.raw_id, f_path=f_path)) c.default_message = _('Edited file %s via RhodeCode') % (f_path) c.f_path = f_path if r_post: old_content = c.file.content sl = old_content.splitlines(1) first_line = sl[0] if sl else '' # modes: 0 - Unix, 1 - Mac, 2 - DOS mode = detect_mode(first_line, 0) content = convert_line_endings(r_post.get('content', ''), mode) message = r_post.get('message') or c.default_message author = self.rhodecode_user.full_contact if content == old_content: h.flash(_('No changes'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) try: self.scm_model.commit_change(repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, user=self.rhodecode_user.user_id, author=author, message=message, content=content, f_path=f_path) h.flash(_('Successfully committed to %s') % f_path, category='success') except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during commit'), category='error') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) return render('files/files_edit.html')
def add(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash( _("This repository is has been locked by %s on %s") % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), "warning", ) return redirect(h.url("files_home", repo_name=repo_name, revision="tip")) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name, redirect_after=False) if c.cs is None: c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias) c.default_message = _("Added file via RhodeCode") c.f_path = f_path if r_post: unix_mode = 0 content = convert_line_endings(r_post.get("content"), unix_mode) message = r_post.get("message") or c.default_message filename = r_post.get("filename") location = r_post.get("location") file_obj = r_post.get("upload_file", None) if file_obj is not None and hasattr(file_obj, "filename"): filename = file_obj.filename content = file_obj.file if not content: h.flash(_("No content"), category="warning") return redirect(url("changeset_home", repo_name=c.repo_name, revision="tip")) if not filename: h.flash(_("No filename"), category="warning") return redirect(url("changeset_home", repo_name=c.repo_name, revision="tip")) if location.startswith("/") or location.startswith(".") or "../" in location: h.flash(_("Location must be relative path and must not " "contain .. in path"), category="warning") return redirect(url("changeset_home", repo_name=c.repo_name, revision="tip")) if location: location = os.path.normpath(location) filename = os.path.basename(filename) node_path = os.path.join(location, filename) author = self.rhodecode_user.full_contact try: self.scm_model.create_node( repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, user=self.rhodecode_user.user_id, author=author, message=message, content=content, f_path=node_path, ) h.flash(_("Successfully committed to %s") % node_path, category="success") except (NodeError, NodeAlreadyExistsError), e: h.flash(_(e), category="error") except Exception: log.error(traceback.format_exc()) h.flash(_("Error occurred during commit"), category="error")