本文整理汇总了Python中inphosite.model.meta.Session.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Session.delete方法的具体用法?Python Session.delete怎么用?Python Session.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inphosite.model.meta.Session
的用法示例。
在下文中一共展示了Session.delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_obj
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import delete [as 别名]
def delete_obj(obj):
"""
Deletes any arbitrary object from the SQLAlchemy Session and cascades deletes to evaluations.
:param obj: object to delete
"""
Session.delete(obj)
Session.flush()
示例2: getentries
# 需要导入模块: from inphosite.model.meta import Session [as 别名]
# 或者: from inphosite.model.meta.Session import delete [as 别名]
def getentries(db_dir):
#to do feb 10: do something more elegant than just delete existing and rewrite...perhaps only write new?
#first, clear out the current table
#Session.query(SEPEntry).delete()
#Session.flush()
#Session.commit()
entries = defaultdict(lambda: {'title' : '', 'published' : False, 'status' : ''})
pars = HTMLParser.HTMLParser()
#get published entries
published = open('/Users/inpho/SitesOld/dev/entries-published.txt')
status = open(os.path.join(db_dir , 'entrystatus.txt'))
entrylist = open(os.path.join(db_dir, 'entries.txt'))
#set up entries dict
for line in entrylist:
line = line.split('::')
sep_dir = pars.unescape(re.sub('<(/)?[a-zA-Z]*>', '', line[0]))
title = re.sub("\\\\\'", "'", pars.unescape(re.sub('<(/)?[a-zA-Z]*>', '', line[1])))
entries[sep_dir]['title'] = title
for line in published:
line = re.sub('\\n', '', line)
if entries[line]['title']:
entries[line]['published'] = True
else:
print "uh-oh, " + line + "doesn't appear to be in dict object"
for line in status:
line = line.split('::')
if entries[line[0]]['title']:
entries[line[0]]['status'] = line[1]
#print "status = " + line[1] + ' for ' + line[0]
else:
print "uh-oh, " + line[0] + "doesn't appear to be in dict object"
for key in entries.keys():
#so, what I should really do here is figure out whether the entry already has a place in the table; if so, update its existing stats; if not,
#insert a new one;
#also need to check if old entries in sepentries table are no longer in file...
entry_q = Session.query(SEPEntry)
o = SEPEntry.title.like(entries[key]['title'])
entry_q = entry_q.filter(o)
# if only 1 result, go ahead and view that idea
if entry_q.count() == 0:
entry_add = SEPEntry(entries[key]['title'], key, entries[key]['published'], entries[key]['status'])
Session.add(entry_add)
elif entry_q.count() == 1:
#replace data from most recent from SEPMirror
entry = entry_q.first()
entry.title = entries[key]['title']
entry.published = entries[key]['published']
entry.status = entries[key]['status']
#need to really add something here to delete entries no longer in the DB...
entry_q2 = Session.query(SEPEntry)
for entry in entry_q2:
if not entries[entry.sep_dir]['title']:
print str(entry.title) + " appears to have been deleted from SEPMirror; deleting from InPhO database."
Session.delete(entry)
Session.flush()
Session.commit()