Exemple #1
0
    def test_fork_and_watch_project(self):
        p6 = CodeDoubanProject.add('project6', owner_id="admin_user",
                                   summary="test", product="fire")
        p7 = CodeDoubanProject.add('project7', owner_id="other_user",
                                   summary="test", product="fire")

        fork_count = CodeDoubanProject.get_forked_count(p6.id)
        p6fork = p6.fork('project6_other_user', 'other_user')
        fork_count2 = CodeDoubanProject.get_forked_count(p6.id)
        ok_(fork_count2 == fork_count + 1)
        ok_(CodeDoubanProject.get_forked_count(p6fork.id) == 0)

        p6fork2 = p6fork.fork('project6_fork_other_user', 'other_user')
        ok_(CodeDoubanProject.get_forked_count(p6.id) == fork_count + 2)
        ok_(CodeDoubanProject.get_forked_count(p6fork.id) == 1)
        ok_(CodeDoubanProject.get_forked_count(p6fork2.id) == 0)

        watch_count = CodeDoubanProject.get_watched_count(p7.id)
        CodeDoubanProject.add_watch(p7.id, 'admin_user')
        watch_count2 = CodeDoubanProject.get_watched_count(p7.id)
        ok_(watch_count2 == watch_count + 1)

        ok_(len(p7.get_watch_users()) == watch_count2)

        p6.delete()
        p7.delete()
Exemple #2
0
    def test_fork_and_watch_project(self):
        p6 = CodeDoubanProject.add('project6',
                                   owner_id="admin_user",
                                   summary="test",
                                   product="fire")
        p7 = CodeDoubanProject.add('project7',
                                   owner_id="other_user",
                                   summary="test",
                                   product="fire")

        fork_count = CodeDoubanProject.get_forked_count(p6.id)
        p6fork = p6.fork('project6_other_user', 'other_user')
        fork_count2 = CodeDoubanProject.get_forked_count(p6.id)
        ok_(fork_count2 == fork_count + 1)
        ok_(CodeDoubanProject.get_forked_count(p6fork.id) == 0)

        p6fork2 = p6fork.fork('project6_fork_other_user', 'other_user')
        ok_(CodeDoubanProject.get_forked_count(p6.id) == fork_count + 2)
        ok_(CodeDoubanProject.get_forked_count(p6fork.id) == 1)
        ok_(CodeDoubanProject.get_forked_count(p6fork2.id) == 0)

        watch_count = CodeDoubanProject.get_watched_count(p7.id)
        CodeDoubanProject.add_watch(p7.id, 'admin_user')
        watch_count2 = CodeDoubanProject.get_watched_count(p7.id)
        ok_(watch_count2 == watch_count + 1)

        ok_(len(p7.get_watch_users()) == watch_count2)

        p6.delete()
        p7.delete()
Exemple #3
0
def watch(request):
    user = request.user
    if not user:
        return request.redirect("/")
    errors = ""
    if request.method == "POST":
        proj_id = request.get_form_var('proj_id')
        CodeDoubanProject.add_watch(proj_id, user.name)
        project = CodeDoubanProject.get(proj_id)
        return request.redirect('/%s/' % project.name)

    proj_id = request.get_form_var('proj_id') or ""
    project = CodeDoubanProject.get(proj_id)
    action = "watch"
    return st('watch.html', **locals())
Exemple #4
0
def watch(request):
    user = request.user
    if not user:
        return request.redirect("/")
    errors = ""
    if request.method == "POST":
        proj_id = request.get_form_var('proj_id')
        CodeDoubanProject.add_watch(proj_id, user.name)
        project = CodeDoubanProject.get(proj_id)
        return request.redirect('/%s/' % project.name)

    proj_id = request.get_form_var('proj_id') or ""
    project = CodeDoubanProject.get(proj_id)
    action = "watch"
    return st('watch.html', **locals())
Exemple #5
0
def create(request):
    user = request.user
    if not user:
        return request.redirect("/")
    errors = ""

    template_filename = 'create.html'

    if request.method == "POST":
        name = request.get_form_var('name')
        product = request.get_form_var('product')
        org_proj = request.get_form_var('org_proj')
        summary = request.get_form_var('summary')
        repo_url = request.get_form_var('url')
        fork_from = request.get_form_var('fork_from')
        intern_banned = request.get_form_var('intern_banned', None)
        with_proxy = request.get_form_var('with_proxy', MIRROR_NOT_PROXY)
        with_proxy = int(with_proxy)
        mirror = None

        def add_people_project(project):
            name = "%s/%s" % (project.owner_id, project.name)
            _project = CodeDoubanProject.add(
                name=name, owner_id=project.owner_id,
                summary=project.summary, product=project.product,
                intern_banned=project.intern_banned)
            return _project

        def add_org_project(project):
            _project = CodeDoubanProject.add(
                name=name, owner_id=project.owner_id,
                summary=project.summary, product=project.product,
                intern_banned=project.intern_banned)
            return _project

        def add_mirror_project(project):
            name = "mirror/%s" % (project.name)
            _project = CodeDoubanProject.add(
                name=name, owner_id='mirror', summary=project.summary,
                product=project.product, intern_banned=project.intern_banned,
                mirror=project.mirror_url)
            if _project:
                CodeDoubanMirror.add(url=project.mirror_url,
                                     state=MIRROR_STATE_CLONING,
                                     project_id=_project.id,
                                     with_proxy=project.mirror_proxy)
            return _project

        def add_fork_project(project):
            name = "%s/%s" % (project.owner_id, project.name)
            _project = CodeDoubanProject.add(
                name=name, owner_id=project.owner_id, summary=project.summary,
                product=project.product, fork_from=project.fork_from,
                intern_banned=project.intern_banned)
            if _project:
                fork_from_project = CodeDoubanProject.get(project.fork_from)
                _project.update(project.summary,
                                project.product,
                                name,
                                fork_from_project.intern_banned)
            return _project

        def validate_project(project_type, project):
            error = ''
            if project_type in (PEOPLE_PROJECT, ORGANIZATION_PROJECT):
                error = project.validate()
            elif project_type == MIRROR_PROJECT:
                error = project.validate()
                if not error:
                    error = CodeDoubanMirror.validate(project.mirror_url)
            else:
                error = project.validate()
            return error

        def add_project(project):
            _project = None
            if project_type == PEOPLE_PROJECT:
                _project = add_people_project(project)
            elif project_type == ORGANIZATION_PROJECT:
                _project = add_org_project(project)
            elif project_type == MIRROR_PROJECT:
                _project = add_mirror_project(project)
            else:
                _project = add_fork_project(project)
            return _project

        project = CodeDoubanProject(None, name, user.username, summary,
                                    datetime.now(), product, None, None,
                                    fork_from=fork_from,
                                    intern_banned=intern_banned,
                                    mirror_url=repo_url,
                                    mirror_proxy=with_proxy)
        # FIXME: rename org_proj of html
        project_type = org_proj
        errors = validate_project(project_type, project)
        if errors:
            return st(template_filename, **locals())

        project = add_project(project)
        if not project:
            fork_from = ''
            errors = 'project exists'
            return st(template_filename, **locals())

        CodeDoubanProject.add_watch(project.id, user.name)
        return request.redirect('/%s/' % project.name)

    fork_from = ''
    if request.get_form_var('fork_from'):
        fork_from = CodeDoubanProject.get(request.get_form_var('fork_from'))
        name = "%s/%s" % (user.name, fork_from.realname)
        if CodeDoubanProject.exists(name):
            return request.redirect('/%s/' % name)
        projects = CodeDoubanProject.gets_by_owner_id(user.name)
        for p in projects:
            if p.origin_project_id == fork_from.id and '/' in p.name:
                return request.redirect('/%s/' % p.name)
    return st(template_filename, **locals())
Exemple #6
0
def new(request, proj_id):
    user = request.user
    CodeDoubanProject.add_watch(proj_id, user.name)
    return json.dumps({"ok": 1})
Exemple #7
0
def create(request):
    user = request.user
    if not user:
        return request.redirect("/")
    errors = ""

    template_filename = 'create.html'

    if request.method == "POST":
        name = request.get_form_var('name')
        product = request.get_form_var('product')
        org_proj = request.get_form_var('org_proj')
        summary = request.get_form_var('summary')
        repo_url = request.get_form_var('url')
        fork_from = request.get_form_var('fork_from')
        intern_banned = request.get_form_var('intern_banned', None)
        with_proxy = request.get_form_var('with_proxy', MIRROR_NOT_PROXY)
        with_proxy = int(with_proxy)
        mirror = None

        def add_people_project(project):
            name = "%s/%s" % (project.owner_id, project.name)
            _project = CodeDoubanProject.add(
                name=name,
                owner_id=project.owner_id,
                summary=project.summary,
                product=project.product,
                intern_banned=project.intern_banned)
            return _project

        def add_org_project(project):
            _project = CodeDoubanProject.add(
                name=name,
                owner_id=project.owner_id,
                summary=project.summary,
                product=project.product,
                intern_banned=project.intern_banned)
            return _project

        def add_mirror_project(project):
            name = "mirror/%s" % (project.name)
            _project = CodeDoubanProject.add(
                name=name,
                owner_id='mirror',
                summary=project.summary,
                product=project.product,
                intern_banned=project.intern_banned,
                mirror=project.mirror_url)
            if _project:
                CodeDoubanMirror.add(url=project.mirror_url,
                                     state=MIRROR_STATE_CLONING,
                                     project_id=_project.id,
                                     with_proxy=project.mirror_proxy)
            return _project

        def add_fork_project(project):
            name = "%s/%s" % (project.owner_id, project.name)
            _project = CodeDoubanProject.add(
                name=name,
                owner_id=project.owner_id,
                summary=project.summary,
                product=project.product,
                fork_from=project.fork_from,
                intern_banned=project.intern_banned)
            if _project:
                fork_from_project = CodeDoubanProject.get(project.fork_from)
                _project.update(project.summary, project.product, name,
                                fork_from_project.intern_banned)
            return _project

        def validate_project(project_type, project):
            error = ''
            if project_type in (PEOPLE_PROJECT, ORGANIZATION_PROJECT):
                error = project.validate()
            elif project_type == MIRROR_PROJECT:
                error = project.validate()
                if not error:
                    error = CodeDoubanMirror.validate(project.mirror_url)
            else:
                error = project.validate()
            return error

        def add_project(project):
            _project = None
            if project_type == PEOPLE_PROJECT:
                _project = add_people_project(project)
            elif project_type == ORGANIZATION_PROJECT:
                _project = add_org_project(project)
            elif project_type == MIRROR_PROJECT:
                _project = add_mirror_project(project)
            else:
                _project = add_fork_project(project)
            return _project

        project = CodeDoubanProject(None,
                                    name,
                                    user.username,
                                    summary,
                                    datetime.now(),
                                    product,
                                    None,
                                    None,
                                    fork_from=fork_from,
                                    intern_banned=intern_banned,
                                    mirror_url=repo_url,
                                    mirror_proxy=with_proxy)
        # FIXME: rename org_proj of html
        project_type = org_proj
        errors = validate_project(project_type, project)
        if errors:
            return st(template_filename, **locals())

        project = add_project(project)
        if not project:
            fork_from = ''
            errors = 'project exists'
            return st(template_filename, **locals())

        CodeDoubanProject.add_watch(project.id, user.name)
        return request.redirect('/%s/' % project.name)

    fork_from = ''
    if request.get_form_var('fork_from'):
        fork_from = CodeDoubanProject.get(request.get_form_var('fork_from'))
        name = "%s/%s" % (user.name, fork_from.realname)
        if CodeDoubanProject.exists(name):
            return request.redirect('/%s/' % name)
        projects = CodeDoubanProject.gets_by_owner_id(user.name)
        for p in projects:
            if p.origin_project_id == fork_from.id and '/' in p.name:
                return request.redirect('/%s/' % p.name)
    return st(template_filename, **locals())
Exemple #8
0
def new(request, proj_id):
    user = request.user
    CodeDoubanProject.add_watch(proj_id, user.name)
    return json.dumps({"ok": 1})