Пример #1
0
    def test_datapackage(self, project, testapp):
        """Create a data package."""

        event = Event(name="Test Event", summary="Just testin")
        event.save()

        role = Role(name="Test Role")
        role.save()

        user = UserFactory(username="******")
        user.roles.append(role)
        user.save()

        proj1 = Project(name="Test Project")
        proj1.event = event
        proj1.user = user
        proj1.save()

        acty1 = Activity("review", proj1.id)
        acty1.content = "Hello World!"
        acty1.save()

        dp_json = PackageEvent(event, user)
        assert dp_json.title == "Test Event"

        acty1.delete()
        proj1.delete()
        event.delete()

        assert Event.query.filter_by(name="Test Event").count() == 0

        ImportEventPackage(dp_json)
        assert Event.query.filter_by(name="Test Event").count() == 1
Пример #2
0
def project_new(event_id):
    form = None
    event = Event.query.filter_by(id=event_id).first_or_404()
    if current_user and current_user.is_authenticated:
        project = Project()
        project.user_id = current_user.id
        project.progress = -1
        form = ProjectForm(obj=project, next=request.args.get('next'))
        form.progress.choices = projectProgressList(event.has_started)
        form.category_id.choices = [(c.id, c.name)
                                    for c in project.categories_all(event)]
        form.category_id.choices.insert(0, (-1, ''))
        if form.validate_on_submit():
            del form.id
            form.populate_obj(project)
            project.event = event
            project.update()
            db.session.add(project)
            db.session.commit()
            flash('Project added.', 'success')
            project_action(project.id, 'create', False)
            cache.clear()
            project_action(project.id, 'star', False)
            return redirect(url_for('public.project', project_id=project.id))
        del form.logo_icon
        del form.logo_color
    return render_template('public/projectnew.html',
                           current_event=event,
                           form=form)
Пример #3
0
def project_new(event_id):
    if not isUserActive(current_user):
        flash(
            "Your account needs to be activated - " +
            " please contact an organizer.", 'warning')
        return redirect(url_for('public.event', event_id=event_id))
    form = None
    event = Event.query.filter_by(id=event_id).first_or_404()
    if event.lock_starting:
        flash('Starting a new project is disabled for this event.', 'error')
        return redirect(url_for('public.event', event_id=event.id))
    if isUserActive(current_user):
        project = Project()
        project.user_id = current_user.id
        form = ProjectNew(obj=project, next=request.args.get('next'))
        form.category_id.choices = [(c.id, c.name)
                                    for c in project.categories_all(event)]
        if len(form.category_id.choices) > 0:
            form.category_id.choices.insert(0, (-1, ''))
        else:
            del form.category_id
        if form.validate_on_submit():
            del form.id
            form.populate_obj(project)
            project.event = event
            if event.has_started:
                project.progress = 5  # Start as team
            else:
                project.progress = -1  # Start as challenge
            project.update()
            db.session.add(project)
            db.session.commit()
            flash('Invite your team to Join this page!', 'success')
            project_action(project.id, 'create', False)
            cache.clear()
            if event.has_started:
                project_action(project.id, 'star', False)  # Join team
            if len(project.autotext_url) > 1:
                return project_autoupdate(project.id)
            else:
                purl = url_for('project.project_view', project_id=project.id)
                return redirect(purl)
    return render_template('public/projectnew.html',
                           active="projectnew",
                           current_event=event,
                           form=form)
Пример #4
0
def project_new(event_id):
    form = None
    event = Event.query.filter_by(id=event_id).first_or_404()
    if event.lock_starting:
        flash('Starting a new project is disabled for this event.', 'error')
        return redirect(url_for('public.event', event_id=event.id))
    if current_user and current_user.is_authenticated:
        project = Project()
        project.user_id = current_user.id
        form = ProjectNew(obj=project, next=request.args.get('next'))
        form.category_id.choices = [(c.id, c.name)
                                    for c in project.categories_all(event)]
        form.category_id.choices.insert(0, (-1, ''))
        if form.validate_on_submit():
            del form.id
            form.populate_obj(project)
            project.event = event
            if event.has_started:
                project.progress = 0
            else:
                project.progress = -1  # Start as challenge
            project.update()
            db.session.add(project)
            db.session.commit()
            flash('New challenge added.', 'success')
            project_action(project.id, 'create', False)
            cache.clear()
            project_action(project.id, 'star', False)
            if len(project.autotext_url) > 1:
                return project_autoupdate(project.id)
            else:
                return redirect(
                    url_for('public.project', project_id=project.id))
    return render_template('public/projectnew.html',
                           current_event=event,
                           form=form)
Пример #5
0
def project_new():
    project = Project()
    project.user_id = current_user.id
    form = ProjectForm(obj=project, next=request.args.get('next'))
    event = get_current_event()
    form.category_id.choices = [(c.id, c.name) for c in project.categories_for_event(event.id)]
    form.category_id.choices.insert(0, (-1, ''))
    if form.validate_on_submit():
        form.populate_obj(project)
        project.event = event
        project.update()
        db.session.add(project)
        db.session.commit()
        flash('Project added.', 'success')
        return project_action(project.id, 'create')
    del form.logo_icon
    del form.logo_color
    return render_template('public/projectnew.html', current_event=event, form=form)
Пример #6
0
    def test_user_schema(self, project, testapp):
        """Test user schema."""

        event = Event(name="Test Event", summary="Just testin")
        event.save()
        user = UserFactory(username="******")
        user.save()

        # Generate importable schema for local host
        hosturl = "https://localhost"

        # Initially just a warning message
        schema = get_schema_for_user_projects(user, hosturl)
        assert 'message' in schema

        # Join a project
        proj1 = Project(name="Test Project")
        proj1.event = event
        proj1.user = user
        proj1.save()
        ProjectActivity(proj1, "star", user)

        # Now we are a member of one project
        schema = get_schema_for_user_projects(user, hosturl)
        assert len(schema) == 1
        assert len(schema[0]["workPerformed"]) == 1

        # Create another project
        proj2 = Project(name="Another Project")
        proj2.event = event
        proj2.user = user
        proj2.save()
        ProjectActivity(proj2, "star", user)

        # Now we are a member of two projects
        schema = get_schema_for_user_projects(user, hosturl)
        assert len(schema[0]["workPerformed"]) == 2

        # Clean up
        proj1.delete()
        proj2.delete()
        event.delete()
        user.delete()
Пример #7
0
def project_new(event_id):
    if not isUserActive(current_user):
        flash(
            "Your account needs to be activated - " +
            " please contact an organizer.", 'warning')
        return redirect(url_for('public.event', event_id=event_id))
    form = None
    event = Event.query.filter_by(id=event_id).first_or_404()
    if event.lock_starting:
        flash('Starting a new project is disabled for this event.', 'error')
        return redirect(url_for('public.event', event_id=event.id))
    if not isUserActive(current_user):
        flash('Your user account is not permitted to start projects.', 'error')
        return redirect(url_for('public.event', event_id=event.id))
    # Collect resource tips
    suggestions = []
    if not event.lock_resources:
        suggestions = getSuggestionsForStage(0)
    # Project form
    project = Project()
    project.user_id = current_user.id
    form = ProjectNew(obj=project, next=request.args.get('next'))
    form.category_id.choices = [(c.id, c.name)
                                for c in project.categories_all(event)]
    if len(form.category_id.choices) > 0:
        form.category_id.choices.insert(0, (-1, ''))
    else:
        del form.category_id
    if form.validate_on_submit():
        tpl_id = None
        if form.template.data:
            tpl_id = form.template.data
        del form.id
        del form.template
        form.populate_obj(project)
        if tpl_id:
            template = Project.query.get(tpl_id)
            project.longtext = template.longtext
            project.image_url = template.image_url
            project.source_url = template.source_url
            project.webpage_url = template.webpage_url
            project.download_url = template.download_url
        # Check event state
        project.event = event
        if event.has_started:
            project.progress = 5  # Start as team
        else:
            project.progress = -1  # Start as challenge
        # Update the project
        project.update()
        db.session.add(project)
        db.session.commit()
        flash('Now invite your team to Join this page!', 'success')
        project_action(project.id, 'create', False)
        cache.clear()
        if event.has_started:
            project_action(project.id, 'star', False)  # Join team
        if len(project.autotext_url) > 1:
            return project_autoupdate(project.id)
        else:
            purl = url_for('project.project_view', project_id=project.id)
            return redirect(purl)
    return render_template('public/projectnew.html',
                           current_event=event,
                           form=form,
                           suggestions=suggestions,
                           active="projects")