コード例 #1
0
ファイル: content.py プロジェクト: scottjiang1415/syndicate
   def __init__(self, api, content_filter = None, columns = None ):
      Table.__init__(self, api, Content, columns)

      db_name = "contents"
      
      sql = "SELECT %s FROM %s WHERE True" % \
         (", ".join(self.columns.keys()),db_name)

      if content_filter is not None:
         if isinstance(content_filter, (list, tuple, set)):
               # Separate the list into integers and strings
               ints = filter(lambda x: isinstance(x, (int, long)), content_filter)
               strs = filter(lambda x: isinstance(x, StringTypes), content_filter)
               content_filter = Filter(Content.fields, {'content_id': ints, 'host_url': strs})
               sql += " AND (%s) %s" % content_filter.sql(api, "OR")
         elif isinstance(content_filter, dict):
               content_filter = Filter(Content.fields, content_filter)
               sql += " AND (%s) %s" % content_filter.sql(api, "AND")
         elif isinstance (content_filter, StringTypes):
               content_filter = Filter(Content.fields, {'host_url':[content_filter]})
               sql += " AND (%s) %s" % content_filter.sql(api, "AND")
         elif isinstance (content_filter, int):
               content_filter = Filter(Content.fields, {'content_id':[content_filter]})
               sql += " AND (%s) %s" % content_filter.sql(api, "AND")
         else:
               raise MDInvalidArgument, "Wrong content filter %r"%content_filter

      self.selectall(sql)
コード例 #2
0
   def __init__(self, api, user_filter = None, columns = None ):
      Table.__init__(self, api, User, columns)

      db_name = "view_users"
      
      sql = "SELECT %s FROM %s WHERE True" % \
         (", ".join(self.columns.keys()),db_name)

      if user_filter is not None:
         if isinstance(user_filter, (list, tuple, set)):
               # Separate the list into integers and strings
               ints = filter(lambda x: isinstance(x, (int, long)), user_filter)
               strs = filter(lambda x: isinstance(x, StringTypes), user_filter)
               user_filter = Filter(User.fields, {'user_id': ints, 'username': strs})
               sql += " AND (%s) %s" % user_filter.sql(api, "OR")
         elif isinstance(user_filter, dict):
               user_filter = Filter(User.fields, user_filter)
               sql += " AND (%s) %s" % user_filter.sql(api, "AND")
         elif isinstance (user_filter, StringTypes):
               user_filter = Filter(User.fields, {'username':[user_filter]})
               sql += " AND (%s) %s" % user_filter.sql(api, "AND")
         elif isinstance (user_filter, int):
               user_filter = Filter(User.fields, {'user_id':[user_filter]})
               sql += " AND (%s) %s" % user_filter.sql(api, "AND")
         else:
               raise MDInvalidArgument, "Wrong person filter %r"%user_filter

      self.selectall(sql)
コード例 #3
0
ファイル: mdserver.py プロジェクト: scottjiang1415/syndicate
    def __init__(self, api, md_filter=None, columns=None):
        Table.__init__(self, api, MDServer, columns)

        db_name = "view_mdservers"

        sql = "SELECT %s FROM %s WHERE True" % \
           (", ".join(self.columns.keys()),db_name)

        if md_filter is not None:
            if isinstance(md_filter, (list, tuple, set)):
                # Separate the list into integers and strings
                ints = filter(lambda x: isinstance(x, (int, long)), md_filter)
                strs = filter(lambda x: isinstance(x, StringTypes), md_filter)
                md_filter = Filter(MDServer.fields, {
                    'server_id': ints,
                    'host': strs
                })
                sql += " AND (%s) %s" % md_filter.sql(api, "OR")
            elif isinstance(md_filter, dict):
                md_filter = Filter(MDServer.fields, md_filter)
                sql += " AND (%s) %s" % md_filter.sql(api, "AND")
            elif isinstance(md_filter, int):
                md_filter = Filter(MDServer.fields, {'server_id': [md_filter]})
                sql += " AND (%s) %s" % md_filter.sql(api, "AND")
            else:
                raise MDInvalidArgument, "Wrong metadata server filter %r" % md_filter

        self.selectall(sql)
コード例 #4
0
ファイル: mdserver.py プロジェクト: etherparty/syndicate
   def __init__(self, api, md_filter = None, columns = None ):
      Table.__init__(self, api, MDServer, columns)

      db_name = "view_mdservers"
      
      sql = "SELECT %s FROM %s WHERE True" % \
         (", ".join(self.columns.keys()),db_name)

      if md_filter is not None:
         if isinstance(md_filter, (list, tuple, set)):
               # Separate the list into integers and strings
               ints = filter(lambda x: isinstance(x, (int, long)), md_filter)
               strs = filter(lambda x: isinstance(x, StringTypes), md_filter)
               md_filter = Filter(MDServer.fields, {'server_id': ints, 'host': strs})
               sql += " AND (%s) %s" % md_filter.sql(api, "OR")
         elif isinstance(md_filter, dict):
               md_filter = Filter(MDServer.fields, md_filter)
               sql += " AND (%s) %s" % md_filter.sql(api, "AND")
         elif isinstance (md_filter, int):
               md_filter = Filter(MDServer.fields, {'server_id':[md_filter]})
               sql += " AND (%s) %s" % md_filter.sql(api, "AND")
         else:
               raise MDInvalidArgument, "Wrong metadata server filter %r"%md_filter

      self.selectall(sql)