Exemple #1
0
 def default_category(cls):
     category = DBCategory.get_by_url("")
     if not category:
         category = DBCategory.create(url="", name="Home")
         category.save()
         _ = category.stats  # init stats
     return cls(category)
Exemple #2
0
 def default_category(cls):
     category = DBCategory.get_by_url("")
     if not category:
         category = DBCategory.create(url="", name="Home")
         category.save()
         _ = category.stats  # init stats
     return cls(category)
Exemple #3
0
    def update(self, **settings):
        url = settings.get("url", None)
        if url is not None:
            url = Category.norm_url(url)
            category = DBCategory.get_by_url(url)
            if category and category.id != self.id:
                raise Exception("url '%s' exist" % url)
            settings["url"] = url

        self.db_object.update(**settings)
Exemple #4
0
    def update(self, **settings):
        url = settings.get("url", None)
        if url is not None:
            url = Category.norm_url(url)
            category = DBCategory.get_by_url(url)
            if category and category.id != self.id:
                raise Exception("url '%s' exist" % url)
            settings["url"] = url

        self.db_object.update(**settings)
Exemple #5
0
 def create_category(cls, **settings):
     url = cls.norm_url(settings.pop("url"))
     name = settings.pop("name")
     if cls.check_exist(url=url):
         raise Exception("category %s exist" % url)
     dbcategory = DBCategory.create(url=url, name=name)
     dbcategory.save()
     _ = dbcategory.stats  # init stats
     dbcategory.update(**settings)
     return cls(dbcategory)
Exemple #6
0
 def create_category(cls, **settings):
     url = cls.norm_url(settings.pop("url"))
     name = settings.pop("name")
     if cls.check_exist(url=url):
         raise Exception("category %s exist" % url)
     dbcategory = DBCategory.create(url=url, name=name)
     dbcategory.save()
     _ = dbcategory.stats  # init stats
     dbcategory.update(**settings)
     return cls(dbcategory)
Exemple #7
0
 def check_exist(cls, **kwargs):
     return DBCategory.check_exist(**kwargs)
Exemple #8
0
 def get_by_url(cls, category_url):
     if not category_url:
         return cls.default_category()
     category_url = cls.norm_url(category_url)
     dbcategory = DBCategory.get_by_url(category_url)
     return dbcategory and cls(dbcategory)
Exemple #9
0
 def get_by_id(cls, id):
     dbcategory = DBCategory.get_by_id(id)
     return dbcategory and cls(dbcategory)
Exemple #10
0
 def check_exist(cls, **kwargs):
     return DBCategory.check_exist(**kwargs)
Exemple #11
0
 def get_by_url(cls, category_url):
     if not category_url:
         return cls.default_category()
     category_url = cls.norm_url(category_url)
     dbcategory = DBCategory.get_by_url(category_url)
     return dbcategory and cls(dbcategory)
Exemple #12
0
 def get_by_id(cls, id):
     dbcategory = DBCategory.get_by_id(id)
     return dbcategory and cls(dbcategory)