本文整理汇总了Python中website.project.model.has_anonymous_link函数的典型用法代码示例。如果您正苦于以下问题:Python has_anonymous_link函数的具体用法?Python has_anonymous_link怎么用?Python has_anonymous_link使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了has_anonymous_link函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_node_contributors_abbrev
def get_node_contributors_abbrev(auth, node, **kwargs):
anonymous = has_anonymous_link(node, auth)
formatter = "surname"
max_count = kwargs.get("max_count", 3)
if "user_ids" in kwargs:
users = [User.load(user_id) for user_id in kwargs["user_ids"] if user_id in node.visible_contributor_ids]
else:
users = node.visible_contributors
if anonymous or not node.can_view(auth):
raise HTTPError(http.FORBIDDEN)
contributors = []
n_contributors = len(users)
others_count = ""
for index, user in enumerate(users[:max_count]):
if index == max_count - 1 and len(users) > max_count:
separator = " &"
others_count = str(n_contributors - 3)
elif index == len(users) - 1:
separator = ""
elif index == len(users) - 2:
separator = " &"
else:
separator = ","
contributor = user.get_summary(formatter)
contributor["user_id"] = user._primary_key
contributor["separator"] = separator
contributors.append(contributor)
return {"contributors": contributors, "others_count": others_count}
示例2: _get_summary
def _get_summary(node, auth, rescale_ratio, primary=True, link_id=None, show_path=False):
# TODO(sloria): Refactor this or remove (lots of duplication with _view_project)
summary = {
'id': link_id if link_id else node._id,
'primary': primary,
'is_registration': node.is_registration,
'is_fork': node.is_fork,
'is_pending_registration': node.is_pending_registration,
'is_retracted': node.is_retracted,
'is_pending_retraction': node.is_pending_retraction,
'embargo_end_date': node.embargo_end_date.strftime("%A, %b. %d, %Y") if node.embargo_end_date else False,
'is_pending_embargo': node.is_pending_embargo,
'archiving': node.archiving,
}
if node.can_view(auth):
summary.update({
'can_view': True,
'can_edit': node.can_edit(auth),
'primary_id': node._id,
'url': node.url,
'primary': primary,
'api_url': node.api_url,
'title': node.title,
'category': node.category,
'node_type': node.project_or_component,
'is_fork': node.is_fork,
'is_registration': node.is_registration,
'anonymous': has_anonymous_link(node, auth),
'registered_date': node.registered_date.strftime('%Y-%m-%d %H:%M UTC')
if node.is_registration
else None,
'forked_date': node.forked_date.strftime('%Y-%m-%d %H:%M UTC')
if node.is_fork
else None,
'nlogs': None,
'ua_count': None,
'ua': None,
'non_ua': None,
'addons_enabled': node.get_addon_names(),
'is_public': node.is_public,
'parent_title': node.parent_node.title if node.parent_node else None,
'parent_is_public': node.parent_node.is_public if node.parent_node else False,
'show_path': show_path
})
if rescale_ratio:
ua_count, ua, non_ua = _get_user_activity(node, auth, rescale_ratio)
summary.update({
'nlogs': len(node.logs),
'ua_count': ua_count,
'ua': ua,
'non_ua': non_ua,
})
else:
summary['can_view'] = False
# TODO: Make output format consistent with _view_project
return {
'summary': summary,
}
示例3: get_contributors
def get_contributors(auth, node, **kwargs):
# Can set limit to only receive a specified number of contributors in a call to this route
if request.args.get('limit'):
try:
limit = int(request.args['limit'])
except ValueError:
raise HTTPError(http.BAD_REQUEST, data=dict(
message_long='Invalid value for "limit": {}'.format(request.args['limit'])
))
else:
limit = None
anonymous = has_anonymous_link(node, auth)
if anonymous or not node.can_view(auth):
raise HTTPError(http.FORBIDDEN)
# Limit is either an int or None:
# if int, contribs list is sliced to specified length
# if None, contribs list is not sliced
contribs = profile_utils.serialize_contributors(
node.visible_contributors[0:limit],
node=node,
)
# Will either return just contributor list or contributor list + 'more' element
if limit:
return {
'contributors': contribs,
'more': max(0, len(node.visible_contributors) - limit)
}
else:
return {'contributors': contribs}
示例4: _get_logs
def _get_logs(node, count, auth, link=None, page=0):
"""
:param Node node:
:param int count:
:param auth:
:return list: List of serialized logs,
boolean: if there are more logs
"""
logs = []
total = 0
for log in reversed(node.logs):
# A number of errors due to database inconsistency can arise here. The
# log can be None; its `node__logged` back-ref can be empty, and the
# 0th logged node can be None. Need to make sure that log is not None
if log:
log_node = log.resolve_node(node)
if log.can_view(node, auth):
total += 1
anonymous = has_anonymous_link(log_node, auth)
logs.append(serialize_log(log, anonymous))
else:
logger.warn('Log on node {} is None'.format(node._id))
paginated_logs, pages = paginate(logs, total, page, count)
return list(paginated_logs), total, pages
示例5: node_register_template_page
def node_register_template_page(auth, node, metaschema_id, **kwargs):
if node.is_registration and bool(node.registered_schema):
try:
meta_schema = RegistrationSchema.objects.get(_id=metaschema_id)
except RegistrationSchema.DoesNotExist:
# backwards compatability for old urls, lookup by name
meta_schema = RegistrationSchema.objects.filter(name=_id_to_name(metaschema_id)).order_by('-schema_version').first()
if not meta_schema:
raise HTTPError(http.NOT_FOUND, data={
'message_short': 'Invalid schema name',
'message_long': 'No registration schema with that name could be found.'
})
if not node.registered_schema.filter(id=meta_schema.id).exists():
raise HTTPError(http.BAD_REQUEST, data={
'message_short': 'Invalid schema',
'message_long': 'This registration has no registration supplment with that name.'
})
ret = _view_project(node, auth, primary=True)
my_meta = serialize_meta_schema(meta_schema)
if has_anonymous_link(node, auth):
for indx, schema_page in enumerate(my_meta['schema']['pages']):
for idx, schema_question in enumerate(schema_page['questions']):
if schema_question['title'] in settings.ANONYMIZED_TITLES:
del my_meta['schema']['pages'][indx]['questions'][idx]
ret['node']['registered_schema'] = serialize_meta_schema(meta_schema)
return ret
else:
status.push_status_message(
'You have been redirected to the project\'s registrations page. From here you can initiate a new Draft Registration to complete the registration process',
trust=False,
id='redirected_to_registrations',
)
return redirect(node.web_url_for('node_registrations', view=kwargs.get('template'), _guid=True))
示例6: _get_logs
def _get_logs(node, count, auth, link=None, offset=0):
"""
:param Node node:
:param int count:
:param auth:
:return list: List of serialized logs,
boolean: if there are more logs
"""
logs = []
has_more_logs = False
for log in (x for idx, x in enumerate(reversed(node.logs)) if idx >= offset):
# A number of errors due to database inconsistency can arise here. The
# log can be None; its `node__logged` back-ref can be empty, and the
# 0th logged node can be None. Catch and log these errors and ignore
# the offending logs.
log_node = log.resolve_node(node)
if log.can_view(node, auth):
anonymous = has_anonymous_link(log_node, auth)
if len(logs) < count:
logs.append(serialize_log(log, anonymous))
else:
has_more_logs = True
break
return logs, has_more_logs
示例7: osf_storage_get_revisions
def osf_storage_get_revisions(payload, node_addon, **kwargs):
node = node_addon.owner
page = payload.get('page') or 0
path = payload.get('path')
is_anon = has_anonymous_link(node, Auth(private_key=payload.get('view_only')))
if not path:
raise HTTPError(httplib.BAD_REQUEST)
try:
page = int(page)
except (TypeError, ValueError):
raise HTTPError(httplib.BAD_REQUEST)
record = model.OsfStorageFileRecord.find_by_path(path, node_addon)
if record is None:
raise HTTPError(httplib.NOT_FOUND)
indices, versions, more = record.get_versions(
page,
size=osf_storage_settings.REVISIONS_PAGE_SIZE,
)
return {
'revisions': [
utils.serialize_revision(node, record, versions[idx], indices[idx], anon=is_anon)
for idx in range(len(versions))
],
'more': more,
}
示例8: dataverse_get_file_info
def dataverse_get_file_info(node_addon, auth, **kwargs):
"""API view that gets info for a file."""
node = node_addon.owner
file_id = kwargs.get('path')
fail_if_unauthorized(node_addon, auth, file_id)
fail_if_private(file_id)
anonymous = has_anonymous_link(node, auth)
download_url = node.web_url_for('dataverse_download_file', path=file_id)
dataverse_url = 'http://{0}/dvn/dv/'.format(HOST) + node_addon.dataverse_alias
study_url = 'http://dx.doi.org/' + node_addon.study_hdl
delete_url = node.api_url_for('dataverse_delete_file', path=file_id)
data = {
'node': {
'id': node._id,
'title': node.title
},
'filename': scrape_dataverse(file_id, name_only=True)[0],
'dataverse': privacy_info_handle(node_addon.dataverse, anonymous),
'study': privacy_info_handle(node_addon.study, anonymous),
'urls': {
'dataverse': privacy_info_handle(dataverse_url, anonymous),
'study': privacy_info_handle(study_url, anonymous),
'download': privacy_info_handle(download_url, anonymous),
'delete': privacy_info_handle(delete_url, anonymous),
'files': node.web_url_for('collect_file_trees'),
}
}
return {'data': data}, httplib.OK
示例9: comment_discussion
def comment_discussion(auth, node, **kwargs):
users = collect_discussion(node)
anonymous = has_anonymous_link(node, auth)
# Sort users by comment frequency
# TODO: Allow sorting by recency, combination of frequency and recency
sorted_users = sorted(
users.keys(),
key=lambda item: len(users[item]),
reverse=True,
)
return {
'discussion': [
{
'id': privacy_info_handle(user._id, anonymous),
'url': privacy_info_handle(user.url, anonymous),
'fullname': privacy_info_handle(user.fullname, anonymous, name=True),
'isContributor': node.is_contributor(user),
'gravatarUrl': privacy_info_handle(
gravatar(
user, use_ssl=True, size=settings.GRAVATAR_SIZE_DISCUSSION,
),
anonymous
),
}
for user in sorted_users
]
}
示例10: serialize_node_summary
def serialize_node_summary(node, auth, primary=True, show_path=False):
summary = {
'id': node._id,
'primary': primary,
'is_registration': node.is_registration,
'is_fork': node.is_fork,
'is_pending_registration': node.is_pending_registration,
'is_retracted': node.is_retracted,
'is_pending_retraction': node.is_pending_retraction,
'embargo_end_date': node.embargo_end_date.strftime('%A, %b. %d, %Y') if node.embargo_end_date else False,
'is_pending_embargo': node.is_pending_embargo,
'is_embargoed': node.is_embargoed,
'archiving': node.archiving,
}
contributor_data = serialize_contributors_for_summary(node)
parent_node = node.parent_node
user = auth.user
if node.can_view(auth):
summary.update({
'can_view': True,
'can_edit': node.can_edit(auth),
'primary_id': node._id,
'url': node.url,
'primary': primary,
'api_url': node.api_url,
'title': node.title,
'category': node.category,
'isPreprint': bool(node.preprint_file_id),
'childExists': bool(node.nodes_active),
'is_admin': node.has_permission(user, permissions.ADMIN),
'is_contributor': node.is_contributor(user),
'logged_in': auth.logged_in,
'node_type': node.project_or_component,
'is_fork': node.is_fork,
'is_registration': node.is_registration,
'anonymous': has_anonymous_link(node, auth),
'registered_date': node.registered_date.strftime('%Y-%m-%d %H:%M UTC')
if node.is_registration
else None,
'forked_date': node.forked_date.strftime('%Y-%m-%d %H:%M UTC')
if node.is_fork
else None,
'ua_count': None,
'ua': None,
'non_ua': None,
'is_public': node.is_public,
'parent_title': parent_node.title if parent_node else None,
'parent_is_public': parent_node.is_public if parent_node else False,
'show_path': show_path,
# Read nlogs annotation if possible
'nlogs': node.nlogs if hasattr(node, 'nlogs') else node.logs.count(),
'contributors': contributor_data['contributors'],
'others_count': contributor_data['others_count'],
})
else:
summary['can_view'] = False
return summary
示例11: osfstorage_get_revisions
def osfstorage_get_revisions(file_node, node_addon, payload, **kwargs):
is_anon = has_anonymous_link(node_addon.owner, Auth(private_key=request.args.get('view_only')))
# Return revisions in descending order
return {
'revisions': [
utils.serialize_revision(node_addon.owner, file_node, version, index=len(file_node.versions) - idx - 1, anon=is_anon)
for idx, version in enumerate(reversed(file_node.versions))
]
}
示例12: file_info
def file_info(auth, fid, **kwargs):
versions = []
node = kwargs['node'] or kwargs['project']
file_name = fid
file_name_clean = urlsafe_filename(file_name)
files_page_url = node.web_url_for('collect_file_trees')
latest_download_url = None
api_url = None
anonymous = has_anonymous_link(node, auth)
try:
files_versions = node.files_versions[file_name_clean]
except KeyError:
raise HTTPError(http.NOT_FOUND)
latest_version_number = get_latest_version_number(file_name_clean, node) + 1
for idx, version in enumerate(list(reversed(files_versions))):
node_file = NodeFile.load(version)
number = len(files_versions) - idx
unique, total = get_basic_counters('download:{}:{}:{}'.format(
node._primary_key,
file_name_clean,
number,
))
download_url = node_file.download_url(node)
api_url = node_file.api_url(node)
versions.append({
'file_name': file_name,
'download_url': download_url,
'version_number': number,
'display_number': number if idx > 0 else 'current',
'modified_date': node_file.date_uploaded.strftime('%Y/%m/%d %I:%M %p'),
'downloads': total if total else 0,
'committer_name': privacy_info_handle(
node_file.uploader.fullname, anonymous, name=True
),
'committer_url': privacy_info_handle(node_file.uploader.url, anonymous),
})
if number == latest_version_number:
latest_download_url = download_url
return {
'node_title': node.title,
'file_name': file_name,
'versions': versions,
'registered': node.is_registration,
'urls': {
'api': api_url,
'files': files_page_url,
'latest': {
'download': latest_download_url,
},
}
}
示例13: _get_summary
def _get_summary(node, auth, rescale_ratio, primary=True, link_id=None, show_path=False):
# TODO(sloria): Refactor this or remove (lots of duplication with _view_project)
summary = {
"id": link_id if link_id else node._id,
"primary": primary,
"is_registration": node.is_registration,
"is_fork": node.is_fork,
"is_pending_registration": node.is_pending_registration,
"is_retracted": node.is_retracted,
"is_pending_retraction": node.is_pending_retraction,
"embargo_end_date": node.embargo_end_date.strftime("%A, %b. %d, %Y") if node.embargo_end_date else False,
"is_pending_embargo": node.is_pending_embargo,
"archiving": node.archiving,
}
if node.can_view(auth):
summary.update(
{
"can_view": True,
"can_edit": node.can_edit(auth),
"primary_id": node._id,
"url": node.url,
"primary": primary,
"api_url": node.api_url,
"title": node.title,
"category": node.category,
"node_type": node.project_or_component,
"is_fork": node.is_fork,
"is_registration": node.is_registration,
"anonymous": has_anonymous_link(node, auth),
"registered_date": node.registered_date.strftime("%Y-%m-%d %H:%M UTC")
if node.is_registration
else None,
"forked_date": node.forked_date.strftime("%Y-%m-%d %H:%M UTC") if node.is_fork else None,
"nlogs": None,
"ua_count": None,
"ua": None,
"non_ua": None,
"addons_enabled": node.get_addon_names(),
"is_public": node.is_public,
"parent_title": node.parent_node.title if node.parent_node else None,
"parent_is_public": node.parent_node.is_public if node.parent_node else False,
"show_path": show_path,
}
)
if rescale_ratio:
ua_count, ua, non_ua = _get_user_activity(node, auth, rescale_ratio)
summary.update({"nlogs": len(node.logs), "ua_count": ua_count, "ua": ua, "non_ua": non_ua})
else:
summary["can_view"] = False
# TODO: Make output format consistent with _view_project
return {"summary": summary}
示例14: list_comments
def list_comments(auth, node, **kwargs):
anonymous = has_anonymous_link(node, auth)
guid = request.args.get('target')
target = resolve_target(node, guid)
serialized_comments = serialize_comments(target, auth, anonymous)
n_unread = 0
if node.is_contributor(auth.user):
if auth.user.comments_viewed_timestamp is None:
auth.user.comments_viewed_timestamp = {}
auth.user.save()
n_unread = n_unread_comments(target, auth.user)
return {
'comments': serialized_comments,
'nUnread': n_unread
}
示例15: osf_storage_get_revisions
def osf_storage_get_revisions(payload, node_addon, **kwargs):
node = node_addon.owner
path = payload.get('path')
is_anon = has_anonymous_link(node, Auth(private_key=payload.get('view_only')))
if not path:
raise HTTPError(httplib.BAD_REQUEST)
record = model.OsfStorageFileNode.get(path.strip('/'), node_addon)
# Return revisions in descending order
return {
'revisions': [
utils.serialize_revision(node, record, version, index=len(record.versions) - idx - 1, anon=is_anon)
for idx, version in enumerate(reversed(record.versions))
]
}