Exemplo n.º 1
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)
Exemplo n.º 2
0
    def get(self):

        catalog_id = self.get_argument_int('c', 1)
        page_size = self.get_argument_int('sepa', 20)
        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.db2.query(Appliance).filter_by(
            catalog_id=catalog_id).filter_by(
            isprivate=False).order_by(by_exp)

        total = apps.count()
        apps = apps.slice(start, stop)
            
        catalogs = self.db2.query(ApplianceCatalog).all()
        for c in catalogs:
            c.total = self.db2.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,
              'catalogs': catalogs,
              'cur_catalog': catalog_id,
              'page_html': page_html }

        self.render("appliance/index.html", **d)
Exemplo n.º 3
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 )
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def get(self):

        catalog_id = self.get_argument_int('c', 1)
        page_size = self.get_argument_int('sepa', 20)
        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.db2.query(Appliance).filter_by(
            catalog_id=catalog_id).filter_by(isprivate=False).order_by(by_exp)

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

        catalogs = self.db2.query(ApplianceCatalog).all()
        for c in catalogs:
            c.total = self.db2.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,
            'catalogs': catalogs,
            'cur_catalog': catalog_id,
            'page_html': page_html
        }

        self.render("appliance/index.html", **d)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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.db2.query(LyTrace)

        if user_id:
            user = self.db2.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.db2.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 )
Exemplo n.º 10
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 )
Exemplo n.º 11
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)
Exemplo n.º 12
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.db2.query(Message).filter_by(receiver_id=UID,
                                                   isinbox=True)
        elif show == "outbox":
            ml = self.db2.query(Message).filter_by(
                sender_id=UID,
                isinbox=False).filter(Message.receiver_id != None)
        elif show == "notice":
            ml = self.db2.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
        }
Exemplo n.º 13
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)
Exemplo n.º 14
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.db2.query(Message).filter_by(
                receiver_id=UID, isinbox=True)
        elif show == "outbox":
            ml = self.db2.query(Message).filter_by(
                sender_id=UID, isinbox=False).filter(
                Message.receiver_id != None)
        elif show == "notice":
            ml = self.db2.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 }
Exemplo n.º 15
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)
Exemplo n.º 16
0
    def get_index(self):

        catalog_id = self.catalog.id if self.catalog else 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)

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

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

        apps = self.db2.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.db2.query(ApplianceCatalog).all()
        for c in catalogs:
            c.total = self.db2.query(Appliance.id).filter_by( catalog_id = c.id ).count()

        d = { 'title': self.trans(_('LuoYun Appliance Management')),
              'CATALOG_LIST': catalogs, 'CID': catalog_id,
              '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 )
Exemplo n.º 17
0
    def page_view_instances(self, app):

        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.db2.query(Instance).filter(
            Instance.isprivate != True ).filter(
            Instance.status.in_( slist) ).filter(
            Instance.appliance_id == app.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)

        return instances, page_html
Exemplo n.º 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)
Exemplo n.º 19
0
    def page_view_instances(self, app):

        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.db2.query(Instance).filter(
            Instance.isprivate != True).filter(
                Instance.status.in_(slist)).filter(
                    Instance.appliance_id == app.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)

        return instances, page_html
Exemplo n.º 20
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.db2.query(Job)

        U = None
        if user_id:
            U = self.db2.query(User).get(user_id)
            JOB_LIST = JOB_LIST.filter(Job.user_id == user_id)
        JOB_LIST = JOB_LIST.order_by( order_func ).slice(start, stop)

        JOB_TOTAL = self.db2.query(Job.id).count()

        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)
Exemplo n.º 21
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.db2.query(NetworkPool).get(nid) if nid else None

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

        POOL = self.db2.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': self.trans(_('IP Pool')),
            'TOTAL': TOTAL,
            'NETWORK': N,
            'IPPOOL': POOL.all(),
            'PAGE_HTML': page_html
        }

        self.render('system/ippool.html', **d)
Exemplo n.º 22
0
    def page_view_my_appliances(self):

        #catalog_id = self.get_argument_int('c', 1)
        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.db2.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)

        return apps, page_html
Exemplo n.º 23
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)
Exemplo n.º 24
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)
Exemplo n.º 25
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.db2.query(NetworkPool).get(nid) if nid else None

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

        POOL = self.db2.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': self.trans(_('IP Pool')), 'TOTAL': TOTAL, 'NETWORK': N,
              'IPPOOL': POOL.all(), 'PAGE_HTML': page_html }

        self.render('system/ippool.html', **d)
Exemplo n.º 26
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)
Exemplo n.º 27
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_int('status', -1)
        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),
                    ) )

        if status not in [k for k,v in INSTANCE_STATUS_SHORT_STR]:
            status = -1

        if status == -1:
            instances = instances.filter(
                Instance.status != DELETED_S )
        else:
            instances = instances.filter(Instance.status==status)

        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'

        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,
              'INSTANCE_STATUS': INSTANCE_STATUS_SHORT_STR,
              '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 )
Exemplo n.º 28
0
    def get_index(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.db2.query(User)

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

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

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

        if search:
            search = '%' + search + '%'
            PL = self.db2.query(UserProfile).filter(
                UserProfile.email.like(search))
            user_ids = [ x.user_id for x in PL ]
            UL = UL.filter( or_(User.username.like(search),
                                User.id.in_( user_ids ) ) )

        GROUP = None
        if gid == 0:
            UL = UL.filter( ~User.groups.any() )
        elif gid > 0:
            GROUP = self.db2.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,
              'urlupdate': self.urlupdate,
              'USER_LIST': UL, 'PAGE_HTML': page_html,
              'TOTAL_USER': total,
              'PAGE_SIZE': page_size,
              'GROUP': GROUP, 'GID': gid,
              'GROUP_LIST': self.db2.query(Group).all()}

        if self.get_argument('ajax', None):
            self.render( 'admin/user/index.ajax', **d )
        else:
            self.render( 'admin/user/index.html', **d )
Exemplo n.º 29
0
    def get_index(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.db2.query(User)

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

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

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

        if search:
            search = '%' + search + '%'
            PL = self.db2.query(UserProfile).filter(
                UserProfile.email.like(search))
            user_ids = [x.user_id for x in PL]
            UL = UL.filter(
                or_(User.username.like(search), User.id.in_(user_ids)))

        GROUP = None
        if gid == 0:
            UL = UL.filter(~User.groups.any())
        elif gid > 0:
            GROUP = self.db2.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,
            'urlupdate': self.urlupdate,
            'USER_LIST': UL,
            'PAGE_HTML': page_html,
            'TOTAL_USER': total,
            'PAGE_SIZE': page_size,
            'GROUP': GROUP,
            'GID': gid,
            'GROUP_LIST': self.db2.query(Group).all()
        }

        if self.get_argument('ajax', None):
            self.render('admin/user/index.ajax', **d)
        else:
            self.render('admin/user/index.html', **d)
Exemplo n.º 30
0
    def get(self):

        # TODO: a temp hack for status sync
        self.db2.commit()

        # TODO:
        #self.set_secure_cookie('session_key', session_key)
        instance_sort = self.get_secure_cookie('instance_sort')
        instance_sort = '?view=all'

        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.db2.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
        }

        # TODO: save user sort method
        self.set_secure_cookie('instance_sort', instance_sort)

        self.render("instance/index.html", **d)
Exemplo n.º 31
0
    def get(self):

        view = self.get_argument("view", "all")
        by = self.get_argument("by", "id")
        order = self.get_argument_int("order", 1)
        status = self.get_argument_int("status", -1)
        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)))

        if status not in [k for k, v in INSTANCE_STATUS_SHORT_STR]:
            status = -1

        if status == -1:
            instances = instances.filter(Instance.status != DELETED_S)
        else:
            instances = instances.filter(Instance.status == status)

        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 == "created":
            by_obj = Instance.created
        elif by == "updated":
            by_obj = Instance.updated
        elif by == "node":
            by_obj = Instance.node_id
        elif by == "user":
            by_obj = Instance.user_id
        elif by == "appliance":
            by_obj = Instance.appliance_id
        elif by == "status":
            by_obj = Instance.status
        elif by == "name":
            by_obj = Instance.name
        else:
            by_obj = Instance.id

        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).all()

        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, "p": "dropthis"})

        d = {
            "title": self.trans(_("Instance Management")),
            "urlupdate": self.urlupdate,
            "sort_by": sort_by,
            "SORTBY": by,
            "ORDER": order,
            "INSTANCE_LIST": instances,
            "TOTAL_INSTANCE": total,
            "PAGE_HTML": page_html,
            "SORT_USER": U,
            "SORT_APPLIANCE": APPLIANCE,
            "SORT_NODE": NODE,
            "STATUS": status,
            "INSTANCE_STATUS": INSTANCE_STATUS_SHORT_STR,
            "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)
Exemplo n.º 32
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.db2.query(LyTrace)

        if user_id:
            user = self.db2.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.db2.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)
Exemplo n.º 33
0
    def get_index(self):

        view = self.get_argument('view', 'all')
        by = self.get_argument('by', 'id')
        order = self.get_argument_int('order', 1)
        status = self.get_argument_int('status', -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

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

        instances = self.db2.query(Instance)

        if status not in [k for k, v in INSTANCE_STATUS_SHORT_STR]:
            status = -1

        if status == -1:
            instances = instances.filter(Instance.status != DELETED_S)
        else:
            instances = instances.filter(Instance.status == status)

        U = self.db2.query(User).get(uid)
        if U:
            instances = instances.filter_by(user_id=uid)

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

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

        if by == 'created':
            by_obj = Instance.created
        elif by == 'updated':
            by_obj = Instance.updated
        elif by == 'node':
            by_obj = Instance.node_id
        elif by == 'user':
            by_obj = Instance.user_id
        elif by == 'appliance':
            by_obj = Instance.appliance_id
        elif by == 'status':
            by_obj = Instance.status
        elif by == 'name':
            by_obj = Instance.name
        else:
            by_obj = Instance.id

        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).all()

        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,
                'p': 1
            })

        d = {
            'title': self.trans(_('Instance Management')),
            'urlupdate': self.urlupdate,
            'sort_by': sort_by,
            'INSTANCE_LIST': instances,
            'TOTAL_INSTANCE': total,
            'PAGE_HTML': page_html,
            'SORT_USER': U,
            'SORT_APPLIANCE': APPLIANCE,
            'SORT_NODE': NODE,
            'STATUS': status,
            'INSTANCE_STATUS': INSTANCE_STATUS_SHORT_STR
        }

        self.render('admin/instance/index.html', **d)
Exemplo n.º 34
0
    def get_index(self):

        view = self.get_argument('view', 'all')
        by = self.get_argument('by', 'id')
        order = self.get_argument_int('order', 1)
        status = self.get_argument_int('status', -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

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

        instances = self.db2.query(Instance)

        if status not in [k for k,v in INSTANCE_STATUS_SHORT_STR]:
            status = -1

        if status == -1:
            instances = instances.filter(
                Instance.status != DELETED_S )
        else:
            instances = instances.filter(Instance.status==status)

        U = self.db2.query(User).get( uid )
        if U:
            instances = instances.filter_by( user_id = uid )

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

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

        if by == 'created':
            by_obj = Instance.created
        elif by == 'updated':
            by_obj = Instance.updated
        elif by == 'node':
            by_obj = Instance.node_id
        elif by == 'user':
            by_obj = Instance.user_id
        elif by == 'appliance':
            by_obj = Instance.appliance_id
        elif by == 'status':
            by_obj = Instance.status
        elif by == 'name':
            by_obj = Instance.name
        else:
            by_obj = Instance.id


        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).all()

        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, 'p': 1})

        d = { 'title': self.trans(_('Instance Management')),
              'urlupdate': self.urlupdate,
              'sort_by': sort_by,
              'INSTANCE_LIST': instances, 'TOTAL_INSTANCE': total,
              'PAGE_HTML': page_html,
              'SORT_USER': U, 'SORT_APPLIANCE': APPLIANCE,
              'SORT_NODE': NODE, 'STATUS': status,
              'INSTANCE_STATUS': INSTANCE_STATUS_SHORT_STR }

        self.render( 'admin/instance/index.html', **d )