Beispiel #1
0
    def get(self):

        page_size = self.get_argument_int('sepa', 10)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'ASC')

        by_exp = desc(by) if sort == 'DESC' else asc(by)
        start = (cur_page - 1) * page_size
        stop = start + page_size

        apps = self.db.query(Appliance).filter_by(
            user_id=self.current_user.id).order_by(by_exp)

        total = apps.count()
        apps = apps.slice(start, stop)

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        d = {
            'title': self.trans(_('My Appliances')),
            'APPLIANCE_LIST': apps,
            'page_html': page_html
        }

        self.render('myun/appliance/index.html', **d)
Beispiel #2
0
    def get_post_votes(self):

        page_size = self.get_argument_int('ps', 20)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'created')
        order = self.get_argument_int('order', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        VOTE_LIST = self.db.query(ForumPostVote)

        if by not in ['id', 'created', 'updated']:
            by = 'id'

        total = VOTE_LIST.count()

        sort_by_obj = desc(by) if order else asc(by)
        VOTE_LIST = VOTE_LIST.order_by(sort_by_obj).slice(start, stop).all()

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        d = {
            'title': _('Forum Post Vote History'),
            'VOTE_LIST': VOTE_LIST,
            'VOTE_TOTAL': total,
            'page_html': page_html
        }

        self.render('forum/index_post_votes.html', **d)
Beispiel #3
0
    def get(self):

        cur_page, page_size, start, stop = pagination(self)

        article_q = self.db.query(BlogArticle).filter_by(
            user_id = self.current_user.id )

        # 选择本周、本月、本年?
        article_q, time = self.do_time_select( article_q )

        count = article_q.count()

        # 排序
        article_q, sortby = self.do_sort( article_q )

        article_q = article_q.slice(start, stop)

        d = { 'article_list': article_q,
              'article_total': count,
              'sortby': sortby,
              'time': time,
              'urlupdate': lambda k, v: urlupdate(self.request.uri, k, v),
        }

        self.render('blog/consoles/article_list.html', **d)
    def get(self):

        catalog_id = self.get_argument_int('catalog', 0)
        page_size = self.get_argument_int('sepa', 20)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'ASC')
        uid = self.get_argument('uid', 0)

        if by not in [
                'name', 'created', 'updated', 'id', 'os', 'disksize',
                'user_id', 'catalog_id', 'filesize', 'islocked', 'isprivate',
                'like', 'unlike', 'visit'
        ]:
            by = 'id'

        by_exp = desc(by) if sort == 'DESC' else asc(by)
        start = (cur_page - 1) * page_size
        stop = start + page_size

        catalog = self.db.query(ApplianceCatalog).get(catalog_id)
        user = self.db.query(User).get(uid)

        apps = self.db.query(Appliance)

        if catalog:
            apps = apps.filter_by(catalog_id=catalog_id)

        if user:
            apps = apps.filter_by(user_id=uid)

        apps = apps.order_by(by_exp)

        total = apps.count()
        apps = apps.slice(start, stop)

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        catalogs = self.db.query(ApplianceCatalog).all()
        for c in catalogs:
            c.total = self.db.query(
                Appliance.id).filter_by(catalog_id=c.id).count()

        d = {
            'title': _('LuoYun Appliance Management'),
            'BY': by,
            'SORT': sort,
            'CATALOG_LIST': catalogs,
            'CATALOG': catalog,
            'APPLIANCE_LIST': apps,
            'PAGE_HTML': page_html,
            'CATALOG': catalog,
            'USER': user,
            'TOTAL_APPLIANCE': total,
            'human_size': human_size,
            'urlupdate': self.urlupdate,
            'PAGE_SIZE': page_size
        }

        self.render('admin/appliance/index.html', **d)
Beispiel #5
0
    def get(self):

        page_size = self.get_argument_int('sepa', 50)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'id')
        order = self.get_argument_int('order', 1)
        gid = self.get_argument_int('gid', -1)

        RL = self.db.query(Resource)
        total = RL.count()

        by_obj = Resource.id
        by_exp = desc(by_obj) if order else asc(by_obj)

        RL = RL.order_by(by_exp)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        RL = RL.slice(start, stop)

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        d = {
            'title': self.trans(_('Admin User Management')),
            'RESOURCE_TOTAL': total,
            'urlupdate': self.urlupdate,
            'RESOURCE_LIST': RL,
            'PAGE_HTML': page_html,
            'PAGE_SIZE': page_size
        }

        self.render('admin/resource/index.html', **d)
Beispiel #6
0
    def get_post_votes(self):

        page_size = self.get_argument_int('ps', 20)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'created')
        order = self.get_argument_int('order', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        VOTE_LIST = self.db.query(ForumPostVote)

        if by not in ['id', 'created', 'updated']:
            by = 'id'

        total = VOTE_LIST.count()

        sort_by_obj = desc(by) if order else asc(by)
        VOTE_LIST = VOTE_LIST.order_by(
            sort_by_obj).slice(start, stop).all()

        page_html = pagination(
            self.request.uri, total, page_size, cur_page )

        d = { 'title': _('Forum Post Vote History'),
              'VOTE_LIST': VOTE_LIST,
              'VOTE_TOTAL': total,
              'page_html': page_html }

        self.render('forum/index_post_votes.html', **d)
Beispiel #7
0
    def get(self, article_id):

        cur_uid = self.current_user.id if self.current_user else 0

        article = self.db.query(BlogArticle).get( article_id )

        if not article:
            emsg = _('Can not find article %s') % article_id
            return self.send_error(404, emsg=emsg)

        if not article.is_public:
            if cur_uid != article.user_id:
                emsg = _('Article %s is not public.') % article_id
                return self.send_error(404, emsg=emsg)

        cur_page, page_size, start, stop = pagination(self)

        post_total = article.post_count

        posts = self.db.query(BlogPost).filter_by(
            article_id = article_id).order_by(
                get_post_order(self)).slice(start, stop)

        # 增加查看次数
        article.view_count += 1
        self.db.commit()

        self.data = dict(article = article,
                         post_total = post_total,
                         posts = posts,
                         ftime = ftime,
                         urlupdate = urlupdate,
                         urlupdate2 = urlupdate2)

        self.render('blog/article_view.html')
Beispiel #8
0
    def get(self):

        page_size = self.get_argument_int('sepa', 50)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'id')
        order = self.get_argument_int('order', 1)
        gid = self.get_argument_int('gid', -1)

        RL = self.db.query(Resource)
        total = RL.count()

        by_obj = Resource.id
        by_exp = desc(by_obj) if order else asc(by_obj)

        RL = RL.order_by( by_exp )

        start = (cur_page - 1) * page_size
        stop = start + page_size

        RL = RL.slice(start, stop)

        page_html = pagination( self.request.uri, total,
                                page_size, cur_page )

        d = { 'title': self.trans(_('Admin User Management')),
              'RESOURCE_TOTAL': total,
              'urlupdate': self.urlupdate,
              'RESOURCE_LIST': RL, 'PAGE_HTML': page_html,
              'PAGE_SIZE': page_size }

        self.render( 'admin/resource/index.html', **d )
Beispiel #9
0
    def get(self):

        by = self.get_argument('by', 'id')
        order = self.get_argument_int('order', 1)
        status = self.get_argument('status', None)
        page_size = self.get_argument_int('sepa', 50)
        cur_page = self.get_argument_int('p', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        jobs = self.db.query(SiteJob)

        if by not in ['id', 'created', 'updated']:
            by = 'id';

        by = desc(by) if order else asc(by)
        jobs = jobs.order_by( by )

        total = jobs.count()

        jobs = jobs.slice(start, stop)

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        d = { 'PAGE_HTML': page_html,
              'status': status,
              'JOB_LIST': jobs }

        self.render('admin/site/job/index.html', **d)
Beispiel #10
0
    def get(self):

        by = self.get_argument('by', 'id')
        order = self.get_argument_int('order', 1)
        status = self.get_argument('status', None)
        page_size = self.get_argument_int('sepa', 50)
        cur_page = self.get_argument_int('p', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        jobs = self.db.query(SiteJob)

        if by not in ['id', 'created', 'updated']:
            by = 'id'

        by = desc(by) if order else asc(by)
        jobs = jobs.order_by(by)

        total = jobs.count()

        jobs = jobs.slice(start, stop)

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        d = {'PAGE_HTML': page_html, 'status': status, 'JOB_LIST': jobs}

        self.render('admin/site/job/index.html', **d)
Beispiel #11
0
    def get(self):

        view = self.get_argument('view', 'all')
        by = self.get_argument('by', 'updated')
        order = self.get_argument_int('order', 1)
        status = self.get_argument('status', 'running')
        page_size = self.get_argument_int('sepa',
                                          settings.INSTANCE_HOME_PAGE_SIZE)
        cur_page = self.get_argument_int('p', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        if status == 'running':
            slist = settings.INSTANCE_SLIST_RUNING
        elif status == 'stoped':
            slist = settings.INSTANCE_SLIST_STOPED
        else:
            status == 'all'
            slist = settings.INSTANCE_SLIST_ALL

        instances = self.db.query(Instance).filter(
            Instance.isprivate != True).filter(Instance.status.in_(slist))

        if view == 'self' and self.current_user:
            instances = instances.filter_by(user_id=self.current_user.id)

        if by == 'created':
            by_obj = Instance.created
        elif by == 'user':
            by_obj = Instance.user_id
        else:
            by_obj = Instance.updated

        sort_by_obj = desc(by_obj) if order else asc(by_obj)

        instances = instances.order_by(sort_by_obj)

        # TODO: may have a more highly active count ( use id )
        total = instances.count()

        instances = instances.slice(start, stop)

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        d = {
            'title': self.title,
            'INSTANCE_LIST': instances,
            'cur_page': cur_page,
            'SORTBY': by,
            'ORDER': "0" if order == 0 else "1",
            'STATUS': status,
            'VIEW': view,
            'urlupdate': self.urlupdate,
            'page_html': page_html
        }

        self.render("instance/index.html", **d)
Beispiel #12
0
    def get(self):

        view = self.get_argument('view', 'all')
        by = self.get_argument('by', 'updated')
        order = self.get_argument_int('order', 1)
        status = self.get_argument('status', 'running')
        page_size = self.get_argument_int(
                'sepa', settings.INSTANCE_HOME_PAGE_SIZE)
        cur_page = self.get_argument_int('p', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        if status == 'running':
            slist = settings.INSTANCE_SLIST_RUNING
        elif status == 'stoped':
            slist = settings.INSTANCE_SLIST_STOPED
        else:
            status == 'all'
            slist = settings.INSTANCE_SLIST_ALL

        instances = self.db.query(Instance).filter(
            Instance.isprivate != True ).filter(
            Instance.status.in_( slist) )

        if view == 'self' and self.current_user:
            instances = instances.filter_by(
                user_id = self.current_user.id )

        if by == 'created':
            by_obj = Instance.created
        elif by == 'user':
            by_obj = Instance.user_id
        else:
            by_obj = Instance.updated

        sort_by_obj = desc(by_obj) if order else asc(by_obj)

        instances = instances.order_by( sort_by_obj )

        # TODO: may have a more highly active count ( use id )
        total = instances.count()

        instances = instances.slice(start, stop)

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        d = { 'title': self.title,
              'INSTANCE_LIST': instances,
              'cur_page': cur_page,
              'SORTBY': by, 'ORDER': "0" if order == 0 else "1",
              'STATUS': status, 'VIEW': view,
              'urlupdate': self.urlupdate,
              'page_html': page_html }

        self.render("instance/index.html", **d)
Beispiel #13
0
    def get_index(self):

        page_size = self.get_argument_int("sepa", 50)
        cur_page = self.get_argument_int("p", 1)
        by = self.get_argument("by", "id")
        order = self.get_argument_int("order", 1)
        user_id = self.get_argument_int("user", 0)
        target_type = self.get_argument_int("target_type", None)
        target_id = self.get_argument_int("target_id", 0)
        comefrom = self.get_argument("comefrom", None)
        result = self.get_argument("result", False)

        if by in ["id", "who_id", "comefrom", "target_type", "target_id", "isok"]:
            by = by
        elif by == "when":
            by = LyTrace.when
        elif by == "do":
            by = LyTrace.do
        else:
            return self.write(self.trans(_("Wrong sort by value: %s")) % by)

        by_exp = desc(by) if order else asc(by)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        traces = self.db.query(LyTrace)

        if user_id:
            user = self.db.query(User).get(user_id)
            if user:
                traces = traces.filter_by(who_id=user_id)
            else:
                return self.write(self.trans(_("Can not find user by id %s")) % user_id)
        else:
            user = None

        traces = traces.order_by(by_exp).slice(start, stop).all()

        total = self.db.query(LyTrace.id).count()

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        def sort_by(by):
            return self.urlupdate({"by": by, "order": 1 if order == 0 else 0, "p": 1})

        d = {
            "title": self.trans(_("Trace system action")),
            "sort_by": sort_by,
            "TRACE_LIST": traces,
            "PAGE_HTML": page_html,
            "USER": user,
            "TOTAL_TRACE": total,
        }

        self.render("system/traces.html", **d)
Beispiel #14
0
    def get(self):

        A, msg = self.get_appliance_byid()
        if not A:
            return self.render404( msg )

        view = self.get_argument('view', 'all')
        by = self.get_argument('by', 'updated')
        sort = self.get_argument('sort', 'desc')
        status = self.get_argument('status', 'all')
        page_size = self.get_argument_int(
                'sepa', settings.APPLIANCE_INSTANCE_LIST_PAGE_SIZE)

        cur_page = self.get_argument_int('p', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        if status == 'running':
            slist = settings.INSTANCE_SLIST_RUNING
        elif status == 'stoped':
            slist = settings.INSTANCE_SLIST_STOPED
        else:
            slist = settings.INSTANCE_SLIST_ALL

        instances = self.db.query(Instance).filter(
            Instance.isprivate != True ).filter(
            Instance.status.in_( slist) ).filter(
            Instance.appliance_id == A.id)
            

        if view == 'self' and self.current_user:
            instances = instances.filter_by(
                user_id = self.current_user.id )

        if by == 'created':
            by_obj = Instance.created
        else:
            by_obj = Instance.updated

        sort_by_obj = desc(by_obj) if sort == 'desc' else asc(by_obj)

        instances = instances.order_by( sort_by_obj )

        total = instances.count()
        instances = instances.slice(start, stop).all()

        page_html = pagination(self.request.uri, total,  page_size, cur_page)

        d = { 'title': _('View Appliance "%s"') % A.name,
              'appliance': A,
              'instances': instances,
              'page_html': page_html }

        self.render('appliance/view.html', **d)
Beispiel #15
0
    def get_index(self):

        page_size = self.get_argument_int('sepa', 50)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'id')
        order = self.get_argument_int('order', 1)
        user_id = self.get_argument_int('user', 0)
        target_type = self.get_argument_int('target_type', None)
        target_id = self.get_argument_int('target_id', 0)
        comefrom = self.get_argument('comefrom', None)
        result = self.get_argument('result', False)

        if by in ['id', 'who_id', 'comefrom', 'target_type', 'target_id', 'isok']:
            by = by
        elif by == 'when':
            by = LyTrace.when
        elif by == 'do':
            by = LyTrace.do
        else:
            return self.write( self.trans(_('Wrong sort by value: %s')) % by )

        by_exp = desc(by) if order else asc(by)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        traces = self.db.query(LyTrace)

        if user_id:
            user = self.db.query(User).get(user_id)
            if user:
                traces = traces.filter_by(who_id=user_id)
            else:
                return self.write( self.trans(_('Can not find user by id %s')) % user_id )
        else: user = None

        traces = traces.order_by(by_exp).slice(start, stop).all()

        total = self.db.query(LyTrace.id).count()
            
        page_html = pagination(self.request.uri, total, page_size, cur_page)


        def sort_by(by):
            return self.urlupdate(
                {'by': by, 'order': 1 if order == 0 else 0, 'p': 1})

        d = { 'title': self.trans(_('Trace system action')),
              'sort_by': sort_by,
              'TRACE_LIST': traces, 'PAGE_HTML': page_html,
              'USER': user, 'TOTAL_TRACE': total }

        self.render( 'system/traces.html', **d )
Beispiel #16
0
    def get(self):

        cur_page, page_size, start, stop = pagination(self)
        total = self.db.query(User).count()
        accounts = self.db.query(User).order_by(
            desc(User.id)).slice(start, stop)

        self.data = {'account_list': accounts,
                     'account_total': total,
                     'ftime': ftime}

        self.render('account/admins/list.html')
Beispiel #17
0
    def get(self):

        catalog_id = self.get_argument_int('catalog', 0)
        page_size = self.get_argument_int('sepa', 20)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'ASC')
        uid = self.get_argument('uid', 0)

        if by not in [ 'name', 'created', 'updated', 'id', 'os',
                       'disksize',
                       'user_id', 'catalog_id', 'filesize',
                       'islocked', 'isprivate',
                       'like', 'unlike', 'visit' ]:
            by = 'id'

        by_exp = desc(by) if sort == 'DESC' else asc(by)
        start = (cur_page - 1) * page_size
        stop = start + page_size

        catalog = self.db.query(ApplianceCatalog).get( catalog_id )
        user = self.db.query(User).get( uid )

        apps = self.db.query(Appliance)

        if catalog:
            apps = apps.filter_by(catalog_id=catalog_id)

        if user:
            apps = apps.filter_by(user_id = uid)

        apps = apps.order_by(by_exp)

        total = apps.count()
        apps = apps.slice(start, stop)
            
        page_html = pagination(self.request.uri, total, page_size, cur_page)

        catalogs = self.db.query(ApplianceCatalog).all()
        for c in catalogs:
            c.total = self.db.query(Appliance.id).filter_by( catalog_id = c.id ).count()

        d = { 'title': _('LuoYun Appliance Management'),
              'BY': by, 'SORT': sort,
              'CATALOG_LIST': catalogs, 'CATALOG': catalog,
              'APPLIANCE_LIST': apps, 'PAGE_HTML': page_html,
              'CATALOG': catalog, 'USER': user,
              'TOTAL_APPLIANCE': total,
              'human_size': human_size,
              'urlupdate': self.urlupdate,
              'PAGE_SIZE': page_size }

        self.render( 'admin/appliance/index.html', **d )
Beispiel #18
0
    def get_index(self):

        user_id = self.get_argument_int('user', 0)
        by = self.get_argument('by', 'id')
        order = self.get_argument_int('order', 1)

        if by not in [
                'id', 'user_id', 'status', 'target_type', 'target_id',
                'action', 'created', 'started', 'ended'
        ]:
            by = 'id'

        order_func = desc(by) if order else asc(by)

        page_size = self.get_argument_int('sepa', 50)
        cur_page = self.get_argument_int('p', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        JOB_LIST = self.db.query(Job)

        U = None
        if user_id:
            U = self.db.query(User).get(user_id)
            JOB_LIST = JOB_LIST.filter(Job.user_id == user_id)

        JOB_TOTAL = JOB_LIST.count()
        JOB_LIST = JOB_LIST.order_by(order_func).slice(start, stop)

        page_html = pagination(self.request.uri,
                               JOB_TOTAL,
                               page_size,
                               cur_page,
                               sepa_range=[20, 50, 100])

        def sort_by(by):
            return self.urlupdate({
                'by': by,
                'order': 1 if order == 0 else 0,
                'p': 1
            })

        d = {
            'title': 'Jobs',
            'U': U,
            'sort_by': sort_by,
            'JOB_TOTAL': JOB_TOTAL,
            'JOB_LIST': JOB_LIST,
            'page_html': page_html
        }

        self.render('admin/job/index.html', **d)
Beispiel #19
0
    def get(self):

        view = self.get_argument('view', 'all')
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'desc')
        status = self.get_argument('status', 'all')
        page_size = self.get_argument_int(
                'sepa', settings.MYUN_INSTANCE_LIST_PAGE_SIZE)
        cur_page = self.get_argument_int('p', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        if status == 'running':
            slist = settings.INSTANCE_SLIST_RUNING
        elif status == 'stoped':
            slist = settings.INSTANCE_SLIST_STOPED
        else:
            slist = None

        if slist:
            instances = self.db.query(Instance).filter(
                Instance.status.in_( slist) ).filter_by(
                user_id = self.current_user.id )
        else:
            instances = self.db.query(Instance).filter(
                Instance.status != DELETED_S ).filter_by(
                user_id = self.current_user.id )

        # TODO: does this work ?
        if by == 'created':
            by_obj = Instance.created
        elif by == 'username':
            by_obj = Instance.user.username
        else:
            by_obj = Instance.id

        sort_by_obj = desc(by_obj) if sort == 'desc' else asc(by_obj)

        instances = instances.order_by( sort_by_obj )

        total = instances.count()
        instances = instances.slice(start, stop).all()

        page_html = pagination(self.request.uri, total, page_size, cur_page)


        d = { 'INSTANCE_LIST': instances, 'page_html': page_html }

        self.render( 'myun/instance/index.html', **d)
Beispiel #20
0
    def get(self):

        cur_page, page_size, start, stop = pagination(self)
        total = self.db.query(User).count()
        accounts = self.db.query(User).order_by(desc(User.id)).slice(
            start, stop)

        self.data = {
            'account_list': accounts,
            'account_total': total,
            'ftime': ftime
        }

        self.render('account/admins/list.html')
Beispiel #21
0
    def my_box_list(self, show="inbox"):

        UID = self.current_user.id

        page_size = self.get_argument_int('sepa', 20)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'DESC')

        if by == 'status':
            by = Message.status
        elif by == 'isread':
            by = Message.isread
        elif by == 'readtime':
            by = Message.readtime
        elif by == 'sender':
            by = Message.sender_id
        else:
            by = Message.id

        by_exp = desc(by) if sort == 'DESC' else asc(by)
        start = (cur_page - 1) * page_size
        stop = start + page_size

        if show == "inbox":
            ml = self.db.query(Message).filter_by(receiver_id=UID,
                                                  isinbox=True)
        elif show == "outbox":
            ml = self.db.query(Message).filter_by(
                sender_id=UID,
                isinbox=False).filter(Message.receiver_id != None)
        elif show == "notice":
            ml = self.db.query(Message).filter(Message.receiver_id == None)
        else:
            return {}

        total = ml.count()

        ml = ml.order_by(by_exp).slice(start, stop).all()

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        return {
            'MESSAGE_LIST': ml,
            'PAGE_HTML': page_html,
            'TOTAL': total,
            'SORT': sort,
            'BY': by
        }
Beispiel #22
0
    def get(self):

        view = self.get_argument('view', 'all')
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'desc')
        status = self.get_argument('status', 'all')
        page_size = self.get_argument_int(
            'sepa', settings.MYUN_INSTANCE_LIST_PAGE_SIZE)
        cur_page = self.get_argument_int('p', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        if status == 'running':
            slist = settings.INSTANCE_SLIST_RUNING
        elif status == 'stoped':
            slist = settings.INSTANCE_SLIST_STOPED
        else:
            slist = None

        if slist:
            instances = self.db.query(Instance).filter(
                Instance.status.in_(slist)).filter_by(
                    user_id=self.current_user.id)
        else:
            instances = self.db.query(Instance).filter(
                Instance.status != DELETED_S).filter_by(
                    user_id=self.current_user.id)

        # TODO: does this work ?
        if by == 'created':
            by_obj = Instance.created
        elif by == 'username':
            by_obj = Instance.user.username
        else:
            by_obj = Instance.id

        sort_by_obj = desc(by_obj) if sort == 'desc' else asc(by_obj)

        instances = instances.order_by(sort_by_obj)

        total = instances.count()
        instances = instances.slice(start, stop).all()

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        d = {'INSTANCE_LIST': instances, 'page_html': page_html}

        self.render('myun/instance/index.html', **d)
Beispiel #23
0
    def get(self):

        page_size = self.get_argument_int('sepa', 50)
        cur_page = self.get_argument_int('p', 1)
        gid = self.get_argument_int('gateway', 0)
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'ASC')

        has_ip = self.get_argument('has_ip', False)

        if by == 'created':
            by = PortMapping.created
        elif by == 'network':
            by = PortMapping.gateway_id
        else:
            by = PortMapping.id

        by_exp = desc(by) if sort == 'DESC' else asc(by)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        G = self.db.query(Gateway).get(gid) if gid else None

        binding_total = self.db.query(PortMapping.id).filter(
            PortMapping.ip != None).count()

        PORT_L = self.db.query(PortMapping)
        if G:
            PORT_L = PORT_L.filter( PortMapping.gateway_id == gid )

        if has_ip:
            PORT_L = PORT_L.filter( PortMapping.ip != None )

        TOTAL = PORT_L.count()

        PORT_L = PORT_L.order_by( by_exp )
        PORT_L = PORT_L.slice(start, stop)

        page_html = pagination(self.request.uri, TOTAL, page_size, cur_page)


        d = { 'title': _('IP Pool'), 'TOTAL': TOTAL, 'gateway': G,
              'binding_total': binding_total,
              'portmapping_list': PORT_L.all(),
              'PAGE_HTML': page_html }

        self.render('admin/network/portmapping.html', **d)
Beispiel #24
0
    def get(self):

        cur_page, page_size, start, stop = pagination(self)

        articles = self.db.query(BlogArticle).filter_by(is_public=True)

        total = articles.count()

        articles = articles.order_by(self.get_order()).slice(start, stop)

        d = dict(article_list=articles,
                 article_total=total,
                 ftime=ftime,
                 htime=htime)

        self.render('blog/index.html', **d)
Beispiel #25
0
    def get(self):

        ID = self.get_argument_int('id', None)
        if not ID:
            return self.write( _('Give me catalog id please.') )

        CATALOG = self.db.query(ForumCatalog).get(ID)
        if not CATALOG:
            return self.write( _('No such catalog %s') % ID )

        if CATALOG.is_private:
            if not CATALOG.is_visible:
                return self.write( _('Catalog is private and not visible.') )

        page_size = self.get_argument_int('ps', 20)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'created')
        order = self.get_argument_int('order', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        TOPIC_LIST = self.db.query(ForumTopic).filter(
            and_( ForumTopic.catalog_id == ID,
                  ForumTopic.status != 1 ) )

        if by not in ['id', 'created', 'updated']:
            by = 'id'

        total = TOPIC_LIST.count()

        sort_by_obj = desc(by) if order else asc(by)
        TOPIC_LIST = TOPIC_LIST.order_by(
            sort_by_obj).slice(start, stop).all()


        page_html = pagination(
            self.request.uri, total, page_size, cur_page )

        d = { 'title': _('Forum Catalog Home'),
              'can_add_topic': self.can_add_topic,
              'CATALOG': CATALOG,
              'TOPIC_LIST': TOPIC_LIST,
              'TOPIC_TOTAL': total,
              'page_html': page_html }

        self.render('forum/catalog_index.html', **d)
Beispiel #26
0
    def my_box_list(self, show="inbox"):

        UID = self.current_user.id

        page_size = self.get_argument_int('sepa', 20)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'DESC')

        if by == 'status':
            by = Message.status
        elif by == 'isread':
            by = Message.isread
        elif by == 'readtime':
            by = Message.readtime
        elif by == 'sender':
            by = Message.sender_id
        else:
            by = Message.id

        by_exp = desc(by) if sort == 'DESC' else asc(by)
        start = (cur_page - 1) * page_size
        stop = start + page_size

        if show == "inbox":
            ml = self.db.query(Message).filter_by(
                receiver_id=UID, isinbox=True)
        elif show == "outbox":
            ml = self.db.query(Message).filter_by(
                sender_id=UID, isinbox=False).filter(
                Message.receiver_id != None)
        elif show == "notice":
            ml = self.db.query(Message).filter(
                Message.receiver_id == None)
        else:
            return {}

        total = ml.count()

        ml = ml.order_by( by_exp ).slice(start, stop).all()

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        return { 'MESSAGE_LIST': ml,
                 'PAGE_HTML': page_html,
                 'TOTAL': total,
                 'SORT': sort, 'BY': by }
Beispiel #27
0
    def get(self):

        cur_page, page_size, start, stop = pagination(self)

        articles = self.db.query(BlogArticle).filter_by(
            is_public = True )

        total = articles.count()

        articles = articles.order_by(
            self.get_order() ).slice(start, stop)

        d = dict(article_list = articles,
                 article_total = total,
                 ftime = ftime)

        self.render('blog/index.html', **d)
Beispiel #28
0
    def get(self):

        ID = self.get_argument_int('id', None)
        if not ID:
            return self.write(_('Give me catalog id please.'))

        CATALOG = self.db.query(ForumCatalog).get(ID)
        if not CATALOG:
            return self.write(_('No such catalog %s') % ID)

        if CATALOG.is_private:
            if not CATALOG.is_visible:
                return self.write(_('Catalog is private and not visible.'))

        page_size = self.get_argument_int('ps', 20)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'created')
        order = self.get_argument_int('order', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        TOPIC_LIST = self.db.query(ForumTopic).filter(
            and_(ForumTopic.catalog_id == ID, ForumTopic.status != 1))

        if by not in ['id', 'created', 'updated']:
            by = 'id'

        total = TOPIC_LIST.count()

        sort_by_obj = desc(by) if order else asc(by)
        TOPIC_LIST = TOPIC_LIST.order_by(sort_by_obj).slice(start, stop).all()

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        d = {
            'title': _('Forum Catalog Home'),
            'can_add_topic': self.can_add_topic,
            'CATALOG': CATALOG,
            'TOPIC_LIST': TOPIC_LIST,
            'TOPIC_TOTAL': total,
            'page_html': page_html
        }

        self.render('forum/catalog_index.html', **d)
Beispiel #29
0
    def get_index(self):

        user_id = self.get_argument_int('user', 0)
        by = self.get_argument('by', 'id')
        order = self.get_argument_int('order', 1)

        if by not in [ 'id', 'user_id', 'status', 'target_type',
                       'target_id', 'action', 'created', 'started',
                       'ended' ]:
            by = 'id'

        order_func = desc( by ) if order else asc( by )

        page_size = self.get_argument_int('sepa', 50)
        cur_page = self.get_argument_int('p', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        JOB_LIST = self.db.query(Job)

        U = None
        if user_id:
            U = self.db.query(User).get(user_id)
            JOB_LIST = JOB_LIST.filter(Job.user_id == user_id)

        JOB_TOTAL = JOB_LIST.count()
        JOB_LIST = JOB_LIST.order_by( order_func ).slice(start, stop)

        page_html = pagination(self.request.uri, JOB_TOTAL,
                               page_size, cur_page,
                               sepa_range = [20, 50, 100])

        def sort_by(by):
            return self.urlupdate(
                {'by': by, 'order': 1 if order == 0 else 0, 'p': 1})

        d = { 'title': 'Jobs', 'U': U,
              'sort_by': sort_by,
              'JOB_TOTAL': JOB_TOTAL,
              'JOB_LIST': JOB_LIST,
              'page_html': page_html }

        self.render('admin/job/index.html', **d)
Beispiel #30
0
    def get(self):

        ID = self.get_argument_int('id', None)
        if not ID:
            return self.write(_('Give me tag id please.'))

        TAG = self.db.query(ForumTopicTag).get(ID)
        if not TAG:
            return self.write(_('No such tag %s') % ID)

        page_size = self.get_argument_int('ps', 20)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'created')
        order = self.get_argument_int('order', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        TOPICS = self.db.query(ForumTopic).filter(
            ForumTopic.tags.contains(TAG))

        if by not in ['id', 'created', 'updated']:
            by = 'id'

        total = TOPICS.count()

        sort_by_obj = desc(by) if order else asc(by)
        TOPICS = TOPICS.order_by(sort_by_obj).slice(start, stop)

        TAGS = self.db.query(ForumTopicTag).order_by(desc('hit')).limit(30)

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        d = {
            'title': _('Forum Tag Home'),
            'TAG': TAG,
            'TAGS': TAGS,
            'TOPIC_LIST': TOPICS,
            'TOPIC_TOTAL': total,
            'page_html': page_html
        }

        self.render('forum/tag/view.html', **d)
Beispiel #31
0
    def get_topics(self):

        page_size = self.get_argument_int('ps', 20)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'created')
        order = self.get_argument_int('order', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        TOPIC_LIST = self.db.query(ForumTopic).join(
            ForumTopic.catalog).filter(
            and_(ForumTopic.status != 1,
                 ForumTopic.is_visible == True,
                 ForumCatalog.is_visible == True,
                 ForumCatalog.is_private == False))

        if by == 'created':
            by = ForumTopic.created
        elif by == 'updated':
            by = ForumTopic.updated
        else:
            by = ForumTopic.id

        total = TOPIC_LIST.count()

        sort_by_obj = desc(by) if order else asc(by)

        TOPIC_LIST = TOPIC_LIST.order_by(
            sort_by_obj).slice(start, stop).all()

        page_html = pagination(
            self.request.uri, total, page_size, cur_page )

        d = { 'title': _('Forum Catalog Home'),
              'TOPIC_LIST': TOPIC_LIST,
              'TOPIC_TOTAL': total,
              'page_html': page_html }

        self.render('forum/index_topics.html', **d)
Beispiel #32
0
    def get(self):

        ID = self.get_argument_int('id', None)
        if not ID:
            return self.write( _('Give me tag id please.') )

        TAG = self.db.query(ForumTopicTag).get(ID)
        if not TAG:
            return self.write( _('No such tag %s') % ID )

        page_size = self.get_argument_int('ps', 20)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'created')
        order = self.get_argument_int('order', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        TOPICS = self.db.query(ForumTopic).filter(
            ForumTopic.tags.contains(TAG) )

        if by not in ['id', 'created', 'updated']:
            by = 'id'

        total = TOPICS.count()

        sort_by_obj = desc(by) if order else asc(by)
        TOPICS = TOPICS.order_by(sort_by_obj).slice(start, stop)

        TAGS = self.db.query(ForumTopicTag).order_by(
            desc('hit') ).limit(30)

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        d = { 'title': _('Forum Tag Home'),
              'TAG': TAG, 'TAGS': TAGS, 'TOPIC_LIST': TOPICS,
              'TOPIC_TOTAL': total, 'page_html': page_html }

        self.render('forum/tag/view.html', **d)
Beispiel #33
0
    def get(self):

        catalog_id = self.get_argument_int('c', 0)
        page_size = self.get_argument_int('sepa', 24)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'updated')
        sort = self.get_argument('sort', 'DESC')

        by_exp = desc(by) if sort == 'DESC' else asc(by)
        start = (cur_page - 1) * page_size
        stop = start + page_size

        apps = self.db.query(Appliance).filter_by(isprivate=False)

        if catalog_id:
            apps = apps.filter_by(catalog_id=catalog_id)

        total = apps.count()

        apps = apps.order_by(by_exp)
        apps = apps.slice(start, stop)
            
        catalogs = self.db.query(ApplianceCatalog).all()
        for c in catalogs:
            c.total = self.db.query(Appliance.id).filter_by(
                catalog_id = c.id ).filter_by(
                isprivate=False).count()

        page_html = pagination(self.request.uri, total,  page_size, cur_page)

        d = { 'title': self.title,
              'appliances': apps,
              'appliance_total': total,
              'catalogs': catalogs,
              'cur_catalog': catalog_id,
              'page_html': page_html }

        self.render("appliance/index.html", **d)
Beispiel #34
0
    def get(self):

        page_size = self.get_argument_int('sepa', 50)
        cur_page = self.get_argument_int('p', 1)
        nid = self.get_argument_int('network', 0)
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'ASC')

        if by == 'created':
            by = IPPool.created
        elif by == 'network':
            by = IPPool.network_id
        else:
            by = IPPool.id

        by_exp = desc(by) if sort == 'DESC' else asc(by)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        N = self.db.query(NetworkPool).get(nid) if nid else None

        TOTAL = self.db.query(IPPool.id).count()

        POOL = self.db.query(IPPool)
        if N:
            POOL = POOL.filter( IPPool.network_id == nid )

        POOL = POOL.order_by( by_exp )
        POOL = POOL.slice(start, stop)

        page_html = pagination(self.request.uri, TOTAL, page_size, cur_page)


        d = { 'title': _('IP Pool'), 'TOTAL': TOTAL, 'NETWORK': N,
              'IPPOOL': POOL.all(), 'PAGE_HTML': page_html }

        self.render('admin/network/ippool.html', **d)
Beispiel #35
0
    def get_topics(self):

        page_size = self.get_argument_int('ps', 20)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'created')
        order = self.get_argument_int('order', 1)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        TOPIC_LIST = self.db.query(ForumTopic).join(ForumTopic.catalog).filter(
            and_(ForumTopic.status != 1, ForumTopic.is_visible == True,
                 ForumCatalog.is_visible == True,
                 ForumCatalog.is_private == False))

        if by == 'created':
            by = ForumTopic.created
        elif by == 'updated':
            by = ForumTopic.updated
        else:
            by = ForumTopic.id

        total = TOPIC_LIST.count()

        sort_by_obj = desc(by) if order else asc(by)

        TOPIC_LIST = TOPIC_LIST.order_by(sort_by_obj).slice(start, stop).all()

        page_html = pagination(self.request.uri, total, page_size, cur_page)

        d = {
            'title': _('Forum Catalog Home'),
            'TOPIC_LIST': TOPIC_LIST,
            'TOPIC_TOTAL': total,
            'page_html': page_html
        }

        self.render('forum/index_topics.html', **d)
Beispiel #36
0
    def get(self):

        page_size = self.get_argument_int('sepa', 10)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'ASC')

        by_exp = desc(by) if sort == 'DESC' else asc(by)
        start = (cur_page - 1) * page_size
        stop = start + page_size

        apps = self.db.query(Appliance).filter_by(
            user_id=self.current_user.id).order_by(by_exp)

        total = apps.count()
        apps = apps.slice(start, stop)
            
        page_html = pagination(self.request.uri, total, page_size, cur_page)


        d = { 'title': self.trans(_('My Appliances')),
              'APPLIANCE_LIST': apps, 'page_html': page_html }

        self.render( 'myun/appliance/index.html', **d)
Beispiel #37
0
    def get(self):

        page_size = self.get_argument_int('sepa', USER_PS)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'id')
        order = self.get_argument_int('order', 1)
        gid = self.get_argument_int('gid', -1)
        search = self.get_argument('search', False)

        UL = self.db.query(User)

        if by == 'id':
            by_obj = User.id
        elif by == 'date_joined':
            by_obj = User.date_joined
        elif by == 'last_login':
            by_obj = User.last_login
        elif by == 'last_active':
            by_obj = User.last_active
        elif by == 'username':
            by_obj = User.username
        elif by == 'is_locked':
            by_obj = User.is_locked
        elif by == 'description':
            by_obj = User.id
            UL = UL.filter( User.description != None )
        else:
            by_obj = User.id

        by_exp = desc(by_obj) if order else asc(by_obj)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        if search:
            search = '%' + search + '%'
            UL = UL.filter( or_(User.username.like(search),
                                User.email.like(search) ) )

        GROUP = None
        if gid == 0:
            UL = UL.filter( ~User.groups.any() )
        elif gid > 0:
            GROUP = self.db.query(Group).get(gid)
            if GROUP:
                UL = UL.filter( User.groups.contains(GROUP) )

        UL = UL.order_by( by_exp )

        total = UL.count()
        UL = UL.slice(start, stop)

        page_html = pagination(self.request.uri, total,
                               page_size, cur_page,
                               sepa_range = [20, 50, 100])

        def sort_by(by):
            return self.urlupdate(
                { 'by': by, 'order': 1 if order == 0 else 0 })
            
        d = { 'title': self.trans(_('Admin User Management')),
              'sort_by': sort_by,
              'SORT_BY': by,
              'ORDER': order,
              'urlupdate': self.urlupdate,
              'USER_LIST': UL, 'PAGE_HTML': page_html,
              'TOTAL_USER': total,
              'PAGE_SIZE': page_size,
              'GROUP': GROUP, 'GID': gid,
              'GROUP_LIST': self.db.query(Group).all()}

        if self.get_argument('ajax', None):
            self.render( 'admin/user/index.ajax.html', **d )
        else:
            self.render( 'admin/user/index.html', **d )
Beispiel #38
0
    def get(self):

        page_size = self.get_argument_int('sepa', USER_PS)
        cur_page = self.get_argument_int('p', 1)
        by = self.get_argument('by', 'id')
        order = self.get_argument_int('order', 1)
        gid = self.get_argument_int('gid', -1)
        search = self.get_argument('search', False)

        UL = self.db.query(User)

        if by == 'id':
            by_obj = User.id
        elif by == 'date_joined':
            by_obj = User.date_joined
        elif by == 'last_login':
            by_obj = User.last_login
        elif by == 'last_active':
            by_obj = User.last_active
        elif by == 'username':
            by_obj = User.username
        elif by == 'is_locked':
            by_obj = User.is_locked
        elif by == 'description':
            by_obj = User.id
            UL = UL.filter(User.description != None)
        else:
            by_obj = User.id

        by_exp = desc(by_obj) if order else asc(by_obj)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        if search:
            search = '%' + search + '%'
            UL = UL.filter(
                or_(User.username.like(search), User.email.like(search)))

        GROUP = None
        if gid == 0:
            UL = UL.filter(~User.groups.any())
        elif gid > 0:
            GROUP = self.db.query(Group).get(gid)
            if GROUP:
                UL = UL.filter(User.groups.contains(GROUP))

        UL = UL.order_by(by_exp)

        total = UL.count()
        UL = UL.slice(start, stop)

        page_html = pagination(self.request.uri,
                               total,
                               page_size,
                               cur_page,
                               sepa_range=[20, 50, 100])

        def sort_by(by):
            return self.urlupdate({'by': by, 'order': 1 if order == 0 else 0})

        d = {
            'title': self.trans(_('Admin User Management')),
            'sort_by': sort_by,
            'SORT_BY': by,
            'ORDER': order,
            'urlupdate': self.urlupdate,
            'USER_LIST': UL,
            'PAGE_HTML': page_html,
            'TOTAL_USER': total,
            'PAGE_SIZE': page_size,
            'GROUP': GROUP,
            'GID': gid,
            'GROUP_LIST': self.db.query(Group).all()
        }

        if self.get_argument('ajax', None):
            self.render('admin/user/index.ajax.html', **d)
        else:
            self.render('admin/user/index.html', **d)
Beispiel #39
0
    def get(self):

        view = self.get_argument('view', 'all')
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'DESC')
        status = self.get_argument('status', 'running')
        user_group = self.get_argument_int('user_group', -1)
        page_size = self.get_argument_int('sepa', 50)
        cur_page = self.get_argument_int('p', 1)
        uid = self.get_argument_int('uid', 0) # sort by user
        aid = self.get_argument_int('aid', 0) # sort by appliance
        nid = self.get_argument_int('node', 0) # sort by node
        search = self.get_argument('search', False)

        start = (cur_page - 1) * page_size
        stop = start + page_size

        instances = self.db.query(Instance)

        # TODO: more search func
        if search:
            if len(search) > 128: # TODO
                return self.write( _('Too long search text.') )
            sid = self.get_int(search, 0)
            search = '%' + search.lower() + '%'
            if sid:
                instances = instances.filter( or_(
                        func.lower(Instance.name).like(search),
                        Instance.id.in_( [sid] ) ) )
            else:
                instances = instances.filter( or_(
                    func.lower(Instance.name).like(search),
                    ) )

        status_range = INSTANCE_HUMAN_STATUS.get(status, None)
        if status_range:
            instances = instances.filter( Instance.status.in_( status_range ) )
        else:
            instances = instances.filter( Instance.status != DELETED_S )

        U = None
        if (user_group <= 0) and uid:
            U = self.db.query(User).get( uid )
            if U:
                instances = instances.filter_by( user_id = uid )

        APPLIANCE = self.db.query(Appliance).get( aid )
        if APPLIANCE:
            instances = instances.filter_by( appliance_id = aid )

        if nid:
            NODE = self.db.query(Node).get( nid )
            if NODE:
                instances = instances.filter_by( node_id = nid )
        else:
            NODE = None

        # Group filter
        if user_group > 0:
            ug = self.db.query(Group).get(user_group)
            if ug:
                instances = instances.join(
                    Instance.user).join(User.groups).filter(
                    User.groups.contains(ug) )

        if by not in ['created', 'updated', 'node_id', 'user_id',
                      'appliance_id', 'status', 'name', 'id',
                      'tx', 'rx', 'bandwidth', 'extendsize',
                      'memory', 'cpus', 'islocked', 'isprivate',
                      'like', 'unlike', 'visit']:
            by = 'id'

        # TODO: Fix sqlalchemy column bug
        if by == 'id':
            by = Instance.id

        sort_by_obj = desc(by) if sort == 'DESC' else asc(by)

        instances = instances.order_by( sort_by_obj )

        # TODO: may have a more highly active count ( use id )
        total = instances.count()

        instances = instances.slice(start, stop).all()

        page_html = pagination(self.request.uri, total, page_size, cur_page, sepa_range=[20, 50, 100])


        d = { 'title': self.trans(_('Instance Management')),
              'human_size': human_size,
              'urlupdate': self.urlupdate,
              'SORTBY': by, 'SORT': sort,
              'INSTANCE_LIST': instances, 'TOTAL_INSTANCE': total,
              'PAGE_HTML': page_html,
              'SORT_USER': U, 'SORT_APPLIANCE': APPLIANCE,
              'SORT_NODE': NODE, 'STATUS': status,
              'USER_GROUP_ID': user_group, 'GROUP_LIST': self.db.query(Group) }

        if self.get_argument('ajax', None):
            self.render( 'admin/instance/index.ajax.html', **d )
        else:
            self.render( 'admin/instance/index.html', **d )