本文整理汇总了Python中anitya.app.SESSION.add方法的典型用法代码示例。如果您正苦于以下问题:Python SESSION.add方法的具体用法?Python SESSION.add怎么用?Python SESSION.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anitya.app.SESSION
的用法示例。
在下文中一共展示了SESSION.add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_project_version
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import add [as 别名]
def delete_project_version(project_id, version):
project = anitya.lib.model.Project.get(SESSION, project_id)
if not project:
flask.abort(404)
version_obj = None
for vers in project.versions_obj:
if version == vers.version:
version_obj = vers
break
if version_obj is None:
flask.abort(
404,
'Version %s not found for project %s' % (version, project.name)
)
if not is_admin():
flask.abort(401)
form = anitya.forms.ConfirmationForm()
confirm = flask.request.form.get('confirm', False)
if form.validate_on_submit():
if confirm:
anitya.log(
SESSION,
project=project,
topic='project.version.remove',
message=dict(
agent=flask.g.auth.openid,
project=project.name,
version=version,
)
)
# Delete the record of the version for this project
SESSION.delete(version_obj)
# Adjust the latest_version if needed
if project.latest_version == version:
project.latest_version = None
SESSION.add(project)
SESSION.commit()
flask.flash('Version for %s has been removed' % version)
return flask.redirect(
flask.url_for('project', project_id=project.id))
return flask.render_template(
'version_delete.html',
current='projects',
project=project,
version=version,
form=form)
示例2: edit_distro
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import add [as 别名]
def edit_distro(distro_name):
distro = anitya.lib.model.Distro.by_name(SESSION, distro_name)
if not distro:
flask.abort(404)
if not is_admin():
flask.abort(401)
form = anitya.forms.DistroForm(obj=distro)
if form.validate_on_submit():
name = form.name.data
if name != distro.name:
anitya.log(
SESSION,
distro=distro,
topic='distro.edit',
message=dict(
agent=flask.g.auth.openid,
old=distro.name,
new=name,
)
)
distro.name = name
SESSION.add(distro)
SESSION.commit()
message = 'Distribution edited'
flask.flash(message)
return flask.redirect(
flask.url_for('distros')
)
return flask.render_template(
'distro_edit.html',
current='distros',
distro=distro,
form=form)
示例3: add_distro
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import add [as 别名]
def add_distro():
if not is_admin():
flask.abort(401)
form = anitya.forms.DistroForm()
if form.validate_on_submit():
name = form.name.data
distro = anitya.lib.model.Distro(name)
anitya.log(
SESSION,
distro=distro,
topic='distro.add',
message=dict(
agent=flask.g.auth.openid,
distro=distro.name,
)
)
try:
SESSION.add(distro)
SESSION.commit()
flask.flash('Distribution added')
except SQLAlchemyError as err:
flask.flash(
'Could not add this distro, already exists?', 'error')
return flask.redirect(
flask.url_for('distros')
)
return flask.render_template(
'distro_add.html',
current='distros',
form=form)