Exemple #1
0
def feedback_form_view(project, request):
    """
    View for the feedback form
    """

    form_controller = FormController(project.feedback_form)

    return dict(
        project=project,
        form=project.feedback_form,
        menu=project_menu(project, request, 'feedback_form'),
        form_widgets=form_controller.render_widgets(request),
        widget_types=[w[0] for w in all_widget_types],
    )
Exemple #2
0
def feedback(project, request):
    session = DBSession()

    item_id = request.matchdict.get('item_id',None)
    items = project.get_items_for_user(request.user)
    pending_items = [i for i in items if not i.submitted]
    completed_items = [i for i in items if i.submitted]

    if item_id:
        item = project.get_item_for_user(request.user, item_id)
    elif pending_items:
        item = pending_items[0]
    else:
        item = None

    if item is not None:
        item = project.get_item(item.id)
        feedback = session.query(FeedbackRecord).filter(FeedbackRecord.user==request.user).filter(FeedbackRecord.item==item).first()
    else:
        feedback = None

    item_controller = FormController(project.item_form)
    feedback_controller = FormController(project.feedback_form)

    if request.method == 'POST' and item:
        feedback_controller.validate_from_request(request)

        if feedback_controller.errors:
            request.session.flash('There was a problem with your feedback', 'errors')
        else:
            if not feedback:
                feedback = FeedbackRecord(project, request.user, item)
                session.add(feedback)
    
            feedback.update_submitted()
            feedback_controller.populate_record_from_request(feedback, request)
    
            request.session.flash('Feedback on %s submitted' % item.title, 'messages')
    
            # Once feedback is submitted, load the next
            # record from the top of the list
    
            if request.params.get('submit','') == 'save_and_next':
                return HTTPFound(
                    location=route_url('project:feedback', request, project_id=project.id)
                )
            else:
                return HTTPFound(
                    location=route_url('project:feedback:item', request, project_id=project.id, item_id=item.id)
                )

    return dict(
        pending_items=pending_items,
        completed_items=completed_items,
        item=item,
        item_values=item_controller.render_values(request, item),
        form_widgets=feedback_controller.render_widgets(request, feedback),
        project=project,
        responsive_layout=True,
    )
Exemple #3
0
def item_form_view(project, request):
    """
    View for the item form
    """

    form_controller = FormController(project.item_form)

    return dict(
        project=project,
        form=project.item_form,
        menu=project_menu(project, request, 'records'),
        form_widgets=form_controller.render_widgets(request),
        widget_types=[w[0] for w in all_widget_types],
    )
Exemple #4
0
def record(project, request):
    form_controller = FormController(project.item_form)

    record_id = request.matchdict.get("record_id", None)

    if record_id is not None:
        record = project.get_item(record_id)
    else:
        record = None

    if record and not record.reviewed:
        record.reviewed = True

    if request.method == "POST":
        title = request.params.get("title", "").strip()
        submit = request.params.get("submit", "")

        if not title and submit.find("finish") >= 0:
            return HTTPFound(location=route_url("project:feedback_form", request, project_id=project.id))

        elif not title:
            request.session.flash("%s Name or Title is required!" % project.item_name, "errors")

        elif title:
            form_controller = FormController(project.item_form)
            form_controller.validate_from_request(request)

            if form_controller.errors:
                request.session.flash("There was a problem with your submission", "errors")

            else:
                request.session.flash("%s saved!" % title, "messages")

                if record is None:
                    record = ItemRecord(project, title)

                record.title = title

                form_controller.populate_record_from_request(record, request)

                session = DBSession()
                session.add(record)
                session.flush()

                if submit.find("add") >= 0:
                    route = "project:record:add"
                elif submit.find("finish") >= 0:
                    route = "project:feedback_form"
                else:
                    route = "project:record"

                return HTTPFound(location=route_url(route, request, project_id=project.id, record_id=record.id))

    return dict(
        project=project,
        menu=project_menu(project, request, "records"),
        form_widgets=form_controller.render_widgets(request, record),
        record=record,
    )
Exemple #5
0
def record_collect(request):
    session = DBSession()

    collect_code = request.matchdict['collect_code']

    project = session.query(Project).filter(Project.collect_code == collect_code).first()

    form_controller = FormController(project.item_form)

    if request.method == 'POST':
        title = request.params.get('title', '').strip()
        submit = request.params.get('submit','')

        if not title and submit.find('finish') >= 0:
            return HTTPFound(
                location=route_url('project:collect', request, project_id=project.id)
            )

        elif not title:
            request.session.flash('%s Name or Title is required!' % project.item_name, 'errors')

        elif title:
            form_controller = FormController(project.item_form)
            form_controller.validate_from_request(request)

            if form_controller.errors:
                request.session.flash('There was a problem with your submission', 'errors')

            else:
                record = ItemRecord(project, title)
                record.title = title
                record.reviewed = False

                form_controller.populate_record_from_request(record, request)
    
                session.add(record)
                session.flush()
    
                return HTTPFound(
                    location=route_url('project:collect:thanks', request, collect_code=project.collect_code)
                )

    return dict(
        project=project,
        form_widgets=form_controller.render_widgets(request, None)
    )