Ejemplo n.º 1
0
class User(SQLObject):
    username = StringCol(unique=True, notNone=True)
    country_code = StringCol(notNone=True)

    @staticmethod
    def get_user(username):
        return User.selectBy(username=username.lower()).getOne(default=None)
Ejemplo n.º 2
0
class XbmcServers(SQLObject):
    """ SQLObject class for xbmc_servers table """
    name = StringCol()
    host = StringCol()
    port = IntCol()
    username = StringCol(default=None)
    password = StringCol(default=None)
    mac = StringCol(default=None)
Ejemplo n.º 3
0
class NewznabIndexers(SQLObject):
    """ SQLObject class for NewznabIndexers table """
    name = StringCol()
    host = StringCol()
    apikey = StringCol()
    use_ssl = StringCol(default=None)
    apiurl = StringCol(default=None)

    class sqlmeta:
        fromDatabase = True
Ejemplo n.º 4
0
class KodiServers(SQLObject):
    """ SQLObject class for kodi_servers table """
    name = StringCol()
    host = StringCol()
    port = IntCol()
    username = StringCol(default=None)
    password = StringCol(default=None)
    mac = StringCol(default=None)

    class sqlmeta:
        fromDatabase = True
Ejemplo n.º 5
0
 def _notifyFinishClassCreation(cls):
     sqlmeta = cls.sqlmeta
     # verify names of added columns
     if sqlmeta.parentClass:
         # FIXME: this does not check for grandparent column overrides
         parentCols = sqlmeta.parentClass.sqlmeta.columns.keys()
         for column in sqlmeta.columnList:
             if column.name == 'childName':
                 raise AttributeError(
                     "The column name 'childName' is reserved")
             if column.name in parentCols:
                 raise AttributeError("The column '%s' is already defined "
                                      "in an inheritable parent" %
                                      column.name)
     # if this class is inheritable, add column for children distinction
     if cls._inheritable and (cls.__name__ != 'InheritableSQLObject'):
         sqlmeta.addColumn(
             StringCol(
                 name='childName',
                 # limit string length to get VARCHAR and not CLOB
                 length=255,
                 default=None))
     if not sqlmeta.columnList:
         # There are no columns - call addColumn to propagate columns
         # from parent classes to children
         sqlmeta.addColumn(None)
     if not sqlmeta.joins:
         # There are no joins - call addJoin to propagate joins
         # from parent classes to children
         sqlmeta.addJoin(None)
Ejemplo n.º 6
0
class Job(SQLObject):
    uuid = StringCol(length=36)
    name = StringCol(length=255)
    status = StringCol(length=8)
    created = DateTimeCol(default=DateTimeCol.now())
    modified = DateTimeCol(default=DateTimeCol.now())
    message = StringCol()

    def _get_name(self):
        # pylint: disable=no-member
        return str(self._SO_get_name()).strip()

    def _get_message(self):
        # pylint: disable=no-member
        return json.loads(self._SO_get_message())

    def _set_message(self, value):
        # pylint: disable=no-member
        self._SO_set_message(json.dumps(value))

    @staticmethod
    def save(record):
        """

        @param record A `dict` of the job record to store
        @return Job database record
        """
        if 'uuid' not in record:
            record['uuid'] = str(uuid.uuid4())
            record['created'] = arrow.utcnow()
            record['modified'] = arrow.utcnow()
            job = Job(**record)
        else:
            job = Job.selectBy(uuid=record['uuid']).getOne(None)

            if not job:
                raise Exception('Cannot find job record to update')

            job.pop('uuid')
            record['modified'] = arrow.utcnow()
            job.set(**record)

        return job
Ejemplo n.º 7
0
class Setting(SQLObject):
    """ Class for generating settings database table """
    key = StringCol()
    val = StringCol()
Ejemplo n.º 8
0
class Stream(SQLObject):
    user = ForeignKey('User')
    title = StringCol(notNone=True)
    url = StringCol(notNone=True)
    ended = BoolCol(default=False)
Ejemplo n.º 9
0
class Manageusers(SQLObject):
    """ SQLObject class for users table """
    username = StringCol(default=None, unique=True)
    password = StringCol(default=None)
    role = StringCol(default=None)
Ejemplo n.º 10
0
class User(SQLObject):
    class sqlmeta(object):
        table = "users"

    email = StringCol(length=255)
    password = StringCol(length=64)
    first_name = StringCol(length=255)
    last_name = StringCol(length=255)
    created = DateTimeCol(default=DateTimeCol.now())
    modified = DateTimeCol(default=DateTimeCol.now())
    archived = BoolCol(default=False)
    permissions = StringCol(default='')

    def _get_first_name(self):
        return str(self._SO_get_first_name()).strip()

    def _get_last_name(self):
        return str(self._SO_get_last_name()).strip()

    def _get_email(self):
        return str(self._SO_get_email()).strip()

    def _set_password(self, value):
        # pylint: disable=no-member
        self._SO_set_password(User.hash_password(value))

    def _get_permissions(self):
        # pylint: disable=no-member
        return self._SO_get_permissions().split(',')

    def _set_permissions(self, value):
        if isinstance(value, (tuple, list)):
            value = ','.join(value)

        self._SO_set_permissions(value)

    def set(self, _suppress_set_sig=False, **kw):
        kw['modified'] = datetime.now()
        super(User, self).set(_suppress_set_sig, **kw)

    @staticmethod
    def hash_password(password):
        """
        This creates a sha 256 hash of the password to store and use for login.

        :type password: basestring
        :param password:
        :return: str
        """
        value = hashlib.sha256()
        value.update(password)
        return value.hexdigest()

    @staticmethod
    def save(record):
        """

        :type record: dict
        :param record:
        :return:
        """
        if 'id' not in record:
            user = User(**record)
        else:
            user = User.selectBy(email=record['email']).getOne(None)
            if not user:
                # todo better exception handling here
                raise Exception('Cannot find user record to update')
            record.pop(
                'id'
            )  # todo find out how we can force id to be par of the kwargs
            user.set(**record)

        return user

    def as_json(self):
        """

        :return: dict
        """
        return {
            'id': self.id,
            'email': self.email,
            'permissions': self.permissions
        }