本文整理汇总了Python中anitya.app.SESSION.commit方法的典型用法代码示例。如果您正苦于以下问题:Python SESSION.commit方法的具体用法?Python SESSION.commit怎么用?Python SESSION.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anitya.app.SESSION
的用法示例。
在下文中一共展示了SESSION.commit方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_distro
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import commit [as 别名]
def delete_distro(distro_name):
""" Delete a distro """
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.ConfirmationForm()
if form.validate_on_submit():
anitya.log(
SESSION,
distro=distro,
topic='distro.remove',
message=dict(
agent=flask.g.auth.openid,
distro=distro.name,
)
)
SESSION.delete(distro)
SESSION.commit()
flask.flash('Distro %s has been removed' % distro_name)
return flask.redirect(flask.url_for('distros'))
return flask.render_template(
'distro_delete.html',
current='distros',
distro=distro,
form=form)
示例2: map_project
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import commit [as 别名]
def map_project(project_id):
project = anitya.lib.model.Project.get(SESSION, project_id)
if not project:
flask.abort(404)
form = anitya.forms.MappingForm()
if form.validate_on_submit():
try:
anitya.lib.map_project(
SESSION,
project=project,
package_name=form.package_name.data,
distribution=form.distro.data,
user_mail=flask.g.auth.email,
)
SESSION.commit()
flask.flash('Mapping added')
except anitya.lib.exceptions.AnityaException as err:
flask.flash(str(err), 'error')
return flask.redirect(
flask.url_for('project', project_id=project.id)
)
return flask.render_template(
'mapping.html',
current='projects',
project=project,
form=form,
)
示例3: new_project
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import commit [as 别名]
def new_project():
plugins = anitya.lib.plugins.load_plugins(SESSION)
plg_names = [plugin.name for plugin in plugins]
form = anitya.forms.ProjectForm(backends=plg_names)
if flask.request.method == 'GET':
form.name.data = flask.request.args.get('name', '')
form.homepage.data = flask.request.args.get('homepage', '')
form.backend.data = flask.request.args.get('backend', '')
form.distro.data = flask.request.args.get('distro', '')
form.package_name.data = flask.request.args.get('package_name', '')
if form.validate_on_submit():
project = None
try:
project = anitya.lib.create_project(
SESSION,
name=form.name.data.strip(),
homepage=form.homepage.data.strip(),
backend=form.backend.data.strip(),
version_url=form.version_url.data.strip() or None,
version_prefix=form.version_prefix.data.strip() or None,
regex=form.regex.data.strip() or None,
user_id=flask.g.auth.openid,
check_release=form.check_release.data,
)
SESSION.commit()
# Optionally, the user can also map a distro when creating a proj.
if form.distro.data and form.package_name.data:
anitya.lib.map_project(
SESSION,
project=project,
package_name=form.package_name.data,
distribution=form.distro.data,
user_id=flask.g.auth.openid,
)
SESSION.commit()
flask.flash('Project created')
except anitya.lib.exceptions.AnityaException as err:
flask.flash(err)
if project:
return flask.redirect(
flask.url_for('project', project_id=project.id)
)
return flask.render_template(
'project_new.html',
context='Add',
current='Add projects',
form=form,
plugins=plugins,
)
示例4: delete_project_version
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import commit [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)
示例5: delete_project_mapping
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import commit [as 别名]
def delete_project_mapping(project_id, distro_name, pkg_name):
project = anitya.lib.model.Project.get(SESSION, project_id)
if not project:
flask.abort(404)
distro = anitya.lib.model.Distro.get(SESSION, distro_name)
if not distro:
flask.abort(404)
package = anitya.lib.model.Packages.get(
SESSION, project.id, distro.name, pkg_name)
if not package:
flask.abort(404)
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.map.remove',
message=dict(
agent=flask.g.auth.openid,
project=project.name,
distro=distro.name,
)
)
SESSION.delete(package)
SESSION.commit()
flask.flash('Mapping for %s has been removed' % project.name)
return flask.redirect(
flask.url_for('project', project_id=project.id))
return flask.render_template(
'regex_delete.html',
current='projects',
project=project,
package=package,
form=form)
示例6: edit_project_mapping
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import commit [as 别名]
def edit_project_mapping(project_id, pkg_id):
project = anitya.lib.model.Project.get(SESSION, project_id)
if not project:
flask.abort(404)
package = anitya.lib.model.Packages.by_id(SESSION, pkg_id)
if not package:
flask.abort(404)
form = anitya.forms.MappingForm(obj=package)
if form.validate_on_submit():
try:
anitya.lib.map_project(
SESSION,
project=project,
package_name=form.package_name.data,
distribution=form.distro.data,
user_id=flask.g.auth.openid,
old_package_name=package.package_name,
old_distro_name=package.distro,
)
SESSION.commit()
flask.flash('Mapping edited')
except anitya.lib.exceptions.AnityaInvalidMappingException as err:
err.link = flask.url_for('project', project_id=err.project_id)
flask.flash(err.message, 'error')
except anitya.lib.exceptions.AnityaException as err:
flask.flash(str(err), 'error')
return flask.redirect(
flask.url_for('project', project_id=project_id))
return flask.render_template(
'mapping.html',
current='projects',
project=project,
package=package,
form=form,
)
示例7: delete_project
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import commit [as 别名]
def delete_project(project_id):
project = anitya.lib.model.Project.get(SESSION, project_id)
if not project:
flask.abort(404)
if not is_admin():
flask.abort(401)
project_name = project.name
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.remove',
message=dict(
agent=flask.g.auth.openid,
project=project.name,
)
)
for version in project.versions_obj:
SESSION.delete(version)
SESSION.delete(project)
SESSION.commit()
flask.flash('Project %s has been removed' % project_name)
return flask.redirect(flask.url_for('projects'))
else:
return flask.redirect(
flask.url_for('project', project_id=project.id))
return flask.render_template(
'project_delete.html',
current='projects',
project=project,
form=form)
示例8: edit_distro
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import commit [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)
示例9: map_project
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import commit [as 别名]
def map_project(project_id):
project = anitya.lib.model.Project.get(SESSION, project_id)
if not project:
flask.abort(404)
form = anitya.forms.MappingForm()
if flask.request.method == 'GET':
form.package_name.data = flask.request.args.get(
'package_name', project.name)
form.distro.data = flask.request.args.get('distro', '')
if form.validate_on_submit():
try:
anitya.lib.map_project(
SESSION,
project=project,
package_name=form.package_name.data.strip(),
distribution=form.distro.data.strip(),
user_id=flask.g.auth.openid,
)
SESSION.commit()
flask.flash('Mapping added')
except anitya.lib.exceptions.AnityaInvalidMappingException as err:
err.link = flask.url_for('project', project_id=err.project_id)
flask.flash(err.message, 'error')
except anitya.lib.exceptions.AnityaException as err:
flask.flash(str(err), 'error')
return flask.redirect(
flask.url_for('project', project_id=project.id)
)
return flask.render_template(
'mapping.html',
current='projects',
project=project,
form=form,
)
示例10: add_distro
# 需要导入模块: from anitya.app import SESSION [as 别名]
# 或者: from anitya.app.SESSION import commit [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)