def test_user_filter_model(self): filter_details={"root":{"linkType":"All", "enabled":True, "conditions":[{"justAdded":False, "typeName":"SMPL", "enabled":True, "operatorID":"NotNull", "expressions":[{"typeName":"ENTATTR", "id":0}]}, {"justAdded":False, "typeName":"SMPL", "enabled":True, "operatorID":"IsNull", "expressions":[{"typeName":"ENTATTR", "id":1}]}, {"typeName":"PDCT", "linkType":"Any", "enabled": True, "conditions":[ {"justAdded":False, "typeName":"SMPL", "enabled":True, "operatorID":"NotNull", "expressions":[{"typeName":"ENTATTR", "id":3}]}, {"justAdded":False, "typeName":"SMPL", "enabled":True, "operatorID":"IsNull", "expressions":[{"typeName":"ENTATTR", "id":4}]}, ]}]}, "columns":[], "justsorted":[]} user = User(user_name='user', password='******', salt='salt', email='*****@*****.**') item = UserFilter(user=user, name='name', filter_details=filter_details) self.session.add(item) self.session.flush() assert item.user == user assert item.name == 'name' assert item.filter_details == filter_details assert str(item.build_query()) == str(sa.and_(FactData.fact_by_id(0) == True, FactData.fact_by_id(1) == False, sa.or_(FactData.fact_by_id(3) == True, FactData.fact_by_id(4) == False) ))
def __getitem__(self, key): filter = UserFilter.get_all(self.request).filter(UserFilter.user == self.request.user).filter(UserFilter.pk == key).first() if filter: filter.__parent__ = self filter.__name__ = key return filter raise KeyError(key)
def filter_view(request): """ List of jobs """ current_page = int(request.params.get('page', 0)) q = (FactData.get_all(request).filter(UserFilter.get_by_pk(request, request.context.pk).build_query()) .join(ScrapedData)) page_url = paginate.PageURL_WebOb(request) records = paginate.Page(q, current_page, url=page_url) return dict(filter=request.context.name, page = records)
def filter_view(request): """ List of jobs """ current_page = int(request.params.get('page', 0)) q = (FactData.get_all(request).filter( UserFilter.get_by_pk( request, request.context.pk).build_query()).join(ScrapedData)) page_url = paginate.PageURL_WebOb(request) records = paginate.Page(q, current_page, url=page_url) return dict(filter=request.context.name, page=records)
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') )
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'))
def test_user_filter_model(self): filter_details = { "root": { "linkType": "All", "enabled": True, "conditions": [{ "justAdded": False, "typeName": "SMPL", "enabled": True, "operatorID": "NotNull", "expressions": [{ "typeName": "ENTATTR", "id": 0 }] }, { "justAdded": False, "typeName": "SMPL", "enabled": True, "operatorID": "IsNull", "expressions": [{ "typeName": "ENTATTR", "id": 1 }] }, { "typeName": "PDCT", "linkType": "Any", "enabled": True, "conditions": [ { "justAdded": False, "typeName": "SMPL", "enabled": True, "operatorID": "NotNull", "expressions": [{ "typeName": "ENTATTR", "id": 3 }] }, { "justAdded": False, "typeName": "SMPL", "enabled": True, "operatorID": "IsNull", "expressions": [{ "typeName": "ENTATTR", "id": 4 }] }, ] }] }, "columns": [], "justsorted": [] } user = User(user_name='user', password='******', salt='salt', email='*****@*****.**') item = UserFilter(user=user, name='name', filter_details=filter_details) self.session.add(item) self.session.flush() assert item.user == user assert item.name == 'name' assert item.filter_details == filter_details assert str(item.build_query()) == str( sa.and_( FactData.fact_by_id(0) == True, FactData.fact_by_id(1) == False, sa.or_( FactData.fact_by_id(3) == True, FactData.fact_by_id(4) == False)))
def filter_list(request): """ Userilter list view """ return dict(items=UserFilter.get_all(request).filter(UserFilter.user == request.user))
def filter_list(request): """ Userilter list view """ return dict(items=UserFilter.get_all(request).filter( UserFilter.user == request.user))