示例#1
0
class KMBlogArticle(adapter.Model):
    __tablename__ = 'km_blog_article'
    id = adapter.Column(adapter.Integer, autoincrement=True, primary_key=True)
    info_id = adapter.Column(adapter.Integer)
    category_id = adapter.Column(adapter.Integer)
    title = adapter.Column(adapter.Text)
    article = adapter.Column(adapter.Text)
    post_date = adapter.Column(adapter.DateTime)

    def __init__(self, data=None):
        if data is None:
            self.title = ""
            self.article = ""
            self.post_date = datetime.datetime.now()
        else:
            self.set_data(data)

    def __repr__(self):
        return create_repr_str(self)

    def get_json(self):
        return create_json(self)


    def set_data(self, data):
        self.error = None
        self.info_id = data.get_request_parameter('info_id')
        self.category_id = data.get_request_parameter('category_id')
        self.title = data.get_request_parameter('title', default='', decode=True)
        self.article = data.get_request_parameter('article', default='', decode=True)


    def validate(self):
        self.error = KMValidateError()
        if self.title == '':
            self.error.add_data(id='title', message='記事名は必須です。')
        if self.error.size() == 0:
            return True
        else:
            return False

    @classmethod
    def get(self, id):
        if id is None:
            info = KMBlogArticle()
        else:
            info = super(KMBlogArticle, self).get(id=id)
        return info

    @classmethod
    def save_data(self, id, data):
        if id is None:
            article = KMBlogArticle(data)
        else:
            article = KMBlogArticle.get(id=id)
            article.set_data(data)
        if article.validate():
            article.save()
        return article
示例#2
0
class KMBlogInfo(adapter.Model):
    __tablename__ = 'km_blog_info'
    id = adapter.Column(adapter.Integer, autoincrement=True, primary_key=True)
    name = adapter.Column(adapter.Text)
    url = adapter.Column(adapter.Text)
    description = adapter.Column(adapter.Text)

    def __init__(self, data=None):
        if data is None:
            self.name = ''
            self.url = ''
            self.description = ''
        else:
            self.set_data(data)

    def __repr__(self):
        return create_repr_str(self)

    def get_json(self):
        return create_json(self)

    def set_data(self, data):
        self.error = None
        self.name = data.get_request_parameter('name', default='', decode=True)
        self.url = data.get_request_parameter('url', default='')
        self.description = data.get_request_parameter('description',
                                                      default='',
                                                      decode=True)

    def validate(self):
        self.error = KMValidateError()
        if self.name == '':
            self.error.add_data(id='name', message='ブログ名は必須です。')
        if self.url == '':
            self.error.add_data(id='url', message='URLは必須です。')
        if self.error.size() == 0:
            return True
        else:
            return False

    @classmethod
    def get(cls, id):
        if id is None:
            info = KMBlogInfo()
        else:
            info = super(KMBlogInfo, cls).get(id=id)
        return info

    @classmethod
    def save_data(cls, id, data):
        if id is None:
            info = KMBlogInfo(data)
        else:
            info = KMBlogInfo.get(id=id)
            info.set_data(data)
        if info.validate():
            info.save()
        return info
示例#3
0
class KMBlogInfo(adapter.Model):
    __tablename__ = 'km_blog_info'
    id = adapter.Column(adapter.Integer, autoincrement=True, primary_key=True)
    name = adapter.Column(adapter.Text)
    url = adapter.Column(adapter.Text)
    description = adapter.Column(adapter.Text)

    def __init__(self, data=None):
        if data is None:
            self.name = ''
            self.url = ''
            self.description = ''
        else:
            self.set_data(data)

    def __repr__(self):
        return create_repr_str(self)

    def get_json(self):
        return create_json(self)


    def set_data(self, data):
        self.error = None
        self.name = data.get_request_parameter('name', default='')
        self.url = data.get_request_parameter('url', default='')
        self.description = data.get_request_parameter('description', default='')

    def validate(self):
        self.error = KMValidateError()
        if self.name == '':
            self.error.add_data(id='name', message='ブログ名は必須です。')
        if self.url == '':
            self.error.add_data(id='url', message='URLは必須です。')
        if self.error.size() == 0:
            return True
        else:
            return False

    @classmethod
    def get(cls, id):
        if id is None:
            info = KMBlogInfo()
        else:
            info = super(KMBlogInfo, cls).get(id=id)
        return info

    @classmethod
    def save_data(cls, id, data):
        if id is None:
            info = KMBlogInfo(data)
        else:
            info = KMBlogInfo.get(id=id)
            info.set_data(data)
        if info.validate():
            info.save()
        return info
示例#4
0
class KMBlogArticle(adapter.Model):
    __tablename__ = "km_blog_article"
    id = adapter.Column(adapter.Integer, autoincrement=True, primary_key=True)
    info_id = adapter.Column(adapter.Integer)
    category_id = adapter.Column(adapter.Integer)
    title = adapter.Column(adapter.Text)
    article = adapter.Column(adapter.Text)
    post_date = adapter.Column(adapter.DateTime)

    def __init__(self, data=None):
        if data is None:
            self.title = ""
            self.article = ""
            self.post_date = datetime.datetime.now()
        else:
            self.set_data(data)

    def __repr__(self):
        return create_repr_str(self)

    def get_json(self):
        return create_json(self)

    def set_data(self, data):
        self.error = None
        self.info_id = data.get_request_parameter("info_id")
        self.category_id = data.get_request_parameter("category_id")
        self.title = data.get_request_parameter("title", default="", decode=True)
        self.article = data.get_request_parameter("article", default="", decode=True)

    def validate(self):
        self.error = KMValidateError()
        if self.title == "":
            self.error.add_data(id="title", message="記事名は必須です。")
        if self.error.size() == 0:
            return True
        else:
            return False

    @classmethod
    def get(self, id):
        if id is None:
            info = KMBlogArticle()
        else:
            info = super(KMBlogArticle, self).get(id=id)
        return info

    @classmethod
    def save_data(self, id, data):
        if id is None:
            article = KMBlogArticle(data)
        else:
            article = KMBlogArticle.get(id=id)
            article.set_data(data)
        if article.validate():
            article.save()
        return article
示例#5
0
class KMBlogCategory(adapter.Model):
    __tablename__ = 'km_blog_category'
    id = adapter.Column(adapter.Integer, autoincrement=True, primary_key=True)
    info_id = adapter.Column(adapter.Integer)
    name = adapter.Column(adapter.Text)

    def __init__(self, data=None):
        if data is None:
            self.name = ''
        else:
            self.set_data(data)

    def __repr__(self):
        return create_repr_str(self)

    def get_json(self):
        return create_json(self)


    def set_data(self, data):
        self.error = None
        self.name = data.get_request_parameter('name', default='')
        self.info_id = data.get_request_parameter('info_id', default=None)


    def validate(self):
        self.error = KMValidateError()
        if self.name == '':
            self.error.add_data(id='name', message='カテゴリ名は必須です。')
        if self.error.size() == 0:
            return True
        else:
            return False

    @classmethod
    def get(self, id):
        if id is None:
            info = KMBlogCategory()
        else:
            info = super(KMBlogCategory, self).get(id=id)
        return info

    @classmethod
    def save_data(self, id, data):
        if id is None:
            category = KMBlogCategory(data)
        else:
            category = KMBlogCategory.get(id=id)
            category.set_data(data)
        if category.validate():
            category.save()
        return category
class KMBlogCategory(adapter.Model):
    __tablename__ = 'km_blog_category'
    id = adapter.Column(adapter.Integer, autoincrement=True, primary_key=True)
    info_id = adapter.Column(adapter.Integer)
    name = adapter.Column(adapter.Text)

    def __init__(self, data=None):
        if data is None:
            self.name = ''
        else:
            self.set_data(data)

    def __repr__(self):
        return create_repr_str(self)

    def get_json(self):
        return create_json(self)

    def set_data(self, data):
        self.error = None
        self.name = data.get_request_parameter('name', default='', decode=True)
        self.info_id = data.get_request_parameter('info_id', default=None)

    def validate(self):
        self.error = KMValidateError()
        if self.name == '':
            self.error.add_data(id='name', message='カテゴリ名は必須です。')
        if self.error.size() == 0:
            return True
        else:
            return False

    @classmethod
    def get(self, id):
        if id is None:
            info = KMBlogCategory()
        else:
            info = super(KMBlogCategory, self).get(id=id)
        return info

    @classmethod
    def save_data(self, id, data):
        if id is None:
            category = KMBlogCategory(data)
        else:
            category = KMBlogCategory.get(id=id)
            category.set_data(data)
        if category.validate():
            category.save()
        return category
class KMBlogSubscription(adapter.Model):
    __tablename__ = 'km_blog_subscription'
    id = adapter.Column(adapter.Integer, autoincrement=True, primary_key=True)
    user_id = adapter.Column(adapter.Integer)
    target_id = adapter.Column(adapter.Integer)

    def __init__(self, data=None):
        if data is None:
            self.name = ''
            self.url = ''
            self.description = ''
        else:
            self.set_data(data)

    def __repr__(self):
        return create_repr_str(self)

    def get_json(self):
        return create_json(self)

    def set_data(self, data):
        self.error = None
        self.name = data.get_request_parameter('name', default='', decode=True)
        self.url = data.get_request_parameter('url', default='')
        self.description = data.get_request_parameter('description',
                                                      default='',
                                                      decode=True)

    def validate(self):
        self.error = KMValidateError()
        if self.name == '':
            self.error.add_data(id='name', message='ブログ名は必須です。')
        if self.url == '':
            self.error.add_data(id='url', message='URLは必須です。')
        if self.error.size() == 0:
            return True
        else:
            return False
示例#8
0
class KMBlogSubscription(adapter.Model):
    __tablename__ = 'km_blog_subscription'
    id = adapter.Column(adapter.Integer, autoincrement=True, primary_key=True)
    user_id = adapter.Column(adapter.Integer)
    target_id = adapter.Column(adapter.Integer)

    def __init__(self, data=None):
        if data is None:
            self.name = ''
            self.url = ''
            self.description = ''
        else:
            self.set_data(data)

    def __repr__(self):
        return create_repr_str(self)

    def get_json(self):
        return create_json(self)


    def set_data(self, data):
        self.error = None
        self.name = data.get_request_parameter('name', default='')
        self.url = data.get_request_parameter('url', default='')
        self.description = data.get_request_parameter('description', default='')

    def validate(self):
        self.error = KMValidateError()
        if self.name == '':
            self.error.add_data(id='name', message='ブログ名は必須です。')
        if self.url == '':
            self.error.add_data(id='url', message='URLは必須です。')
        if self.error.size() == 0:
            return True
        else:
            return False