Exemplo n.º 1
0
def project(session):
    """ links up a Project with releases, tags, and comments for testing.
    """
    import datetime
    from pygameweb.project.models import Project, Release, Projectcomment, Tags

    from pygameweb.user.models import User, Group

    user = User(name="name",
                email="email",
                password="",
                disabled=0,
                active=True)

    the_project = Project(
        title="Stuntcat",
        summary="Summary of some project 1.",
        description="Description of some project.",
        uri="http://some.example.com/",
        datetimeon=datetime.datetime(2017, 1, 5),
        image="1.png",
        github_repo="https://github.com/pygame/stuntcat",
        user=user,
    )

    tag1 = Tags(project=the_project, value="game")
    tag2 = Tags(project=the_project, value="arcade")
    session.add(tag1)
    session.add(tag2)

    release1 = Release(
        datetimeon=datetime.datetime(2017, 1, 5),
        description="Some release.",
        srcuri="http://example.com/source.tar.gz",
        winuri="http://example.com/win.exe",
        macuri="http://example.com/mac.dmg",
        version="A release title.",
    )

    release2 = Release(
        datetimeon=datetime.datetime(2017, 1, 6),
        description="Some release with new things.",
        srcuri="http://example.com/source.tar.gz",
        winuri="http://example.com/win.exe",
        macuri="http://example.com/mac.dmg",
        version="A second release title.",
    )

    the_project.releases.append(release1)
    the_project.releases.append(release2)

    comment1 = Projectcomment(user=user, content="Some comment 1.", rating=5)
    comment2 = Projectcomment(user=user, content="Some comment 2.", rating=3)
    the_project.comments.append(comment1)
    the_project.comments.append(comment2)

    session.add(the_project)
    session.commit()
    return the_project
Exemplo n.º 2
0
def project(session, user):
    """ links up a Project with releases, tags, and comments for testing.
    """
    import datetime
    from pygameweb.project.models import Project, Release, Projectcomment, Tags

    the_project = Project(
        title='Some project title 1',
        summary='Summary of some project 1.',
        description='Description of some project.',
        uri='http://some.example.com/',
        datetimeon=datetime.datetime(2017, 1, 5),
        image='1.png',
        youtube_trailer='https://www.youtube.com/watch?v=8UnvMe1Neok',
        github_repo='https://github.com/pygame/pygameweb/',
        patreon='https://www.patreon.com/pygame',
        user=user
    )

    tag1 = Tags(project=the_project, value='game')
    tag2 = Tags(project=the_project, value='arcade')
    session.add(tag1)
    session.add(tag2)

    release1 = Release(datetimeon=datetime.datetime(2017, 1, 5),
                       description='Some release.',
                       srcuri='http://example.com/source.tar.gz',
                       winuri='http://example.com/win.exe',
                       macuri='http://example.com/mac.dmg',
                       version='A release title.')

    release2 = Release(datetimeon=datetime.datetime(2017, 1, 6),
                       description='Some release with new things.',
                       srcuri='http://example.com/source.tar.gz',
                       winuri='http://example.com/win.exe',
                       macuri='http://example.com/mac.dmg',
                       version='A second release title.')

    the_project.releases.append(release1)
    the_project.releases.append(release2)

    comment1 = Projectcomment(user=user, content="Some comment 1.", rating=5)
    comment2 = Projectcomment(user=user, content="Some comment 2.", rating=3)
    the_project.comments.append(comment1)
    the_project.comments.append(comment2)

    session.add(the_project)
    session.commit()
    return the_project
Exemplo n.º 3
0
def a_project(session, title, release_description, version, user):
    """ adds a second project with a couple of tags.
    """

    import datetime
    from pygameweb.project.models import Project, Tags, Release

    the_project2 = Project(
        title=title,
        summary='Summary of some project 2.',
        description='Description of some project 2.',
        uri='http://some.example.com/',
        datetimeon=datetime.datetime(2017, 1, 8),
        image='1.png',
        user=user
    )

    release1 = Release(datetimeon=datetime.datetime(2017, 1, 5),
                       description=release_description,
                       srcuri='http://example.com/source.tar.gz',
                       winuri='http://example.com/win.exe',
                       macuri='http://example.com/mac.dmg',
                       version=version)

    the_project2.releases.append(release1)

    tag3 = Tags(project=the_project2, value='2d')
    tag4 = Tags(project=the_project2, value='arcade')
    return the_project2, release1, tag3, tag4
Exemplo n.º 4
0
def release_from_gh(session, project, gh_release_atom, gh_release_api):
    """ make a Release from a gh release.

    :param gh_release_atom: from the atom feed.
    :param gh_release_api: from the API.
    """
    winuri = ''
    srcuri = ''
    macuri = ''
    for asset in gh_release_api['assets']:
        if asset["browser_download_url"].endswith('msi'):
            winuri = asset["browser_download_url"]
        elif asset["browser_download_url"].endswith('tar.gz'):
            srcuri = asset["browser_download_url"]
        elif asset["browser_download_url"].endswith('dmg'):
            macuri = asset["browser_download_url"]

    published_at = dateutil.parser.parse(gh_release_api["published_at"])
    # "2019-01-06T15:29:18Z",

    release = Release(
        datetimeon=published_at,
        description=gh_release_atom['content'][0]["value"],
        srcuri=srcuri,
        winuri=winuri,
        macuri=macuri,
        version=gh_release_atom['title'],
        project=project
    )
    return release
Exemplo n.º 5
0
def new_project():
    """ This adds both a project, and a release.
    """
    form = FirstReleaseForm()

    if form.validate_on_submit():

        now = datetime.datetime.now()

        user = current_user
        project = Project(
            title=form.title.data,
            summary=form.summary.data,
            description=form.description.data,
            uri=form.uri.data,
            datetimeon=now,
            user=user,
            youtube_trailer=form.youtube_trailer.data,
            github_repo=form.github_repo.data,
            patreon=form.patreon.data,
        )

        tags = [t.lstrip().rstrip() for t in form.tags.data.split(',')]
        if '' in tags:
            tags.remove('')

        for value in tags:
            tag = Tags(project=project, value=value)
            current_session.add(tag)

        release = Release(datetimeon=now,
                          description=form.description.data,
                          srcuri=form.srcuri.data,
                          winuri=form.winuri.data,
                          macuri=form.macuri.data,
                          version=form.version.data)
        project.releases.append(release)

        if form.image.data is not None:
            www = Path(current_app.config['WWW'])
            sec_fname = secure_filename(form.image.data.filename)
            extension = os.path.splitext(sec_fname)[-1]

            current_session.commit()
            image_fname = f'{project.id}{extension}'
            project.image = image_fname
            image_path = str(www / 'shots' / image_fname)

            save_image(form.image, image_path)

        current_session.add(project)
        current_session.commit()

        return redirect(url_for('project.view', project_id=project.id))

    return render_template('project/newproject.html', form=form)
Exemplo n.º 6
0
def edit_release(project_id, release_id):
    """ or create a new release if release_id is None.
    """
    project = project_for(project_id)
    if project.user.id != current_user.id:
        abort(404)
    if release_id is not None:
        release = release_for(release_id)
        if release.project.user.id != current_user.id:
            abort(404)

    if request.method == 'GET' and release_id is not None:
        form = ReleaseForm(obj=release)
    else:
        form = ReleaseForm()

    if form.validate_on_submit():

        if release_id is None:
            release = Release(datetimeon=datetime.datetime.now(),
                              description=form.description.data,
                              srcuri=form.srcuri.data,
                              winuri=form.winuri.data,
                              macuri=form.macuri.data,
                              version=form.version.data)
            project.releases.append(release)
            current_session.add(project)
        else:
            release.datetimeon = datetime.datetime.now()
            release.description = form.description.data
            release.srcuri = form.srcuri.data
            release.winuri = form.winuri.data
            release.macuri = form.macuri.data
            release.version = form.version.data
            current_session.add(release)

        current_session.commit()

        return redirect(
            url_for('project.release',
                    project_id=project_id,
                    release_id=release.id))

    return render_template('project/editrelease.html',
                           form=form,
                           project_id=project_id,
                           release_id=release_id)
Exemplo n.º 7
0
def make_pg(releases):
    return [Release(r[0], r[1], r[2]) for r in releases]