Ejemplo n.º 1
0
def project_edit(project_id):
    project = Project.query.filter_by(id=project_id).first_or_404()
    event = project.event
    starred = IsProjectStarred(project, current_user)
    allow_edit = starred or (not current_user.is_anonymous
                             and current_user.is_admin)
    if not allow_edit:
        flash('You do not have access to edit this project.', 'warning')
        return project_action(project_id, None)
    form = ProjectForm(obj=project, next=request.args.get('next'))
    form.progress.choices = projectProgressList(event.has_started
                                                or event.has_finished)
    form.category_id.choices = [(c.id, c.name)
                                for c in project.categories_all()]
    form.category_id.choices.insert(0, (-1, ''))
    if form.validate_on_submit():
        del form.id
        form.populate_obj(project)
        project.update()
        db.session.add(project)
        db.session.commit()
        cache.clear()
        flash('Project updated.', 'success')
        project_action(project_id, 'update', False)
        return redirect(url_for('public.project', project_id=project.id))
    return render_template('public/projectedit.html',
                           current_event=event,
                           project=project,
                           form=form)
Ejemplo n.º 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)
Ejemplo n.º 3
0
def project_post(project_id):
    project = Project.query.filter_by(id=project_id).first_or_404()
    event = project.event
    starred = IsProjectStarred(project, current_user)
    allow_edit = starred or (not current_user.is_anonymous
                             and current_user.is_admin)
    if not allow_edit:
        flash('You do not have access to edit this project.', 'warning')
        return project_action(project_id, None)
    form = ProjectPost(obj=project, next=request.args.get('next'))
    form.progress.choices = projectProgressList(event.has_started
                                                or event.has_finished)
    if not form.note.data:
        form.note.data = "---\n`%s` " % datetime.utcnow().strftime(
            "%d.%m.%Y %H:%M")
    if form.validate_on_submit():
        del form.id
        form.populate_obj(project)
        project.longtext += "\n\n" + form.note.data
        project.update()
        db.session.add(project)
        db.session.commit()
        cache.clear()
        flash('Project updated.', 'success')
        project_action(project_id, 'update', False)
        return redirect(url_for('public.project', project_id=project.id))
    return render_template('public/projectpost.html',
                           current_event=event,
                           project=project,
                           form=form)
Ejemplo n.º 4
0
def project_post(project_id):
    project = Project.query.filter_by(id=project_id).first_or_404()
    event = project.event
    starred = IsProjectStarred(project, current_user)
    allow_post = starred
    # or (not current_user.is_anonymous and current_user.is_admin)
    # allow_post = allow_post and not event.lock_resources
    if not allow_post:
        flash('You do not have access to post to this project.', 'warning')
        return project_action(project_id, None)
    form = ProjectPost(obj=project, next=request.args.get('next'))
    # Evaluate project progress
    stage, all_valid = validateProjectData(project)
    # Process form
    if form.validate_on_submit():
        if form.has_progress.data:
            # Check and update progress
            found_next = False
            if all_valid:
                for a in projectProgressList(True, False):
                    # print(a[0])
                    if found_next:
                        project.progress = a[0]
                        flash('Your project has been promoted!', 'info')
                        break
                    if a[0] == project.progress or \
                        not project.progress or \
                            project.progress < 0:
                        found_next = True
                        # print("Founddd")
            if not all_valid or not found_next:
                flash('Your project did not meet stage requirements.', 'info')

        # Update project data
        del form.id
        del form.has_progress
        form.populate_obj(project)
        project.update()
        db.session.add(project)
        db.session.commit()
        cache.clear()
        project_action(project_id,
                       'update',
                       action='post',
                       text=form.note.data)
        return redirect(
            url_for('project.project_view_posted', project_id=project.id))

    return render_template(
        'public/projectpost.html',
        current_event=event,
        project=project,
        form=form,
        stage=stage,
        all_valid=all_valid,
    )
Ejemplo n.º 5
0
def event_resources(event_id):
    event = Event.query.filter_by(id=event_id).first_or_404()
    steps = []
    for ix, p in enumerate(projectProgressList(True, False)):
        steps.append({
            'index': ix + 1,
            'name': p[1],
            'resources': SuggestionsByProgress(p[0])
        })
    steps.append({
        'name': '/etc',
        'index': -1,
        'resources': SuggestionsByProgress(None)
    })
    return render_template("public/resources.html",
                           current_event=event,
                           steps=steps)
Ejemplo n.º 6
0
def project_post(project_id):
    project = Project.query.filter_by(id=project_id).first_or_404()
    event = project.event
    starred = IsProjectStarred(project, current_user)
    allow_edit = starred or (not current_user.is_anonymous
                             and current_user.is_admin)
    if not allow_edit:
        flash('You do not have access to edit this project.', 'warning')
        return project_action(project_id, None)
    form = ProjectPost(obj=project, next=request.args.get('next'))
    # Populate progress dialog
    form.progress.choices = projectProgressList(event.has_started
                                                or event.has_finished)
    # Populate resource list
    resources = Resource.query.filter_by(is_visible=True).order_by(
        Resource.type_id).all()
    resource_list = [(0, '')]
    resource_list.extend([(r.id, r.of_type + ': ' + r.name)
                          for r in resources])
    form.resource.choices = resource_list
    # Process form
    if form.validate_on_submit():
        del form.id
        if form.resource.data == 0:
            form.resource.data = None
        form.populate_obj(project)
        project.update()
        db.session.add(project)
        db.session.commit()
        cache.clear()
        flash('Thanks for your commit!', 'success')
        project_action(project_id,
                       'update',
                       action='post',
                       text=form.note.data,
                       resource=form.resource.data)
        return redirect(url_for('public.project', project_id=project.id))
    return render_template('public/projectpost.html',
                           current_event=event,
                           project=project,
                           form=form)