本文整理汇总了Python中Model.Model.update方法的典型用法代码示例。如果您正苦于以下问题:Python Model.update方法的具体用法?Python Model.update怎么用?Python Model.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model.Model
的用法示例。
在下文中一共展示了Model.update方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import update [as 别名]
def update(self, itemid, data):
assert(self.table_name != '')
if data.has_key('imagefile') and len(data.imagefile['value']) > 10:
data['itemtype'] = self.table_name
data.Imageid = new_image_id = Image().insert(data) # set Imageid for update
Image().setItemID(new_image_id, itemid)
Model.update(self,itemid,data)
示例2: update
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import update [as 别名]
def update(self, item_id, data):
from controller import ImageConvert # 放到这里是为了避免在import model时中途import controller.* 导致import依赖
# 成为达人时同步到第三方网站, 这是逻辑代码, 但是放到这里了
old_item = self.get(item_id)
daren_title = data.get('daren_title','').encode('utf-8','ignore').strip()
if old_item and old_item.has_key('daren_title') and (old_item.daren_title.strip() != daren_title) and len(daren_title) > 0:
user = self.get(item_id)
if user and user.cover_url:
pic = ImageConvert().getSmallPortrait(user.cover_url, user.small_portrait, 150)
else:
pic = None
getController('Share').shareAll(old_item.Userid,
'【来凹凹啦, 找到最漂亮的自己】@凹凹啦 美妆前沿 我是凹凹啦美妆达人了, 我分享的美妆心得都在这里哦! 求围观, 求关注! 我的美妆主页',
url='/user/'+str(old_item.Userid), pic=pic )
# 设置用户的达人勋章
if user:
self._getDB().delete("delete from UserHasMedal where Userid = %s and Medalid in (select Medalid from Medal where name like 'daren_')", (user.Userid, ))
daren_medal_id = self._getDB().fetchFirst("select Medalid from Medal where name=%s ", ('daren_' + daren_title,))
if daren_medal_id:
self._getDB().insert('insert into UserHasMedal (Userid, Medalid ) values (%s, %s);', (user.Userid, daren_medal_id))
# 更新图片
ret = Model.update(self, item_id, data)
if data.has_key('imagefile'):
self._savePortraitImg(item_id, data.imagefile)
self._setPortraitDefault(item_id)
if data.has_key('imagefile') or data.has_key('small_portrait') or data.has_key('big_portrait'):
self._removeSmallFiles(item_id)
return ret
示例3: insert
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import update [as 别名]
def insert(self, data):
assert(self.table_name != '')
data = sh.copy(data)
img_model = sh.model('Image')
new_id = Model.insert(self, data)
if data.has_key(img_model.image_key):
img_id = img_model.insert(data)
Model.update(self, new_id, {'Imageid': img_id})
img_model.update(img_id, {'data_id': new_id, 'data_name': self.table_name})
# convert image
ignore_covert = data.get('__ignore_convert_image', False)
if self.use_convert and not ignore_covert:
self.convertImage(data, img_id)
return new_id
示例4: update
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import update [as 别名]
def update(self, item_id, data):
img_model = sh.model('Image')
if data.has_key(img_model.image_key):
if self.getImageId(item_id):
img_model.delete(self.getImageId(item_id))
img_id = img_model.insert(data)
self.update(item_id, {'Imageid': img_id})
img_model.update(img_id, {'data_id': item_id, 'data_name': self.table_name})
# convert image
ignore_covert = data.get('__ignore_convert_image', False)
if self.use_convert and not ignore_covert:
self.convertImage(data, img_id)
return Model.update(self, item_id, data)
示例5: TestModel
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import update [as 别名]
class TestModel(TestCase):
def setUp(self):
self.subject = Subject()
self.model = Model(self.subject, 4, 4, 0.5)
self.model.map = [
[1, 0, 0, 1],
[0, 0, 1, 0],
[1, 0, 1, 0],
[0, 0, 1, 1],
]
def test_map_copy(self):
backup = self.model.map_copy()
backup[0] = [0, 1, 1, 0]
self.assertEqual(self.model.map[0],
[1, 0, 0, 1], 'Should not change after update backup')
backup[0][1] = 1
self.assertEqual(self.model.map[0][1],
0, 'Should not change after update backup')
def test_count_neighbours(self):
self.assertEqual(self.model.count_neighbours(1, 1, self.model.map_copy()),
4, 'Should return the correct number of neighbours')
self.assertEqual(self.model.count_neighbours(0, 0, self.model.map_copy()),
2, 'Should return the correct number of neighbours')
def test_update(self):
self.model.update()
self.assertEqual(self.model.round, 1, 'Should go to next round')
self.assertEqual(self.model.map, [
[1, 1, 0, 0],
[1, 0, 1, 0],
[0, 0, 1, 0],
[0, 0, 1, 0],
], 'Should update map correctly')