本文整理汇总了Python中inpho.model.Session.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Session.commit方法的具体用法?Python Session.commit怎么用?Python Session.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inpho.model.Session
的用法示例。
在下文中一共展示了Session.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submit_changes
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def submit_changes(self):
'''
This function validates the submitted profile edit form and commits the
changes. Restricted to ``POST`` requests. If successful, redirects to
the result action to prevent resubmission.
'''
if not h.auth.is_logged_in():
abort(401)
c.user = h.get_user(request.environ['REMOTE_USER'])
if self.form_result['password'] != '':
c.user.set_password(self.form_result['password'])
# TODO: Enable area editing
#c.user.first_area_id=self.form_result['first_area'],
#user.first_area_level=self.form_result['first_area_level'],
#if self.form_result['second_area']:
# c.user.second_area_id=self.form_result['second_area'],
# c.user.second_area_level=self.form_result['second_area_level']
c.user.fullname = self.form_result['fullname']
Session.flush()
Session.commit()
h.redirect(h.url(controller='account', action='profile', message='edited'))
示例2: _reset
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def _reset(self, username=None):
username = username or request.environ.get('REMOTE_USER', False)
if not username:
abort(401)
try:
user = h.get_user(username)
except:
abort(400)
new_password = user.reset_password()
msg = Message("[email protected]", user.email,
"InPhO password reset")
msg.plain = """
%(name)s, your password at the Indiana Philosophy Ontology (InPhO) has been changed to:
Username: %(uname)s
Password: %(passwd)s
The Indiana Philosophy Ontology (InPhO) Team
[email protected]
""" % {'passwd' : new_password,
'uname' : user.username,
'name' : user.fullname or user.username or ''}
msg.send()
Session.commit()
h.redirect(h.url(controller='account', action='reset_result'))
示例3: _delete_evaluation
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def _delete_evaluation(self, evaltype, id, id2, uid=None, username=None):
if not h.auth.is_logged_in():
abort(401)
id2 = request.params.get('id2', id2)
uid = request.params.get('uid', uid)
username = request.params.get('username', username)
evaluation = self._get_evaluation(id, id2, uid, username, autoCreate=False)
if not evaluation:
abort(404)
current_uid = h.get_user(request.environ['REMOTE_USER']).ID
if evaluation.uid != current_uid or not h.auth.is_admin():
abort(401)
setattr(evaluation, evaltype, -1)
# Delete evaluation if this eliminates both settings, new db schema
# will eliminate this need
#if evaluation.generality == -1 and evaluation.relatedness == -1:
# h.delete_obj(evaluation)
Session.flush()
Session.commit()
response.status_int = 200
return "OK"
示例4: delete_obj
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [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()
Session.commit()
示例5: _delete_date
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def _delete_date(self, id, id2):
c.entity = h.fetch_obj(Entity, id, new_id=True)
# get the date object
date = self._get_date(id, id2)
if date in c.entity.dates:
idx = c.entity.dates.index(date)
Session.delete(c.entity.dates[idx])
Session.commit()
return "OK"
示例6: _delete_unary
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def _delete_unary(self, type, id, id2=None):
thinker = h.fetch_obj(Thinker, id)
id2 = request.params.get('id2', id2)
obj = h.fetch_obj(unary_vars[type]['object'], id2)
if obj in getattr(thinker, unary_vars[type]['property']):
getattr(thinker, unary_vars[type]['property']).remove(obj)
Session.commit()
response.status_int = 200
return "OK"
示例7: update
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def update(self, id=None):
terms = ['label', 'sep_dir', 'last_accessed', 'language', 'openAccess', 'active', 'student', 'ISSN']
URL = request.params.get('URL', None)
if URL is not None:
journal = h.fetch_obj(Journal, id)
if URL == 'none' or URL == 'None':
journal.URL = None
else:
journal.URL = unquote(URL)
journal.check_url()
Session.commit()
super(JournalController, self).update(id, terms)
示例8: searchpatterns
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def searchpatterns(self, id):
c.entity = h.fetch_obj(Entity, id, new_id=True)
# add a new search pattern
pattern = request.params.get("pattern", None)
if pattern is None:
abort(400)
if pattern not in c.entity.searchpatterns:
c.entity.searchpatterns.append(unicode(pattern))
Session.commit()
return "OK"
示例9: queries
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def queries(self, id):
c.entity = h.fetch_obj(Journal, id, new_id=True)
# add a new search pattern
pattern = request.params.get('pattern', None)
if pattern is None:
abort(400)
pattern = unicode(pattern)
if pattern not in c.entity.queries:
c.entity.queries.append(unicode(pattern))
Session.commit()
return "OK"
示例10: triple
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def triple(self, id):
c.entity = h.fetch_obj(Thinker, id)
#parese the triple
triple = request.params.get('triple').split()
subject_t = triple[0]
predicate_t = triple[1]
objectURLComponents = triple[2].split('/')#parse triple for last
check = "no teacher or student"
#lastComponentIndex = objectURLComponents.__len__()-1
object_t = objectURLComponents[-1]
#- subject is the same as the id
#- predicate is from the list and will be used in a if/elif/elif/elif/elif ... to see what database to add it to
if "dbpedia.org" in objectURLComponents:
object_t_label = object_t.replace("_"," ")
obj = Thinker(object_t_label)
obj.wiki = object_t
elif "inpho.cogs.indiana.edu" in objectURLComponents:
obj = h.fetch_obj(Thinker, object_t)
'''if(inpho):
obj = h.fetch_obj(Thinker, object_t) # returns the SQLAlchemy object
elif(dbpedia)
obj = Thinker(object_t) # returns the SQLAlchemy object
'''
if predicate_t == 'ns1:influenced':
c.entity.influenced.append(obj)
elif predicate_t == 'ns1:influenced_by':
c.entity.influenced_by.append(obj)
elif predicate_t =='ns1:student':
c.entity.students.append(obj)
elif predicate_t == 'ns1:teacher':
c.entity.teachers.append(obj)
'''
elif predicate == 'profession':
elif predicate == 'birth_date':
elif predicate == 'death_date':
else predicate == 'nationality':
'''
Session.commit()
subject_to_display=subject_t.split("/")[len(subject_t.split("/"))-1]
predicate_to_display=predicate_t.split(":")[1]
object_to_display=object_t
return "OK : "+subject_to_display+" "+predicate_to_display+" "+object_to_display
示例11: _delete_queries
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def _delete_queries(self, id):
c.entity = h.fetch_obj(Journal, id, new_id=True)
# add a new search pattern
pattern = request.params.get('pattern', None)
if pattern is None:
abort(400)
# rudimentary input sanitization
pattern = pattern.strip()
if pattern in c.entity.queries:
c.entity.queries.remove(pattern)
Session.commit()
return "OK"
示例12: abbrs
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def abbrs(self, id):
c.entity = h.fetch_obj(Journal, id, new_id=True)
# add a new search pattern
pattern = request.params.get('pattern', None)
if pattern is None:
abort(400)
# rudimentary input sanitization
pattern = pattern.strip()
if pattern not in c.entity.abbrs:
c.entity.abbrs.append(unicode(pattern))
Session.commit()
return "OK"
示例13: _evaluate
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def _evaluate(self, evaltype, id, id2=None, uid=None, username=None,
degree=-1, maxdegree=4, errors=0):
"""
Function to submit an evaluation. Takes a POST request containing the consequesnt id and
all or none of: generality, relatedness, hyperrank, hyporank.
"""
id2 = request.params.get('id2', id2)
uid = request.params.get('uid', uid)
try:
username = h.auth.get_username_from_cookie(request.params.get('cookieAuth', ''))
except ValueError:
# invalid IP, abort
username = None
print "grabbing eval for", username, uid
if request.environ.get('REMOTE_USER', False):
username = request.environ.get('REMOTE_USER', username)
evaluation = self._get_evaluation(id, id2, None, username)
elif username:
evaluation = self._get_evaluation(id, id2, None, username)
else:
evaluation = self._get_anon_evaluation(id, id2, request.environ.get('REMOTE_ADDR', '0.0.0.0'))
# Populate proper generality, relatedness, hyperrank and hyporank values
evaluation.time = time.time()
# Attempt to convert to integers, if unable, throw HTTP 400
try:
setattr(evaluation, evaltype,
int(request.params.get('degree', getattr(evaluation, evaltype))))
except TypeError:
abort(400)
# Create and commit evaluation
try:
Session.flush()
Session.commit()
except IntegrityError:
Session.rollback()
if not errors:
self._evaluate(evaltype, id, id2, username,
degree, maxdegree, errors+1)
# Issue an HTTP success
response.status_int = 200
return "OK"
示例14: submit
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def submit(self):
'''
This function validates the submitted registration form and creates a
new user. Restricted to ``POST`` requests. If successful, redirects to
the result action to prevent resubmission.
'''
user = User(
self.form_result['username'],
fullname=self.form_result['fullname'],
email=self.form_result['email'],
first_area_id=self.form_result['first_area'],
first_area_level=self.form_result['first_area_level'],
second_area_id=self.form_result['second_area'],
second_area_level=self.form_result['second_area_level']
)
Session.add(user)
password = user.reset_password()
Session.commit()
msg = Message("[email protected]", self.form_result['email'],
"InPhO registration")
msg.plain = """Dear %(name)s,
Thank you for registering with the Indiana Philosophy Ontology Project (InPhO).
You can sign in at https://inpho.cogs.indiana.edu/signin with the following
information:
Username: %(uname)s
Password: %(passwd)s
You may change your password at https://inpho.cogs.indiana.edu/account/edit .
The Indiana Philosophy Ontology Project (InPhO) Team
[email protected]
""" % {'passwd' : password,
'uname' : user.username,
'name' : user.fullname or user.username or ''}
msg.send()
h.redirect(h.url(controller='account', action='result'))
示例15: _delete_searchpatterns
# 需要导入模块: from inpho.model import Session [as 别名]
# 或者: from inpho.model.Session import commit [as 别名]
def _delete_searchpatterns(self, id):
c.entity = h.fetch_obj(Entity, id, new_id=True)
# add a new search pattern
pattern = request.params.get("pattern", None)
if pattern is None:
abort(400)
pattern = pattern.strip()
# Boneheaded working around bogus associationproxy in SQLAlchemy 0.6.8
# Why this isn't just c.entity.searchpatterns.remove(pattern)? who knows
for spattern in c.entity._spatterns:
if spattern.searchpattern == pattern:
Session.delete(spattern)
Session.commit()
return "OK"