本文整理汇总了Python中invenio.modules.deposit.models.Deposition.get方法的典型用法代码示例。如果您正苦于以下问题:Python Deposition.get方法的具体用法?Python Deposition.get怎么用?Python Deposition.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类invenio.modules.deposit.models.Deposition
的用法示例。
在下文中一共展示了Deposition.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create
# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import get [as 别名]
def test_create(self):
from invenio.ext.login.legacy_user import UserInfo
from invenio.modules.deposit.models import Deposition
user = UserInfo(uid=1)
d = Deposition.create(user)
assert d.type == self.DefaultType
assert Deposition.get(d.id).type == self.DefaultType
d = Deposition.create(user, type=self.AnotherType)
assert d.type == self.AnotherType
assert Deposition.get(d.id).type == self.AnotherType
示例2: run_deposition_tasks
# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import get [as 别名]
def run_deposition_tasks(self, deposition_id, with_webcoll=True):
"""
Run all task ids specified in the latest SIP and optionally run
webcoll.
"""
# Run submitted tasks
from invenio.modules.deposit.models import Deposition
dep = Deposition.get(deposition_id)
sip = dep.get_latest_sip(sealed=True)
for task_id in sip.task_ids:
self.run_task_id(task_id)
if with_webcoll:
# Run webcoll (to ensure record is assigned permissions)
from invenio.legacy.bibsched.bibtask import \
task_low_level_submission
task_id = task_low_level_submission('webcoll', 'webdeposit', '-q')
self.run_task_id(task_id)
# Check if record is accessible
response = self.client.get(
url_for('record.metadata', recid=sip.metadata['recid']),
base_url=self.app.config['CFG_SITE_SECURE_URL'],
)
self.assertStatus(response, 200)
示例3: post
# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import get [as 别名]
def post(self, oauth, resource_id):
""" Upload a file """
d = Deposition.get(resource_id, user=current_user)
# Bail-out early if not permitted (add_file will also check, but then
# we already uploaded the file)
if not d.authorize('add_file'):
raise ForbiddenAction('add_file', d)
uploaded_file = request.files['file']
filename = secure_filename(
request.form.get('filename') or uploaded_file.filename
)
df = DepositionFile(backend=DepositionStorage(d.id))
if df.save(uploaded_file, filename=filename):
try:
d.add_file(df)
d.save()
except FilenameAlreadyExists as e:
df.delete()
raise e
return d.type.marshal_file(df), 201
示例4: get
# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import get [as 别名]
def get(self, oauth, resource_id, file_id):
""" Get a deposition file """
d = Deposition.get(resource_id, user=current_user)
df = d.get_file(file_id)
if df is None:
abort(404, message="File does not exist", status=404)
return d.type.marshal_file(df)
示例5: put
# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import get [as 别名]
def put(self, resource_id, file_id):
"""Update a deposition file - i.e. rename it."""
v = APIValidator()
if not v.validate(request.json, file_schema):
abort(
400,
message="Bad request",
status=400,
errors=map(lambda x: dict(message=x, code=error_codes["validation_error"]), v.errors),
)
d = Deposition.get(resource_id, user=current_user)
df = d.get_file(file_id)
if not d.type.authorize_file(d, df, "update_metadata"):
raise ForbiddenAction("update_metadata", df)
new_name = secure_filename(request.json["filename"])
if new_name != request.json["filename"]:
abort(
400,
message="Bad request",
status=400,
errors=[dict(message="Not a valid filename", code=error_codes["validation_error"])],
)
df.name = new_name
d.save()
return d.type.marshal_file(df)
示例6: put
# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import get [as 别名]
def put(self, oauth, resource_id):
""" Update a deposition """
d = Deposition.get(resource_id, user=current_user)
self.validate_input(d)
self.process_input(d)
d.save()
return d.marshal()
示例7: test_create
# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import get [as 别名]
def test_create(self):
"""Test."""
from invenio.ext.login.legacy_user import UserInfo
from invenio.modules.deposit.models import Deposition
user = UserInfo(uid=1)
d = Deposition.create(user)
assert d.type == self.DefaultType
assert Deposition.get(d.id).type == self.DefaultType
d2 = Deposition.create(user, type=self.AnotherType)
assert d2.type == self.AnotherType
assert Deposition.get(d2.id).type == self.AnotherType
# remove the records
Deposition.delete(d)
Deposition.delete(d2)
示例8: delete
# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import get [as 别名]
def delete(self, oauth, resource_id, file_id):
""" Delete existing deposition file """
d = Deposition.get(resource_id, user=current_user)
# Sort files raise ForbiddenAction if not authorized
df = d.remove_file(file_id)
if df is None:
abort(404, message="File does not exist", status=404)
df.delete()
d.save()
return "", 204
示例9: deposition_with_files
# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import get [as 别名]
def deposition_with_files(files, user_id=None, deposition_id=None):
"""Add very big files to a deposition."""
if deposition_id:
d = Deposition.get(deposition_id)
else:
d = Deposition.create(User.query.get(user_id))
for filepath in files:
with open(filepath, "rb") as fileobj:
filename = os.path.basename(filepath)
df = DepositionFile(backend=DepositionStorage(d.id))
df.save(fileobj, filename=filename)
d.add_file(df)
return d
示例10: deposition_users
# 需要导入模块: from invenio.modules.deposit.models import Deposition [as 别名]
# 或者: from invenio.modules.deposit.models.Deposition import get [as 别名]
def deposition_users(depositions):
"""Iterate over deposition users."""
for d in depositions:
yield Deposition.get(d).user_id