Example #1
0
def index():
    # Slice of to pagination

    # List of filter by get args:
    # Example: /admin/sticky/?page=1&name_icontains=apple
    data = request.args.to_dict()

    # Type of filter
    engine_filter = {'name__icontains': str}

    # Prepare filter
    criteria = {}
    for k in data:
        if k in engine_filter:
            criteria[k] = engine_filter[k](data[k])

    pagination = Paginate('admin.sticky.index', count=len(Sticky.objects(**criteria)), per_page=10)
    page = pagination.get_page()
    stickys = Sticky.objects(**criteria)[(page-1) * 10:page * 10]
    return render.template('admin/sticky/index.html', stickys=stickys, pagination=pagination)
 def test_delete_exist_sticky_should_be_done(self):
     sticky = StickyFactory.create()
     resp = self.post('/admin/sticky/' + str(sticky.id) + '/delete',{})
     expect(len(Sticky.objects(id=sticky.id))).to_equal(0)