Beispiel #1
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,
    )
Beispiel #2
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)
    )