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
Example #2
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
Example #3
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
Example #4
0
def edit_project(project_id):
    project = project_for(project_id)
    if project.user.id != current_user.id:
        abort(404)

    if request.method == 'GET':
        form = ProjectForm(obj=project)
        form.tags.data = ','.join([t.value for t in project.tags])
        form.image.data = ''
    else:
        form = ProjectForm()

    if form.validate_on_submit():

        project.title = form.title.data
        project.summary = form.summary.data
        project.description = form.description.data
        project.uri = form.uri.data
        project.datetimeon = datetime.datetime.now()
        project.youtube_trailer = form.youtube_trailer.data
        project.github_repo = form.github_repo.data
        project.patreon = form.patreon.data

        for tag in (current_session.query(Tags).filter(
                Tags.project_id == project.id).all()):
            current_session.delete(tag)

        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)

        current_session.add(project)
        current_session.commit()

        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]

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

            save_image(form.image, image_path)
            current_session.commit()

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

    return render_template('project/editproject.html',
                           form=form,
                           project_id=project_id)
Example #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)