Exemplo n.º 1
0
def member(request):
#def member(request, *args, **kwargs):
    #print args

    print ('进入成员界面')
    pro_id  = request.session['now_project_id']

    input_member = request.POST.get('i_name', "ffff")
    #pro_id = 1
    print('pro_id', pro_id)
    print ('input_member', input_member)
    if len(input_member) == 0:
        pass
    else:
        ff = models.User.objects.filter(user_name=input_member)
        if len(ff) != 0:
            name = models.User.objects.get(user_name=input_member)
            pp = models.project_user.objects.filter(user_name=input_member,project_id=pro_id)
            if len(pp) == 0:
                models.project_user.objects.create(project_id=pro_id, user_name=name)
                print ('ok')

                msg = '在项目'+ request.session['now_project_name'] + u'中添加了成员 '+ str(name)
                user_commit.record(request.session['user_name'], msg)

            else:
                print ('已存在')

    all_members = models.project_user.objects.filter(project_id=pro_id)
    print (len(all_members),"#########")
    return render(request, 'member.html', {"members": all_members})
Exemplo n.º 2
0
def upload(request):
    print '上传'
    if request.method == 'POST':
        obj = request.FILES.get('fafafa')
        f = open(
            os.path.join('hub', 'repo', request.session['now_project_owner'],
                         request.session['now_project_name'], obj.name), 'wb')
        print f
        print '@@@@@@@@@@@@@@@@'
        for line in obj.chunks():
            f.write(line)
        f.close()
        print '33333333'
        msg = '上传了' + obj.name
        GitFileController.change_commit(
            request.session['now_project_repo_path'], obj.name,
            '上传了' + obj.name, request.session['user_name'],
            request.session['user_email'])
        description = '在项目' + request.session[
            'now_project_name'] + '中的' + request.session[
                'head_branch'] + '分支进行了注释为 "' + msg + '" 的提交'

        user_commit.record(request.session['user_name'], description)
        print '********'
    return render_to_response('upload.html')
Exemplo n.º 3
0
def project_create(request):
    print '创建项目'
    if request.method == 'POST':  #dir_name是绝对路径例如/home/bob/apps/CodeHub/XYJ
        #user = request.session['user']#还要把user写入session
        #user_path = request.user.user_path
        project_name = request.POST.get('project_name')
        description = request.POST.get('description')
        dir_name = codehub_path + request.session[
            'user_name'] + '/' + project_name
        repo_path = request.session['user_name'] + '/' + project_name + '/'
        description = '暂时固定'
        GitFileController.create_working_dir(dir_name,
                                             request.session['user_name'],
                                             request.session['user_email'])
        tem = models.Project.objects.create(
            project_name=project_name,
            description=description,
            repo_path=repo_path,
            lead_user=get_object_or_404(User, pk=request.session['user_name']))
        models.project_user.objects.create(
            project_id=tem.project_id,
            user_name=get_object_or_404(User, pk=request.session['user_name']))
        request.session['now_project_owner'], request.session[
            'now_project_name'] = request.session['user_name'], project_name

        msg = '创建了项目 ' + project_name
        user_commit.record(request.session['user_name'], msg)
        return HttpResponseRedirect(reverse('hub:code'))
    #else:
    return render(request, 'projectCreate.html')
Exemplo n.º 4
0
def delProject(request):
    print "删除项目"

    pro_id = request.session['now_project_id']
    models.project_user.objects.filter(project_id=pro_id).delete()
    models.Project.objects.filter(project_id=pro_id).delete()

    shutil.rmtree(request.session['now_project_repo_path'])
    msg = '删除了项目 ' + request.session['now_project_name']
    user_commit.record(request.session['user_name'], msg)
    return HttpResponseRedirect(reverse('hub:profile'))
Exemplo n.º 5
0
def delMem(request):
    print "删除成员"
    name = request.GET.get('member_name')
    print name
    pro_id = request.session['now_project_id']
    models.project_user.objects.filter(project_id=pro_id,user_name=name).delete()

    msg = '在项目'+request.session['now_project_name']+'中删除了成员 '+ name
    user_commit.record(request.session['user_name'], msg)

    all_members = models.project_user.objects.filter(project_id=pro_id)
    return render(request, 'member.html', {"members": all_members})
    pass
Exemplo n.º 6
0
def process_edit(request, *args, **kwargs):
    #print args
    #file_name = (kwargs['file_name'])
    print '处理代码修改'
    data = request.POST.get('data')
    commit_message = request.POST.get('commit_message')
    file_name = request.session['now_file_name']
    with open(request.session['now_project_repo_path']+file_name,'w') as f:
        f.write(data)
    GitFileController.mygit.change_commit(request.session['now_project_repo_path'],file_name,commit_message,request.session['user_name'],request.session['user_email'])

    description = '在项目'+request.session['now_project_name']+'中的'+request.session['head_branch']+'分支进行了注释为 "'+commit_message+'" 的提交'
    
    user_commit.record(request.session['user_name'], description)

    return HttpResponseRedirect(reverse('hub:code_file'))
Exemplo n.º 7
0
def branch(request):
    print '进入分支界面'

    if request.method == "POST":
        if request.POST.get('new_branch') != None:  #新建分支
            name = request.POST.get('new_branch')
            GitFileController.new_branch(
                request.session['now_project_repo_path'], name)
            status = 0

            msg = '在项目' + request.session['now_project_name'] + '中新建了分支 ' + name
            user_commit.record(request.session['user_name'], msg)

            result = "Create new branch success!"
            print(result)
        elif request.POST.get('branch_name') != None:  #删除分支
            print request.POST.get('branch_name')
            name = request.POST.get('branch_name')
            GitFileController.delete_branch(
                request.session['now_project_repo_path'], name)

            msg = '在项目' + request.session['now_project_name'] + '中删除了分支 ' + name
            user_commit.record(request.session['user_name'], msg)

            result = "Delete new branch sdsffsdf!"
            print(result)
        elif request.POST.get('frombranch') != None:  #合并分支
            msg = request.POST.get('message')
            frombranch = request.POST.get('frombranch')
            print msg
            frombranch_exist = GitFileController.merge(
                request.session['now_project_repo_path'], frombranch, msg)
        elif request.POST.get('tobranch') != None:  #切换分支
            tobranch = request.POST.get('tobranch')
            print tobranch
            GitFileController.switch_branch(
                request.session['now_project_repo_path'], tobranch)
            request.session['head_branch'] = tobranch
    elif request.GET.get('branch_name') != None:  #删除分支
        print request.GET.get('branch_name')
        name = request.GET.get('branch_name')
        GitFileController.delete_branch(
            request.session['now_project_repo_path'], name)

        msg = '在项目' + request.session['now_project_name'] + '中删除了分支 ' + name
        user_commit.record(request.session['user_name'], msg)

        result = "Delete new branch success!"
        print(result)
    print 'done'
    data = GitFileController.show_branches_refs(
        request.session['now_project_repo_path'])
    print data
    return render(request, 'branch.html', {'data': data})