Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(13)  |  Call(13)  |  Derive(0)  |  Import(0)

src/z/a/zarkpy-HEAD/web/cgi/modeldecorator/Category.py   zarkpy(Download)
    def addNewCategory(self, name):
        exists = self._getExistsCategory(name)
        assert exists is None, '插入了重复的分类: %s %s' % (self._getModelTableName(), name)
        return self.__insertCategory(name)
 
    def getAllCategory(self):
        return [c.name for c in self.__getCatModel().all({'where': ['data_name=%s', self._getModelTableName()]})]
 
    # 判断model是否已有莫个分类
    def hasCategory(self, name):
    def setCategory(self, item_id, name):
        exists = self._getExistsCategory(name)
        assert exists is not None, '分类不存在: %s %s' % (self._getModelTableName(), name)
        return self.model.update(item_id, {self.arguments.cat_id_key: exists.id})
 
    def __insertCategory(self, name):
        return self.__getCatModel().insert(dict( data_name = self._getModelTableName(), name = name ))
 
    def _getExistsCategory(self, name):
        assert(isinstance(name, (str, unicode)) and len(name.strip()) > 0)
        return self.__getCatModel().getOneByWhere('data_name=%s and name=%s', self._getModelTableName(), name.strip())

src/z/a/zarkpy-HEAD/web/cgi/modeldecorator/Private.py   zarkpy(Download)
    def _setPrivateidToData(self, data):
        uk = self.arguments.user_id_key
        pk = self.arguments.primary_key
        assert not data.has_key(pk), u'你确定你要自己控制%s的值?' % pk
        data[pk] = sh.model('Private').getNextPrivateid(self._getModelTableName(), data[uk])
 
    def _incPrivateid(self, data):
        uk = self.arguments.user_id_key
        sh.model('Private').incPrivateid(self._getModelTableName(), data[uk])

src/z/a/zarkpy-HEAD/web/cgi/modeldecorator/Tag.py   zarkpy(Download)
    def getTags(self, item_id):
        return [t.name for t in self.__getTagModel().all({'where': ['data_name=%s and data_id=%s', self._getModelTableName(), item_id]})]
 
    # 判断某个数据是否有某个tag
    def hasTag(self, item_id, tag):
        tag_model = self.__getTagModel()
        query = tag_model.replaceAttr('select data_id from {$table_name} where data_name=%s and name=%s')
        item_ids = tag_model.db.fetchSomeFirst(query, [self._getModelTableName(), tag])
        items = self.model.gets(item_ids)
        self.__setTags(items)
    def __clearTags(self, item_id):
        tag_model = self.__getTagModel()
        query = tag_model.replaceAttr('delete from {$table_name} where data_name=%s and data_id=%s')
        return tag_model.db.delete(query, [self._getModelTableName(), item_id])
 
    def __getExistsTag(self, item_id, tag):
        tag = sh.unicodeToStr(tag)
        assert(isinstance(tag, str) and len(tag.strip()) > 0)
        return self.__getTagModel().getOneByWhere('data_name=%s and data_id=%s and name=%s', self._getModelTableName(), item_id, tag.strip())
 
    def __insertTag(self, item_id, tag):
        return self.__getTagModel().insert(dict( data_name = self._getModelTableName(), data_id = item_id, name = tag ))