Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 7
0
 def check_exist(cls, **kwargs):
     return DBCategory.check_exist(**kwargs)
Exemplo n.º 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)
Exemplo n.º 9
0
 def get_by_id(cls, id):
     dbcategory = DBCategory.get_by_id(id)
     return dbcategory and cls(dbcategory)
Exemplo n.º 10
0
 def check_exist(cls, **kwargs):
     return DBCategory.check_exist(**kwargs)
Exemplo n.º 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)
Exemplo n.º 12
0
 def get_by_id(cls, id):
     dbcategory = DBCategory.get_by_id(id)
     return dbcategory and cls(dbcategory)