Example #1
0
def add_repo(request):

    def gitignores():
        path  = "%s/gitignores/"%settings.TEMPLATE_DIRS[0]

        files = []
        for ps, ds, fs in os.walk(path):
            for f in fs:
                n, x = os.path.splitext(f)
                if x==".gitignore":
                    p = {
                        "name" : f.replace(".gitignore",""),
                        "path" : os.path.join(ps, f).replace(path,""),
                        "value": f.replace(".gitignore","").lower()
                    }
                    files.append(p)

        return files


    sshkeys_len = SSHKey.objects.filter(user = request.user).count()
    if sshkeys_len < 1:
        return render_to_response("error.html", context_instance  = RequestContext(request,{
                "error" : '在创建项目前,请先添加你的 SSH key,<a href="/accounts/settings/sshkey">点击这里</a> 添加。'
        }))

    if request.method == "POST":

        form = RepoForm(request.POST)
        if form.is_valid():
            repo = form.save(commit=False)
            repo.touchreadme = request.POST.get("touchreadme", False)
            repo.gitignore   = request.POST.get("gitignores", None)
            repo.create_repo()
            return HttpResponseRedirect("/%s/%s"%(repo.owner.username, repo.name))

        else:
            form_message(request, form)

    else:
        form = RepoForm()

    owner_teams = []
    profile = request.user.get_profile()
    teams = profile.teams

    for team in teams.all():
        team_profile = team.get_profile()
        for team_owner in team_profile.owners.all():
            if request.user.username == team_owner.username:
                owner_teams.append(team)

    context = {
                "page" : "repo",
                "form"  : form,
                "owner_teams" : owner_teams,
                "gitignores" : gitignores()
    }

    return render('repo/add.html', request, context=context)
Example #2
0
def add_repo(request):
    def gitignores():
        path = "%s/gitignores/" % settings.TEMPLATE_DIRS[0]

        files = []
        for ps, ds, fs in os.walk(path):
            for f in fs:
                n, x = os.path.splitext(f)
                if x == ".gitignore":
                    p = {
                        "name": f.replace(".gitignore", ""),
                        "path": os.path.join(ps, f).replace(path, ""),
                        "value": f.replace(".gitignore", "").lower()
                    }
                    files.append(p)

        return files

    sshkeys_len = SSHKey.objects.filter(user=request.user).count()
    if sshkeys_len < 1:
        return render_to_response(
            "error.html",
            context_instance=RequestContext(
                request, {
                    "error":
                    '在创建项目前,请先添加你的 SSH key,<a href="/accounts/settings/sshkey">点击这里</a> 添加。'
                }))

    if request.method == "POST":

        form = RepoForm(request.POST)
        if form.is_valid():
            repo = form.save(commit=False)
            repo.touchreadme = request.POST.get("touchreadme", False)
            repo.gitignore = request.POST.get("gitignores", None)
            repo.create_repo()
            return HttpResponseRedirect("/%s/%s" %
                                        (repo.owner.username, repo.name))

        else:
            form_message(request, form)

    else:
        form = RepoForm()

    owner_teams = []
    profile = request.user.get_profile()
    teams = profile.teams

    for team in teams.all():
        team_profile = team.get_profile()
        for team_owner in team_profile.owners.all():
            if request.user.username == team_owner.username:
                owner_teams.append(team)

    context = {
        "page": "repo",
        "form": form,
        "owner_teams": owner_teams,
        "gitignores": gitignores()
    }

    return render('repo/add.html', request, context=context)