本文整理汇总了Python中transifex.projects.permissions.project.ProjectPermission类的典型用法代码示例。如果您正苦于以下问题:Python ProjectPermission类的具体用法?Python ProjectPermission怎么用?Python ProjectPermission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProjectPermission类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_user_perms
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),
}
开发者ID:593in,项目名称:transifex,代码行数:28,代码来源:translation_object.py
示例2: can_unlock
def can_unlock(self, user):
"""
Perform permission check whether 'user' can unlock the Lock instance.
"""
perm = ProjectPermission(user)
return (self.owner == user) or perm.coordinate_team(
project=self.rlstats.resource.project, language=self.rlstats.language)
开发者ID:593in,项目名称:transifex,代码行数:7,代码来源:models.py
示例3: _update
def _update(self, request, project_slug, resource_slug, lang_code=None):
# Permissions handling
try:
resource = Resource.objects.get(
slug=resource_slug, project__slug=project_slug
)
except Resource.DoesNotExist:
return rc.NOT_FOUND
if lang_code == "source":
language = resource.source_language
else:
try:
language = Language.objects.by_code_or_alias(lang_code)
except Language.DoesNotExist:
logger.error("Weird! Selected language code (%s) does "
"not match with any language in the database."
% lang_code)
return BAD_REQUEST(
"Selected language code (%s) does not match with any"
"language in the database." % lang_code
)
team = Team.objects.get_or_none(resource.project, lang_code)
check = ProjectPermission(request.user)
if (not check.submit_translations(team or resource.project) or\
not resource.accept_translations) and not\
check.maintain(resource.project):
return rc.FORBIDDEN
try:
t = Translation.get_object("create", request, resource, language)
res = t.create()
except BadRequestError, e:
return BAD_REQUEST(unicode(e))
开发者ID:rvanlaar,项目名称:easy-transifex,代码行数:34,代码来源:api.py
示例4: cla_project_sign
def cla_project_sign(request, project_slug):
project = get_object_or_404(Project, slug=project_slug)
cla = get_object_or_404(Cla, project=project)
check = ProjectPermission(request.user)
if not check.submit_translations(project, any_team=True):
return permission_denied(request)
try:
signed_cla = request.user.cla_set.filter(project=project)[0]
except IndexError:
signed_cla = None
if request.method == "POST" and not signed_cla:
form = ClaForm(request.POST)
if form.is_valid():
kwargs = {"cla_sign": True, "project": project, "user": request.user}
handle_pre_team(None, **kwargs)
messages.success(request, _("You have signed the CLA."))
return HttpResponseRedirect(reverse("cla_project_sign", args=[project_slug]))
else:
form = ClaForm()
return render_to_response(
"project_cla.html",
{"project": project, "cla": cla, "signed_cla": signed_cla, "form": form},
context_instance=RequestContext(request),
)
开发者ID:qikh,项目名称:transifex,代码行数:30,代码来源:views.py
示例5: stringset_handling
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)
开发者ID:rvanlaar,项目名称:easy-transifex,代码行数:31,代码来源:views.py
示例6: lock_and_get_translation_file
def lock_and_get_translation_file(request, project_slug, resource_slug, lang_code):
"""
Lock and download the translations file.
View to lock a resource for the requested language and as a second step to
download (export+download) the translations in a formatted file.
"""
resource = get_object_or_404(Resource, project__slug = project_slug,
slug = resource_slug)
# Permissions handling
# Project should always be available
project = get_object_or_404(Project, slug=project_slug)
team = Team.objects.get_or_none(project, lang_code)
check = ProjectPermission(request.user)
if not check.submit_translations(team or project) or not \
resource.accept_translations:
return permission_denied(request)
language = get_object_or_404(Language, code=lang_code)
lock = Lock.objects.get_valid(resource, language)
can_lock = Lock.can_lock(resource, language, request.user)
response = {}
if not can_lock:
#print_gray_text(You cannot assign this file to you)
response['status'] = "FAILED"
response['message'] = _("Sorry, you cannot lock this file!")
else:
# User can lock
if not lock:
try:
# Lock the resource now
Lock.objects.create_update(resource, language, request.user)
response['status'] = 'OK'
response['redirect'] = reverse('download_for_translation',
args=[resource.project.slug, resource.slug, lang_code])
except:
response['status'] = "FAILED"
response['message'] = _("Failed to lock the resource!")
else:
if lock.owner == request.user:
try:
# File already locked by me, so extend the lock period.
Lock.objects.create_update(resource, language, request.user)
response['status'] = 'OK'
response['redirect'] = reverse('download_for_translation',
args=[resource.project.slug, resource.slug, lang_code])
except:
response['status'] = "FAILED"
response['message'] = _("Failed to extend lock period on "
"the resource!")
else:
# File locked by someone else:
response['status'] = "FAILED"
response['message'] = _("You cannot lock it right now! (Locked "
"by %s )" % (lock.owner,))
return HttpResponse(simplejson.dumps(response), mimetype='application/json')
开发者ID:garbelini,项目名称:transifex,代码行数:60,代码来源:views.py
示例7: _has_perm
def _has_perm(self, user, project):
"""
Check that the user has access to this resource.
"""
perm = ProjectPermission(user)
if not perm.private(project):
return False
return True
开发者ID:tymofij,项目名称:adofex,代码行数:8,代码来源:__init__.py
示例8: exit
def exit(request, project_slug, lang_code, resource_slug=None, *args, **kwargs):
"""
Exiting Lotte
"""
if request.method != 'POST':
return HttpResponse(status=405)
# Permissions handling
# Project should always be available
project = get_object_or_404(Project, slug=project_slug)
team = Team.objects.get_or_none(project, lang_code)
check = ProjectPermission(request.user)
if not check.submit_translations(team or project) and not\
check.maintain(project):
return permission_denied(request)
language = Language.objects.by_code_or_alias(lang_code)
resources = []
if resource_slug:
resources = Resource.objects.filter(slug=resource_slug, project=project)
if not resources:
raise Http404
else:
resources = Resource.objects.filter(project=project)
data = simplejson.loads(request.raw_post_data)
if data.get('updated'):
modified = True
# ActionLog & Notification
for resource in resources:
nt = 'project_resource_translated'
context = {'project': project,
'resource': resource,
'language': language,
'sender': request.user}
object_list = [project, resource, language]
if team:
object_list.append(team)
action_logging(request.user, object_list, nt, context=context)
else:
modified = False
lotte_done.send(None, request=request, resources=resources,
language=language, modified=modified)
redirect_url = reverse('team_detail', args=[project_slug, language.code])
if request.is_ajax():
json = simplejson.dumps(dict(redirect=redirect_url))
return HttpResponse(json, mimetype='application/json')
return HttpResponseRedirect(redirect_url)
开发者ID:garbelini,项目名称:transifex,代码行数:55,代码来源:views.py
示例9: _save_translation
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)
开发者ID:garbelini,项目名称:transifex,代码行数:55,代码来源:views.py
示例10: can_lock
def can_lock(resource, language, user):
"""
Perform permission check whether 'user' can create a Lock.
CAUTION: It does not perform lock counting check!
"""
perm = ProjectPermission(user)
if resource.accept_translations and (
perm.submit_translations(resource.project, language) or
perm.coordinate_team(project=resource.project, language=language)):
return True
return False
开发者ID:593in,项目名称:transifex,代码行数:12,代码来源:models.py
示例11: proofread
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)
开发者ID:593in,项目名称:transifex,代码行数:51,代码来源:views.py
示例12: update
def update(self, request, project_slug, resource_slug,
language_code, source_hash, api_version=2):
"""
Update existing translations for a source entity of a resource.
"""
try:
project, resource, language = \
self._requested_objects(project_slug,
resource_slug, language_code)
# A translation in source language cannot be updated
self._validate_language_is_not_source_language(
project.source_language, language)
try:
source_entity = SourceEntity.objects.get(
string_hash=source_hash, resource=resource)
except SourceEntity.DoesNotExist, e:
return rc.NOT_FOUND
team = Team.objects.get_or_none(project, language.code)
data = request.data
# This is a hack to use the methods from TranslationObjectsHandler
data['source_entity_hash'] = source_hash
check = ProjectPermission(request.user)
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(
[data], resource, language)
if not trans_obj_dict:
return rc.NOT_FOUND
updated_translations = []
se_ids = []
# 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(data, project, resource,
language, team, check, is_maintainer, request.user,
se_ids, updated_translations, trans_obj_dict)
# Updated translations are saved to db
self._update_translations(updated_translations)
translations = Translation.objects.filter(
source_entity=source_entity, language=language)
field_map = self._get_fieldmap()
fields = self._get_fields_for_translation_value_query_set(field_map)
return self._generate_translations_dict(
Translation.objects.filter( source_entity__id__in=se_ids,
language=language).values(*fields), field_map, True)
开发者ID:593in,项目名称:transifex,代码行数:50,代码来源:translation_object.py
示例13: exit
def exit(request, project_slug, lang_code, resource_slug=None, *args, **kwargs):
"""
Exiting Lotte
"""
# Permissions handling
# Project should always be available
project = get_object_or_404(Project, slug=project_slug)
team = Team.objects.get_or_none(project, lang_code)
check = ProjectPermission(request.user)
if not check.submit_translations(team or project) and not\
check.maintain(project):
return permission_denied(request)
language = Language.objects.by_code_or_alias(lang_code)
resources = []
if resource_slug:
resources = Resource.objects.filter(slug=resource_slug, project=project)
if not resources:
raise Http404
url = reverse('resource_detail', args=[project_slug, resource_slug])
else:
resources = Resource.objects.filter(project=project)
url = reverse('project_detail', args=[project_slug])
if request.POST.get('updated', None) == 'true':
modified = True
# ActionLog & Notification
for resource in resources:
nt = 'project_resource_translated'
context = {'project': project,
'resource': resource,
'language': language}
object_list = [project, resource, language]
action_logging(request.user, object_list, nt, context=context)
if settings.ENABLE_NOTICES:
txnotification.send_observation_notices_for(project,
signal=nt, extra_context=context)
else:
modified = False
lotte_done.send(None, request=request, resources=resources,
language=language, modified=modified)
if request.is_ajax():
json = simplejson.dumps(dict(redirect=url))
return HttpResponse(json, mimetype='application/json')
return HttpResponseRedirect(url)
开发者ID:hfeeki,项目名称:transifex,代码行数:50,代码来源:views.py
示例14: tab_suggestions_snippet
def tab_suggestions_snippet(request, entity_id, lang_code):
"""Return a template snippet with entity & translation details."""
source_entity = get_object_or_404(SourceEntity, pk=entity_id)
check = ProjectPermission(request.user)
if not check.private(source_entity.resource.project):
return permission_denied(request)
current_translation = source_entity.get_translation(lang_code)
return render_to_response("tab_suggestions_snippet.html", {
'source_entity': source_entity,
'lang_code': lang_code,
'current_translation': current_translation
},
context_instance = RequestContext(request))
开发者ID:rvanlaar,项目名称:easy-transifex,代码行数:17,代码来源:views.py
示例15: clone_language
def clone_language(request, project_slug=None, resource_slug=None,
source_lang_code=None, target_lang_code=None):
'''
Get a resource, a src lang and a target lang and clone all translation
strings for the src to the target.
The user is redirected to the online editor for the target language.
'''
resource = get_object_or_404(Resource, slug=resource_slug,
project__slug=project_slug)
# Permissions handling
# Project should always be available
project = get_object_or_404(Project, slug=project_slug)
team = Team.objects.get_or_none(project, target_lang_code)
check = ProjectPermission(request.user)
if not check.submit_translations(team or project) or not \
resource.accept_translations:
return permission_denied(request)
source_lang = get_object_or_404(Language, code=source_lang_code)
target_lang = get_object_or_404(Language, code=target_lang_code)
# get the strings which will be cloned
strings = Translation.objects.filter(
resource = resource,
language = source_lang)
# If the language we want to create, has the same plural rules with the
# source, we also copy the pluralized translations!
if not source_lang.get_pluralrules() == target_lang.get_pluralrules():
strings = strings.exclude(source_entity__pluralized = True)
# clone them in new translation
for s in strings:
Translation.objects.get_or_create(
language=target_lang, string=s.string,
source_entity=s.source_entity, rule=s.rule,
resource=s.resource
)
invalidate_stats_cache(resource, target_lang, user=request.user)
return HttpResponseRedirect(reverse('translate_resource', args=[project_slug,
resource_slug, target_lang_code]),)
开发者ID:garbelini,项目名称:transifex,代码行数:45,代码来源:views.py
示例16: tab_details_snippet
def tab_details_snippet(request, entity_id, lang_code):
"""Return a template snippet with entity & translation details."""
source_entity = get_object_or_404(SourceEntity, pk=entity_id)
check = ProjectPermission(request.user)
if not check.private(source_entity.resource.project):
return permission_denied(request)
language = get_object_or_404(Language, code=lang_code)
translation = source_entity.get_translation(language.code)
return list_detail.object_detail(request,
queryset=SourceEntity.objects.all(),
object_id=entity_id,
template_name="tab_details_snippet.html",
template_object_name='source_entity',
extra_context={"translation": translation,
"project": source_entity.resource.project})
开发者ID:rvanlaar,项目名称:easy-transifex,代码行数:19,代码来源:views.py
示例17: update_translation
def update_translation(request, project_slug, resource_slug, lang_code=None):
"""Ajax view that gets an uploaded translation as a file and saves it.
If the language is not specified, the translation does not exist yet.
Othewise, this is an update.
Returns:
Either an error message, or nothing for success.
"""
resource = get_object_or_404(
Resource.objects.select_related('project'),
project__slug=project_slug, slug=resource_slug
)
if lang_code is None:
lang_code = request.POST.get('language_code', None)
target_language = get_object_or_404(Language, code=lang_code)
project = resource.project
# Get the team if exists to use it for permissions and links
team = Team.objects.get_or_none(project, lang_code)
check = ProjectPermission(request.user)
if (not check.submit_translations(team or resource.project) or\
not resource.accept_translations) and not\
check.maintain(resource.project):
return HttpResponse(
simplejson.dumps({
'msg': _("You are not allowed to upload a translation."),
'status': 403,
}),
status=403, content_type='text/plain'
)
content = content_from_uploaded_file(request.FILES)
try:
_save_translation(resource, target_language, request.user, content)
except FormatsBackendError, e:
return HttpResponse(
simplejson.dumps({
'msg': unicode(e),
'status': 400,
}),
status=400, content_type='text/plain'
)
开发者ID:garbelini,项目名称:transifex,代码行数:43,代码来源:views.py
示例18: add_edit_developer_comment_extra
def add_edit_developer_comment_extra(request, project_slug, *args, **kwargs):
"""
View for handling AJAX calls from Lotte in order to add/edit the
developer comment for a source entity.
Only maintainers can edit it.
"""
# Permissions handling
project = get_object_or_404(Project, slug=project_slug)
check = ProjectPermission(request.user)
if not check.maintain(project):
content = {'error': True, 'message': _('Permission error.')}
elif not request.POST:
content = {'error': True, 'message': _('Bad request.')}
else:
previous_comment = None
try:
se = SourceEntity.objects.get(
id=request.POST.get('source_entity_id', None),
resource__project=project)
previous_comment_extra = se.developer_comment_extra
se.developer_comment_extra = request.POST.get('comment_extra', '')
se.save()
content = {
'error': False,
'comment': se.developer_comment,
'comment_extra': se.developer_comment_extra,
}
except SourceEntity.DoesNotExist:
content = {
'error': True,
'message': _('No such Source Entity for the given project.'),
}
except Exception, e:
logger.error('Lotte: Error while editing developer comment: %s' %
(e.message or str(e)))
content = {
'error': True,
'message': _('Ops! Something weird happened. The admins '
'were notified about it.'),
}
开发者ID:rvanlaar,项目名称:easy-transifex,代码行数:42,代码来源:views.py
示例19: project_delete_permission_request
def project_delete_permission_request(request, project_slug, permission_pk):
"""
View for deleting a request of permission of a user.
This view is an abstraction of a txpermissions.views method.
"""
project, permission=_get_project_and_permission(project_slug, permission_pk)
# It's necessary to distinguish between maintainer and normal users that
# did the request
if request.user.id==permission.user.id:
notice_type = 'project_submit_access_request_withdrawn'
sendto = project.maintainers.all()
else:
notice_type = 'project_submit_access_request_denied'
sendto = [permission.user]
notice = {
'type': notice_type,
'object': project,
'sendto': sendto,
'extra_context': {'project': project,
'user_request': permission.user,
'user_action': request.user,
},
}
check = ProjectPermission(request.user)
if check.maintain(project) or \
request.user.has_perm('authority.delete_permission') or \
request.user.pk == permission.creator.pk:
return delete_permission_or_request(request, permission, False,
extra_context={ 'notice': notice },)
check = ProjectPermission(request.user)
if check.maintain(project) or \
request.user.has_perm('authority.delete_permission') or \
request.user.pk == permission.creator.pk:
return delete_permission_or_request(request, permission, False)
return permission_denied(request)
开发者ID:593in,项目名称:transifex,代码行数:42,代码来源:permission.py
示例20: _read
def _read(self, request, project_slug):
"""
Return a list of projects or the details for a specific project.
"""
if project_slug is None:
# Use pagination
p = Project.objects.for_user(request.user)
res, msg = paginate(p, request.GET.get("start"), request.GET.get("end"))
if res is None:
return BAD_REQUEST(msg)
return res
else:
try:
p = Project.objects.get(slug=project_slug)
perm = ProjectPermission(request.user)
if not perm.private(p):
return rc.FORBIDDEN
except Project.DoesNotExist:
return rc.NOT_FOUND
return p
开发者ID:hfeeki,项目名称:transifex,代码行数:20,代码来源:api.py
注:本文中的transifex.projects.permissions.project.ProjectPermission类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论