Пример #1
0
    def get(self):

        catalog_id = int( self.get_argument('c', 1) )
        page_size = int( self.get_argument('sepa', 10) )
        cur_page = int( self.get_argument('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).order_by(by_exp).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 ).count()

        pagination = Pagination(
            total = self.db2.query(Appliance.id).count(),
            page_size = page_size, cur_page = cur_page )

        page_html = pagination.html( self.get_page_url )

        d = { 'title': "Appliance Home",
              'appliances': apps,
              'catalogs': catalogs,
              'cur_catalog': catalog_id,
              'page_html': page_html }

        self.render("appliance/index.html", **d)
Пример #2
0
    def page_view_my_appliances(self):

        catalog_id = int( self.get_argument('c', 1) )
        page_size = int( self.get_argument('sepa', 10) )
        cur_page = int( self.get_argument('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(
            catalog_id=catalog_id).filter_by(
            user_id=self.current_user.id).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 ).count()

        pagination = Pagination(
            total = total, page_size = page_size, cur_page = cur_page )

        page_html = pagination.html( self.get_page_url )

        return apps, page_html
Пример #3
0
    def get_index(self):

        page_size = int( self.get_argument('sepa', USER_PS) )
        cur_page = int( self.get_argument('p', 1) )
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'DESC')
        gid = int(self.get_argument('gid', -1))
        online = self.get_argument('online', False)

        if by == 'date_joined':
            by = User.date_joined
        elif by == 'last_login':
            by = User.last_login
        else:
            by = User.id

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

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

        UL = self.db2.query(User)

        if online:
            # TODO
            try:
                online = int(online)
            except:
                online = settings.USER_ACTIVE_MIN
            deadline = datetime.datetime.utcnow() - datetime.timedelta(seconds = online)
            UL = UL.filter( User.last_active > deadline )

        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)

        pagination = Pagination(
            total = total, page_size = page_size,
            cur_page = cur_page )

        page_html = pagination.html( self.get_page_url )
            

        d = { 'title': _('Admin User Management'),
              'USER_LIST': UL, 'PAGE_HTML': page_html,
              'TOTAL_USER': total,
              'GROUP': GROUP, 'GID': gid, 'ONLINE': online }

        self.render( 'admin/user/index.html', **d )
Пример #4
0
    def get_index(self):

        catalog_id = self.catalog.id if self.catalog else 0
        page_size = int(self.get_argument('sepa', 10))
        cur_page = int(self.get_argument('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)

        pagination = Pagination(total=total,
                                page_size=page_size,
                                cur_page=cur_page)

        page_html = pagination.html(self.get_page_url)

        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': _('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
        }

        self.render('admin/appliance/index.html', **d)
Пример #5
0
    def get_index(self):

        by = self.get_argument('by', 'id')
        order = self.get_argument('order', 'DESC')
        if (order == 'DESC'):
            order_func = desc(by)
        else:
            order_func = asc(by)

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

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

        JOB_LIST = self.db2.query(Job).order_by(order_func)
        JOB_LIST = JOB_LIST.slice(start, stop)

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

        page_html = Pagination(total=JOB_TOTAL,
                               page_size=page_size,
                               cur_page=cur_page).html(self.get_page_url)

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

        self.render('admin/job/index.html', **d)
Пример #6
0
    def get_index(self):

        catalog_id = self.catalog.id if self.catalog else 0
        page_size = int( self.get_argument('sepa', 10) )
        cur_page = int( self.get_argument('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)
            
        pagination = Pagination(
            total = total,
            page_size = page_size, cur_page = cur_page )

        page_html = pagination.html( self.get_page_url )

        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': _('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 }

        self.render( 'admin/appliance/index.html', **d )
Пример #7
0
    def get_index(self):

        page_size = int( self.get_argument('sepa', USER_PS) )
        cur_page = int( self.get_argument('p', 1) )
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'DESC')
        gid = (self.get_argument('gid', 0))


        if by == 'date_joined':
            by = User.date_joined
        elif by == 'last_login':
            by = User.last_login
        else:
            by = User.id

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

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

        UL = self.db2.query(User)

        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)

        pagination = Pagination(
            total = total, page_size = page_size,
            cur_page = cur_page )

        page_html = pagination.html( self.get_page_url )
            

        d = { 'title': _('Admin User Management'),
              'USER_LIST': UL, 'PAGE_HTML': page_html,
              'TOTAL_USER': total,
              'GROUP': GROUP }

        self.render( 'admin/user/index.html', **d )
Пример #8
0
    def get(self):

        catalog_id = int( self.get_argument('c', 1) )
        page_size = int( self.get_argument('sepa', 10) )
        cur_page = int( self.get_argument('p', 1) )
        by = self.get_argument('by', 'updated')
        sort = self.get_argument('sort', 'DESC')

        # TODO: no SQL-injection
        if not ( sort in ['DESC', 'ASC'] and
                 by  in ['updated', 'created'] ):
            return self.write(u'wrong URL !')

        SQL = "\
SELECT id, name, summary, user_id, catalog_id, logoname, \
       filesize, is_useable, popularity, created, updated \
FROM appliance \
WHERE catalog_id=%s \
ORDER BY %s %s \
LIMIT %s OFFSET %s;" % ( catalog_id, by, sort, page_size, (cur_page - 1) * page_size )

        apps = self.db.query(SQL)

        catalogs = self.db.query( '\
SELECT id, name, position FROM appliance_catalog \
ORDER BY position;' )

        total = len( self.db.query('\
SELECT id FROM appliance WHERE catalog_id=%s;', catalog_id) )
        pagination = Pagination( total = total,
                                 page_size = page_size,
                                 cur_page = cur_page )

        page_html = pagination.html(self.get_page_url)

        d = { 'title': "Appliance Home",
              'appliances': apps,
              'catalogs': catalogs,
              'cur_catalog': catalog_id,
              'page_html': page_html }

        self.render("appliance/index.html", **d)
Пример #9
0
    def page_view_my_instances(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 = int(self.get_argument(
                'sepa', settings.MYUN_INSTANCE_LIST_PAGE_SIZE))
        cur_page = int(self.get_argument('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.db2.query(Instance).filter(
                Instance.status.in_( slist) ).filter_by(
                user_id = self.current_user.id )
        else:
            instances = self.db2.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()

        if total > page_size:
            page_html = Pagination(
                total = total,
                page_size = page_size,
                cur_page = cur_page ).html(self.get_page_url)
        else:
            page_html = ""

        return instances, page_html
Пример #10
0
    def get(self):

        catalog_id = int(self.get_argument('c', 1))
        page_size = int(self.get_argument('sepa', 10))
        cur_page = int(self.get_argument('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()

        pagination = Pagination(total=total,
                                page_size=page_size,
                                cur_page=cur_page)

        page_html = pagination.html(self.get_page_url)

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

        self.render("appliance/index.html", **d)
Пример #11
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 = int(
            self.get_argument('sepa',
                              settings.APPLIANCE_INSTANCE_LIST_PAGE_SIZE))
        cur_page = int(self.get_argument('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()

        if total > page_size:
            page_html = Pagination(total=total,
                                   page_size=page_size,
                                   cur_page=cur_page).html(self.get_page_url)
        else:
            page_html = ""

        return instances, page_html
Пример #12
0
    def get_index(self):

        page_size = int(self.get_argument('sepa', USER_PS))
        cur_page = int(self.get_argument('p', 1))
        by = self.get_argument('by', 'id')
        sort = self.get_argument('sort', 'DESC')
        gid = int(self.get_argument('gid', -1))
        online = self.get_argument('online', False)

        if by == 'date_joined':
            by = User.date_joined
        elif by == 'last_login':
            by = User.last_login
        else:
            by = User.id

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

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

        UL = self.db2.query(User)

        if online:
            # TODO
            try:
                online = int(online)
            except:
                online = settings.USER_ACTIVE_MIN
            deadline = datetime.datetime.utcnow() - datetime.timedelta(
                seconds=online)
            UL = UL.filter(User.last_active > deadline)

        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)

        pagination = Pagination(total=total,
                                page_size=page_size,
                                cur_page=cur_page)

        page_html = pagination.html(self.get_page_url)

        d = {
            'title': _('Admin User Management'),
            'USER_LIST': UL,
            'PAGE_HTML': page_html,
            'TOTAL_USER': total,
            'GROUP': GROUP,
            'GID': gid,
            'ONLINE': online
        }

        self.render('admin/user/index.html', **d)
Пример #13
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')
        sort = self.get_argument('sort', 'desc')
        status = self.get_argument('status', 'running')
        page_size = int(self.get_argument(
                'sepa', settings.INSTANCE_HOME_PAGE_SIZE))
        cur_page = int(self.get_argument('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) )

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

        #by_obj = Instance.created if by == 'created' else Instance.updated
        if by == 'created':
            by_obj = Instance.created
        # TODO: sorted by username
        #elif by == 'username':
        #    by_obj = Instance.user.username
        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 )

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

        instances = instances.slice(start, stop)

        if total > page_size:
            page_html = Pagination(
                total = total,
                page_size = page_size,
                cur_page = cur_page ).html(self.get_page_url)
        else:
            page_html = ""

        d = { 'title': self.title,
              'INSTANCE_LIST': instances,
              'cur_page': cur_page,
              'page_html': page_html }

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

        self.render("instance/index.html", **d)
Пример #14
0
    def get_index(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 = int(self.get_argument('sepa', 30))
        cur_page = int(self.get_argument('p', 1))
        uid = int(self.get_argument('uid', 0)) # sort by user
        aid = int(self.get_argument('aid', 0)) # sort by appliance

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

        instances = self.db2.query(Instance)

        if status != 'all':
            if status == 'stoped':
                slist = settings.INSTANCE_SLIST_STOPED
            else: # show running
                slist = settings.INSTANCE_SLIST_RUNING
            instances = instances.filter(Instance.status.in_( slist))

        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 by == 'created':
            by_obj = Instance.created
        elif by == 'updated':
            by_obj = Instance.updated
        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 )

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

        instances = instances.slice(start, stop)

        if total > page_size:
            page_html = Pagination(
                total = total,
                page_size = page_size,
                cur_page = cur_page ).html(self.get_page_url)
        else:
            page_html = ""

        d = { 'title': _('Instance Management'),
              'INSTANCE_LIST': instances, 'TOTAL_INSTANCE': total,
              'PAGE_HTML': page_html,
              'SORT_USER': U, 'SORT_APPLIANCE': APPLIANCE }

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