本文整理汇总了Python中transifex.projects.permissions.project.ProjectPermission.proofread方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectPermission.proofread方法的具体用法?Python ProjectPermission.proofread怎么用?Python ProjectPermission.proofread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transifex.projects.permissions.project.ProjectPermission
的用法示例。
在下文中一共展示了ProjectPermission.proofread方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stringset_handling
# 需要导入模块: from transifex.projects.permissions.project import ProjectPermission [as 别名]
# 或者: from transifex.projects.permissions.project.ProjectPermission import proofread [as 别名]
def stringset_handling(request, project_slug, lang_code, resource_slug=None,
*args, **kwargs):
"""
Function to serve AJAX data to the datatable holding the translating
stringset.
"""
project = get_object_or_404(Project, slug=project_slug)
resources = []
if resource_slug:
try:
resources = [ Resource.objects.get(slug=resource_slug,
project__slug = project_slug) ]
except Resource.DoesNotExist:
raise Http404
else:
resources = Resource.objects.filter(project__slug = project_slug)
try:
language = Language.objects.by_code_or_alias(lang_code)
except Language.DoesNotExist:
raise Http404
# Check if user is a team reviewer so that we can
# send the extra info.
check = ProjectPermission(request.user)
review = check.proofread(project, language)
# FIXME Do we need to check for non-POST requests and return an error?
return _get_stringset(request.POST, resources, language, review=review)
示例2: _get_user_perms
# 需要导入模块: from transifex.projects.permissions.project import ProjectPermission [as 别名]
# 或者: from transifex.projects.permissions.project.ProjectPermission import proofread [as 别名]
def _get_user_perms(self, user, project, resource, language,
team, checksum, is_maintainer):
"""
Get permissions for a user.
Args:
user: A User instance
project: A Project instance
resource: A Resource instance
language: A Language instance
team: A Team instance
checksum: An md5 checksum representing a source entity
is_maintiner: A boolean
Returns:
A dictionary containing various user permissions
"""
check = ProjectPermission(user)
can_review = check.proofread(project, language)
can_submit_translations = check.submit_translations(
team or resource.project)
accept_translations = resource.accept_translations
return {
'can_review': can_review,
'can_submit_translations': can_submit_translations,
'accept_translations': accept_translations,
'is_maintainer': check.maintain(project),
}
示例3: _save_translation
# 需要导入模块: from transifex.projects.permissions.project import ProjectPermission [as 别名]
# 或者: from transifex.projects.permissions.project.ProjectPermission import proofread [as 别名]
def _save_translation(source_string, translations, target_language, user):
"""Save a translation string to the database.
This functions handle a signle source entity translation
(could be pluralized).
Currently, the function only returns warning strings.
There is no message for success.
Args:
source_string: A Translation object of the string in the source
language.
translations: A (rule, string) tuple.
target_language: The language the string is translated to.
user: The translator.
Returns:
A list if strings to display to the user.
Raises:
An LotteBadRequestError exception in case of errors.
"""
source_id = source_string.pk
resource = source_string.resource
source_language = resource.source_language
warnings = []
check = ProjectPermission(user)
review_perm = check.proofread(resource.project, target_language)
for rule, target_string in translations.items():
rule = target_language.get_rule_num_from_name(rule)
if rule != 5:
# fetch correct source string for plural rule
try:
source_string = Translation.objects.get(
source_entity=source_string.source_entity,
language=source_language, rule=rule
)
except Translation.DoesNotExist:
# target language has extra plural forms
pass
# check for errors
try:
for ErrorValidator in create_error_validators(resource.i18n_method):
v = ErrorValidator(source_language, target_language, rule)
v(source_string.string, target_string)
except ValidationError, e:
raise LotteBadRequestError(e.message)
# check for warnings
for WarningValidator in create_warning_validators(resource.i18n_method):
v = WarningValidator(source_language, target_language, rule)
try:
v(source_string.string, target_string)
except ValidationError, e:
warnings.append(e.message)
示例4: proofread
# 需要导入模块: from transifex.projects.permissions.project import ProjectPermission [as 别名]
# 或者: from transifex.projects.permissions.project.ProjectPermission import proofread [as 别名]
def proofread(request, project_slug, lang_code, resource_slug=None, *args, **kwargs):
"""AJAX view that sets the reviewed flag on Translations to true or false.
The request data is expected in JSON, with the following format:
{
'true': [1,2,3]
'false': [4,5]
}
Note: The IDs are source entity IDs.
"""
if request.method != 'POST':
return HttpResponse(status=405)
project = get_object_or_404(Project, slug=project_slug)
resource = get_object_or_404(Resource, slug=resource_slug, project=project)
try:
language = Language.objects.by_code_or_alias(lang_code)
except Language.DoesNotExist:
raise Http404
# Check if the user has the necessary permissions to review strings.
check = ProjectPermission(request.user)
if not check.proofread(project, language):
return permission_denied(request)
request_data = simplejson.loads(request.raw_post_data)
if 'true' in request_data:
source_entity_ids = request_data['true']
translations = Translation.objects.filter(
source_entity__id__in=source_entity_ids,
language__code=lang_code,
)
translations.update(reviewed=True)
ReviewHistory.add_many(translations, request.user, project.id, reviewed=True)
if 'false' in request_data:
source_entity_ids = request_data['false']
translations = Translation.objects.filter(
source_entity__id__in=source_entity_ids,
language__code=lang_code,
)
translations.update(reviewed=False)
ReviewHistory.add_many(translations, request.user, project.id, reviewed=False)
invalidate_stats_cache(resource, language, user=request.user)
return HttpResponse(status=200)
示例5: update
# 需要导入模块: from transifex.projects.permissions.project import ProjectPermission [as 别名]
# 或者: from transifex.projects.permissions.project.ProjectPermission import proofread [as 别名]
def update(self, request, project_slug, resource_slug,
language_code, api_version=2):
"""
Update existing translations for multiple source entities
of a resource at one go by permitted user(s).
"""
try:
project, resource, language = \
self._requested_objects(
project_slug, resource_slug, language_code)
self._validate_language_is_not_source_language(
project.source_language, language)
translations = request.data
self._validate_translations_json_data(translations)
team = Team.objects.get_or_none(project, language.code)
check = ProjectPermission(request.user)
# User must be a member of the project
is_maintainer = check.maintain(project)
# Allow only project members to issue this update request
if not is_maintainer and not (check.submit_translations(
team or project) or check.proofread(project, language)):
return FORBIDDEN_REQUEST(
"You are not allowed to update translations.")
trans_obj_dict = self._translations_as_dict(
translations, resource, language)
updated_translations = []
se_ids = []
for translation in translations:
# All permission checks for a user is done here and
# updated translations are collected in updated_tranlsations
# and source_entity.id in se_ids
self._process_translation_dict(translation, project, resource,
language, team, check, is_maintainer, request.user,
se_ids, updated_translations, trans_obj_dict)
self._update_translations(updated_translations)
keys = ['key', 'context', 'translation',
'reviewed', 'pluralized', 'wordcount',
'last_update', 'user', 'position', 'occurrences',]
field_map, fields = self._get_update_fieldmap_and_fields(keys)
return self._generate_translations_dict(
Translation.objects.filter( source_entity__id__in=se_ids,
language=language).values(*fields), field_map)
except NotFoundError, e:
return NOT_FOUND_REQUEST(unicode(e))