Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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 )
Exemplo n.º 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)
Exemplo n.º 5
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 )
Exemplo n.º 6
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 )
Exemplo n.º 7
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)
Exemplo n.º 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')

        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)
Exemplo n.º 9
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)