Ejemplo n.º 1
0
def filter_del(request):
    """ UserFilter del view """

    schema = UserFilterDelSchema()
    schema = schema.bind(request=request)
    form = SubmitForm(schema)

    success_message = isinstance(request.context, RootFactory) \
        and _(u'The filter has been removed')

    if request.method == 'GET':
        return dict(form=form,
                        appstruct=request.context.__json__())
    else:
        try:
            controls = request.POST.items()
            captured = form.validate(controls)
        except deform.ValidationFailure, e:
            return dict(form=e, errors=e.error.children)

        filter = request.context

        DBSession.delete(filter)

        request.session.flash(success_message, 'success')

        return HTTPFound(
            location=request.route_url('filter_list')
        )
Ejemplo n.º 2
0
def filter_del(request):
    """ UserFilter del view """

    schema = UserFilterDelSchema()
    schema = schema.bind(request=request)
    form = SubmitForm(schema)

    success_message = isinstance(request.context, RootFactory) \
        and _(u'The filter has been removed')

    if request.method == 'GET':
        return dict(form=form, appstruct=request.context.__json__())
    else:
        try:
            controls = request.POST.items()
            captured = form.validate(controls)
        except deform.ValidationFailure, e:
            return dict(form=e, errors=e.error.children)

        filter = request.context

        DBSession.delete(filter)

        request.session.flash(success_message, 'success')

        return HTTPFound(location=request.route_url('filter_list'))
Ejemplo n.º 3
0
def filter_add(request):
    """ UserFilter add/edit view """

    schema = UserFilterSchema()
    schema = schema.bind(request=request)
    form = SubmitForm(schema)
    form.children[-1].renderer = renderer

    success_message = isinstance(request.context, RootFactory) \
        and _(u'The filter was created') \
        or _(u'The filter was updated')

    if request.method == 'GET':
        if isinstance(request.context, RootFactory):
            return dict(form=form)
        else:
            return dict(form=form,
                        appstruct=request.context.__json__())
    else:
        try:
            controls = request.POST.items()
            captured = form.validate(controls)
        except deform.ValidationFailure, e:
            return dict(form=e, errors=e.error.children)

        if isinstance(request.context, RootFactory):
            filter = UserFilter(user=request.user, name=captured['name'], filter_details=captured['filter_details'])
        else:
            filter = request.context
            filter.name = captured['name']
            filter.filter_details = captured['filter_details']

        DBSession.add(filter)

        request.session.flash(success_message, 'success')

        return HTTPFound(
            location=request.route_url('filter_list')
        )
Ejemplo n.º 4
0
def filter_add(request):
    """ UserFilter add/edit view """

    schema = UserFilterSchema()
    schema = schema.bind(request=request)
    form = SubmitForm(schema)
    form.children[-1].renderer = renderer

    success_message = isinstance(request.context, RootFactory) \
        and _(u'The filter was created') \
        or _(u'The filter was updated')

    if request.method == 'GET':
        if isinstance(request.context, RootFactory):
            return dict(form=form)
        else:
            return dict(form=form, appstruct=request.context.__json__())
    else:
        try:
            controls = request.POST.items()
            captured = form.validate(controls)
        except deform.ValidationFailure, e:
            return dict(form=e, errors=e.error.children)

        if isinstance(request.context, RootFactory):
            filter = UserFilter(user=request.user,
                                name=captured['name'],
                                filter_details=captured['filter_details'])
        else:
            filter = request.context
            filter.name = captured['name']
            filter.filter_details = captured['filter_details']

        DBSession.add(filter)

        request.session.flash(success_message, 'success')

        return HTTPFound(location=request.route_url('filter_list'))