def project_info(request, name, pagenum=1, key=None): if request.method == 'POST': pagenum = request.POST.get('jump', None) pagenum = int(pagenum) project = q_get(Project, name=name) resp = can_access(project, request.user) if resp != None: return resp rc = request.rc rc.pagename = 'Info' rc.project = project rc.logs = get_prj_activitys(project) rc.members = q_gets(ProjectMember, project=project, member_type=consts.PM_ACCEPT_INV) update_my_project_status(request, [project]) rc.navmenusSource = build_prj_nav_menu(request, project, 'info') rc.REPOS = svn.REPOS(project.part, name, '/trunk') q = Q(project=project) build_page( rc, Activity, q, pagenum, '/p/{0}/{1}'.format(name, 'info'), order=['-ctime'], ) cc = [] for i in rc.page.object_list: if i.act_type == 'new_commit': cc = i.content.split(' ') rev = cc[0] tmp = cc[1:len(cc)] msg = ' '.join(tmp) i.commit = {'rev': int(rev), 'msg': msg} return send_response(request, 'project/view.html')
def browse(request, name, path='/'): resp, r, rc = check_acl(request, name, path) if resp is not None: return resp if path[-1] != '/': return view_file(request, name, path, r) if path == '/': update_last_log(request, r, rc.project) o = svn.LIST(r) files = [] entrys = getattr(o.list, 'entry',[]) if type(entrys) != list: entrys = [entrys] for e in entrys: co = e.commit f = { 'dir':e['kind'] == 'dir' and True or False, 'name':unicode(e.name), 'rev':co['revision'], 'date':parse_datetime(str(co.date)), 'author':get_author(getattr(e, 'author', '')), 'size':int(str(getattr(e, 'size', '0'))) } files.append(f) rc.files = files rc.REPOS = svn.REPOS(name, '/trunk') if path == '/': for v in ['/trunk/README', '/README']: try: c = svn.CAT(svn.ADMIN_REPOS(name, v)) if len(c) > 0: rc.README = c break except: continue return send_response(request, 'repos/browse.html')
def project_info(request, name): project = q_get(Project, name=name) resp = can_access(project, request.user) if resp != None: return resp rc = request.rc rc.pagename = 'Info' rc.project = project rc.logs = get_prj_activitys(project) rc.members = q_gets(ProjectMember, project=project, member_type=consts.PM_ACCEPT_INV) update_my_project_status(request, [project]) rc.navmenus = build_prj_nav_menu(request, project, 'info') rc.REPOS = svn.REPOS(name, '/trunk') return send_response(request, 'project/view.html')
def view_file(request, name, path, r): rc = request.rc ul = svn.REPOS(name, '/' + path) if request.GET.get('orig', None) is not None: return redirect(ul) info = svn.INFO(r) rc.mtime = parse_datetime(str(info.entry.commit.date)) rc.author = get_author(getattr(info.entry.commit, 'author', '')) rc.rev = info.entry.commit['revision'] ft = guess_type(path)[0] fname = os.path.split(path)[1] if ft is None: if fname.upper() in ('README','AUTHORS','COPYING','INSTALL', 'CHANGELOG', 'NEWS', 'CONTRIBUTORS'): rc.content = svn.CAT(r) else: rc.srcurl = ul elif ft.startswith('text'): filecon = svn.CAT(r) rc.content = force_unicode(filecon) hf = HtmlFormatter(encoding='utf8') rc.content_style = hf.get_style_defs('.highlight') rc.content = highlight(safe_esc(force_unicode(rc.content)), get_lexer_for_filename(fname), hf) elif ft.startswith('image'): rc.imgurl = ul else: rc.srcurl = ul return send_response(request, 'repos/view_file.html')
def check_acl(request, name, path): project = q_get(Project, name=name) resp = can_access(project, request.user) if resp != None: return resp, None, request.rc path = svn.safe_path(path) rc = request.rc rc.navmenusSource = build_prj_nav_menu(request, project, 'src') rc.project = project rc.pagename = path rc.pagedesc = project.title rc.path = path rc.paths = build_paths(path) if path != '/' and path[-1] == '/': rc.parent = os.path.split(path[:-1])[0] if rc.parent != '/': rc.parent += '/' r = svn.REPOS(project.part, name, path) return resp, r, rc
def browse(request, name, path='/'): resp, r, rc = check_acl(request, name, path) if resp is not None: return resp o = svn.LIST(r) entrys = getattr(o.list, 'entry', []) if path[-1] != '/': if type(entrys) == list or entrys['kind'] == 'dir': return redirect( reverse('apps.repos.views.browse', args=[name, path + '/'])) return view_file(request, name, path, r, o) if path == '/': update_last_log(request, r, rc.project) files = [] if type(entrys) != list: entrys = [entrys] for e in entrys: co = e.commit f = { 'dir': e['kind'] == 'dir' and True or False, 'name': unicode(e.name), 'rev': co['revision'], 'date': parse_datetime(str(co.date)), 'author': get_author(getattr(e, 'author', '')), 'size': int(str(getattr(e, 'size', '0'))) } files.append(f) rc.files = files rc.REPOS = get_repos_base(request, name) if path == '/': for v in ['/trunk/README', '/README']: try: c = svn.CAT(svn.REPOS(rc.project.part, name, v)) if len(c) > 0: rc.README = force_unicode2(c) rc.README_FILE = v break except: continue prj_q = Q(project__status=consts.PROJECT_ENABLE) current_user = q_get(User, name=request.user, status=consts.USER_ENABLE) owner_q = Q(owner=current_user, status=consts.PROJECT_ENABLE) owner_projects = Project.objects.filter(owner_q) joined_projects = q_gets(ProjectMember, user=current_user).filter(prj_q).exclude( member_type=consts.PM_REJECT_INV) power = 'read' if current_user == rc.project.owner: power = 'all' for j in joined_projects: if current_user == j.user and rc.project == j.project: power = 'all' rc.power = power project = q_get(Project, name=rc.project) rc.project = project ''' owner=q_get(User,name=project.owner) members = q_gets(ProjectMember, project = project, member_type = consts.PM_ACCEPT_INV) if owner==current_user: rc.good = 'admin' if current_user in members: rc.good = 'join' ''' update_my_project_status(request, [project]) rs = ProjectWatcher.objects.filter(project=project).aggregate( watchers=Count('id')) rc.rs = rs['watchers'] project.click = project.click + 1 project.save() return send_response(request, 'repos/browse.html')