本文整理汇总了Python中pootle.core.delegate.language_team.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_view_language_team_new_member
def test_view_language_team_new_member(client, language0, request_users,
member, member2):
user = request_users["user"]
team = language_team.get(language0.__class__)(language0)
admin_url = reverse(
'pootle-language-admin-team-new-members',
kwargs=dict(language_code=language0.code))
client.login(
username=user.username,
password=request_users["password"])
if not user.is_superuser:
response = client.post(admin_url)
assert response.status_code == 403
else:
with pytest.raises(Http400):
client.post(admin_url)
response = client.post(admin_url, data=dict(q="DOES NOT EXIST"))
if not user.is_superuser:
if user.is_anonymous:
assert response.status_code == 402
return
assert response.status_code == 403
team.add_member(user, "admin")
response = client.post(admin_url, data=dict(q="DOES NOT EXIST"))
assert json.loads(response.content)["items"]["results"] == []
search_member = (
member
if user == member2
else member2)
response = client.post(admin_url, data=dict(q=search_member.username[:2]))
result = json.loads(response.content)
assert search_member.username in [r["text"] for r in result["items"]["results"]]
team = language_team.get(language0.__class__)(language0)
team.add_member(search_member, "member")
response = client.post(admin_url, data=dict(q=search_member.username[:2]))
result = json.loads(response.content)
assert (
search_member.username
not in [r["text"] for r in result["items"]["results"]])
if user in team.admins:
team.remove_member(user)
from django.core.cache import cache
from django.utils.encoding import iri_to_uri
key = iri_to_uri('Permissions:%s' % user.username)
key = iri_to_uri('Permissions:%s' % search_member.username)
cache.delete(key)
开发者ID:cloph,项目名称:pootle,代码行数:48,代码来源:views.py
示例2: test_view_admin_language_team_suggestion
def test_view_admin_language_team_suggestion(client, language0, request_users):
user = request_users["user"]
team = language_team.get(language0.__class__)(language0)
admin_url = reverse(
'pootle-language-admin-suggestions',
kwargs=dict(language_code=language0.code))
client.login(
username=user.username,
password=request_users["password"])
response = client.get(admin_url)
if not user.is_superuser:
assert response.status_code == 403
if user.is_anonymous:
return
team.add_member(user, "admin")
response = client.get(admin_url)
assert response.context["language"] == language0
assert response.context["page"] == "admin-suggestions"
formtable = response.context["formtable"]
assert isinstance(formtable, SuggestionFormtable)
assert isinstance(formtable.form, LanguageSuggestionAdminForm)
assert formtable.form.user == response.wsgi_request.user
assert formtable.form.language == language0
assert formtable.form.data == dict(
page_no=1,
results_per_page=10)
assert (
[x[0] for x in formtable.form.fields["suggestions"].choices]
== [item.id
for item in
formtable.form.batch().object_list])
assert isinstance(
formtable.form.fields["suggestions"].choices[0][1],
SuggestionDisplay)
开发者ID:cloph,项目名称:pootle,代码行数:34,代码来源:views.py
示例3: test_display_language_suggestion
def test_display_language_suggestion(language0):
team = language_team.get()(language0)
suggestion = team.suggestions.first()
display = SuggestionDisplay(suggestion)
assert display.__suggestion__ is suggestion
assert (
display.project
== ("<a href='%s'>%s</a>"
% (suggestion.unit.store.translation_project.pootle_path,
suggestion.unit.store.translation_project.project.code)))
assert display.unit == display.__suggestion__.unit.source
assert (
display.unit_link
== ("<a href='%s'>#%s</a>"
% (suggestion.unit.get_translate_url(),
suggestion.unit.id)))
assert (
str(display.unit_state)
== STATES_MAP[suggestion.unit.state])
assert (
display.state
== suggestion.state)
with pytest.raises(AttributeError):
display.DOES_NOT_EXIST
开发者ID:cloph,项目名称:pootle,代码行数:25,代码来源:views.py
示例4: test_language_team_non_members
def test_language_team_non_members(language0, member):
team = language_team.get(Language)(language0)
team.add_member(member, "member")
User = get_user_model()
assert (
sorted(team.non_members.values_list("id", flat=True))
== sorted(
User.objects.exclude(
username=member.username).values_list("id", flat=True)))
开发者ID:ta2-1,项目名称:pootle,代码行数:9,代码来源:teams.py
示例5: tp_uploads
def tp_uploads(request, client):
from pootle.core.delegate import language_team
from pootle_language.models import Language
from pootle_translationproject.models import TranslationProject
from pootle_store.models import Store
from django.contrib.auth import get_user_model
submitter_name, uploader_name, errors = request.param
uploader = get_user_model().objects.get(username=uploader_name)
tp = TranslationProject.objects.all()[0]
store = Store.objects.filter(parent=tp.directory)[0]
kwargs = {
"project_code": tp.project.code,
"language_code": tp.language.code,
"dir_path": "",
"filename": store.name}
password = TEST_USERS[submitter_name]['password']
language_team.get(Language)(tp.language).add_member(uploader, "submitter")
client.login(username=submitter_name, password=password)
updated_units = [
(unit.source_f, "%s UPDATED" % unit.target_f, False)
for unit in store.units
]
updated_store = create_store(store.pootle_path, "0", updated_units)
uploaded_file = SimpleUploadedFile(
store.name,
str(updated_store),
"text/x-gettext-translation"
)
response = client.post(
reverse("pootle-tp-store-browse", kwargs=kwargs),
{
'name': '',
'file': uploaded_file,
'user_id': uploader.id
}
)
return tp, response.wsgi_request, response, kwargs, errors
开发者ID:arky,项目名称:pootle,代码行数:39,代码来源:views.py
示例6: test_language_team_suggestions
def test_language_team_suggestions(language0):
team = language_team.get(Language)(language0)
suggestions = Suggestion.objects.filter(
state=SuggestionStates.PENDING,
unit__state__gt=OBSOLETE,
unit__store__translation_project__language=language0)
assert (
list(team.suggestions)
== list(suggestions.order_by("-creation_time", "-pk")))
# there should be some suggestions in the env
assert team.suggestions
assert (
team.users_with_suggestions
== set(
team.suggestions.values_list(
"user__username",
"user__full_name")))
开发者ID:SafaAlfulaij,项目名称:pootle,代码行数:17,代码来源:teams.py
示例7: test_membership_user
def test_membership_user(member, member2, language0, language1):
lang_team = language_team.get()
user_member = membership.get(member.__class__)(member)
assert isinstance(user_member, UserMembership)
assert user_member.user == member
assert user_member.teams == []
assert user_member.teams_and_roles == {}
lang_team(language0).add_member(member, "admin")
user_member = membership.get(member.__class__)(member)
assert user_member.teams == [language0.code]
assert user_member.teams_and_permissions == {
language0.code: set(['administrate', 'review', 'suggest', 'translate'])}
user_member.teams_and_roles[language0.code]["role"] == "Admin"
user_member.teams_and_roles[language0.code]["name"] == language0.name
lang_team(language1).add_member(member, "submitter")
user_member = membership.get(member.__class__)(member)
assert sorted(user_member.teams) == [language0.code, language1.code]
assert user_member.teams_and_permissions == {
language0.code: set(['administrate', 'review', 'suggest', 'translate']),
language1.code: set(['suggest', 'translate'])}
user_member.teams_and_roles[language0.code]["role"] == "Admin"
user_member.teams_and_roles[language0.code]["name"] == language0.name
user_member.teams_and_roles[language1.code]["role"] == "Translater"
user_member.teams_and_roles[language1.code]["name"] == language1.name
lang_team(language0).add_member(member2, "reviewer")
user_member = membership.get(member2.__class__)(member2)
assert user_member.teams == [language0.code]
assert user_member.teams_and_permissions == {
language0.code: set(['review', 'suggest', 'translate'])}
user_member.teams_and_roles[language0.code]["role"] == "Reviewer"
user_member.teams_and_roles[language0.code]["name"] == language0.name
lang_team(language1).add_member(member2, "member")
user_member = membership.get(member2.__class__)(member2)
assert sorted(user_member.teams) == [language0.code, language1.code]
assert user_member.teams_and_permissions == {
language0.code: set(['review', 'suggest', 'translate']),
language1.code: set(['suggest'])}
user_member.teams_and_roles[language0.code]["role"] == "Reviewer"
user_member.teams_and_roles[language0.code]["name"] == language0.name
user_member.teams_and_roles[language1.code]["role"] == ""
user_member.teams_and_roles[language1.code]["name"] == language1.name
开发者ID:arky,项目名称:pootle,代码行数:45,代码来源:membership.py
示例8: test_language_team_suggestions
def test_language_team_suggestions(language0):
team = language_team.get(Language)(language0)
suggestions = (
Suggestion.objects.filter(
state__name="pending",
unit__state__gt=OBSOLETE,
unit__store__translation_project__language=language0
).exclude(
unit__store__translation_project__project__disabled=True
).exclude(unit__store__obsolete=True))
assert (
list(team.suggestions)
== list(suggestions.order_by("-creation_time", "-pk")))
# there should be some suggestions in the env
assert team.suggestions
assert (
team.users_with_suggestions
== set(
team.suggestions.values_list(
"user__username",
"user__full_name")))
开发者ID:arky,项目名称:pootle,代码行数:21,代码来源:teams.py
示例9: test_view_language_team_admin
def test_view_language_team_admin(client, language0, request_users):
user = request_users["user"]
team = language_team.get(language0.__class__)(language0)
admin_url = reverse(
'pootle-language-admin-team',
kwargs=dict(language_code=language0.code))
client.login(
username=user.username,
password=request_users["password"])
response = client.get(admin_url)
if not user.is_superuser:
assert response.status_code == 403
if user.is_anonymous:
return
team.add_member(user, "admin")
response = client.get(admin_url)
assert isinstance(
response.context["form"], LanguageTeamAdminForm)
assert (
list(response.context["tps"])
== list(
language0.translationproject_set.exclude(
project__disabled=True)))
for k in response.context["stats"].keys():
if k.endswith("_display"):
del response.context["stats"][k]
assert (
list(response.context["stats"])
== list(
language0.data_tool.get_stats(
include_children=False,
user=user)))
assert (
list(response.context["suggestions"])
== list(
response.context["form"].language_team.suggestions))
assert response.context["language"] == language0
if user in team.admins:
team.remove_member(user)
开发者ID:SafaAlfulaij,项目名称:pootle,代码行数:39,代码来源:views.py
示例10: test_view_language_team_admin_post
def test_view_language_team_admin_post(client, language0, request_users,
member, member2):
user = request_users["user"]
team = language_team.get(language0.__class__)(language0)
search_member = (
member
if user == member2
else member2)
assert search_member not in team.members
admin_url = reverse(
'pootle-language-admin-team',
kwargs=dict(language_code=language0.code))
client.login(
username=user.username,
password=request_users["password"])
response = client.post(
admin_url,
data=dict(new_member=search_member.id, role="member"))
if not user.is_superuser:
assert search_member not in team.members
if user.is_anonymous:
assert response.status_code == 402
return
team.add_member(user, "admin")
response = client.post(
admin_url,
data=dict(new_member=search_member.id, role="member"))
team.update_permissions()
assert search_member in team.members
assert response.status_code == 302
response = client.post(
admin_url,
data=dict(rm_members=[search_member.id]))
team.update_permissions()
assert search_member not in team.members
assert response.status_code == 302
开发者ID:cloph,项目名称:pootle,代码行数:36,代码来源:views.py
示例11: language_team
def language_team(self):
return language_team.get(self.language.__class__)(self.language)
开发者ID:claudep,项目名称:pootle,代码行数:2,代码来源:forms.py
示例12: test_view_admin_language_suggestion_post
def test_view_admin_language_suggestion_post(client, language0, request_users,
mailoutbox):
user = request_users["user"]
team = language_team.get(language0.__class__)(language0)
admin_url = reverse(
'pootle-language-admin-suggestions',
kwargs=dict(language_code=language0.code))
client.login(
username=user.username,
password=request_users["password"])
suggestion = team.suggestions.first()
data = dict(
actions="accept",
suggestions=[suggestion.id])
response = client.post(admin_url, data=data)
if not user.is_superuser:
if user.is_anonymous:
assert response.status_code == 402
return
assert response.status_code == 403
team.add_member(user, "admin")
response = client.post(admin_url, data=data)
assert response.status_code == 302
suggestion.refresh_from_db()
assert suggestion.state.name == "accepted"
assert len(mailoutbox) == 0
# reject
suggestion = team.suggestions.first()
data = dict(
actions="reject",
suggestions=[suggestion.id])
response = client.post(admin_url, data=data)
assert response.status_code == 302
suggestion.refresh_from_db()
assert suggestion.state.name == "rejected"
assert len(mailoutbox) == 0
# reject with comment
suggestion = team.suggestions.first()
data = dict(
actions="accept",
comment="ta very much!",
suggestions=[suggestion.id])
response = client.post(admin_url, data=data)
assert response.status_code == 302
suggestion.refresh_from_db()
assert suggestion.state.name == "accepted"
assert len(mailoutbox) == 1
# reject with comment
suggestion = team.suggestions.first()
data = dict(
actions="reject",
comment="no way!",
suggestions=[suggestion.id])
response = client.post(admin_url, data=data)
assert response.status_code == 302
suggestion.refresh_from_db()
assert suggestion.state.name == "rejected"
assert len(mailoutbox) == 2
开发者ID:cloph,项目名称:pootle,代码行数:61,代码来源:views.py
示例13: test_language_team_members
def test_language_team_members(language0, member):
team = language_team.get(Language)(language0)
assert (
list(team.members)
== list(team.submitters)
== list(team.reviewers)
== list(team.admins)
== [])
team.add_member(member, "member")
assert list(team.members) == [member]
assert (
list(team.submitters)
== list(team.reviewers)
== list(team.admins)
== [])
assert (
member.permissionset_set
.filter(directory=language0.directory)
.filter(positive_permissions__codename="suggest")
.count()
== 1)
assert (
member.permissionset_set
.filter(directory=language0.directory)
.exclude(positive_permissions__codename="suggest")
.count()
== 0)
team.add_member(member, "submitter")
assert list(team.submitters) == [member]
assert (
list(team.members)
== list(team.reviewers)
== list(team.admins)
== [])
assert (
member.permissionset_set
.filter(directory=language0.directory)
.filter(positive_permissions__codename__in=["suggest",
"translate"])
.count()
== 2)
assert (
member.permissionset_set
.filter(directory=language0.directory)
.exclude(positive_permissions__codename__in=["suggest",
"translate"])
.count()
== 0)
team.add_member(member, "reviewer")
assert list(team.reviewers) == [member]
assert (
list(team.members)
== list(team.submitters)
== list(team.admins)
== [])
assert (
member.permissionset_set
.filter(directory=language0.directory)
.filter(positive_permissions__codename__in=["suggest",
"review",
"translate"])
.count()
== 3)
assert (
member.permissionset_set
.filter(directory=language0.directory)
.exclude(positive_permissions__codename__in=["suggest",
"review",
"translate"])
.count()
== 0)
team.add_member(member, "admin")
assert list(team.admins) == [member]
assert (
list(team.members)
== list(team.submitters)
== list(team.reviewers)
== [])
assert (
member.permissionset_set
.filter(directory=language0.directory)
.filter(positive_permissions__codename__in=["suggest",
"review",
"administrate",
"translate"])
.count()
== 4)
assert (
member.permissionset_set
.filter(directory=language0.directory)
.exclude(positive_permissions__codename__in=["suggest",
"review",
"administrate",
"translate"])
.count()
== 0)
team.remove_member(member)
assert (
list(team.members)
== list(team.submitters)
#.........这里部分代码省略.........
开发者ID:ta2-1,项目名称:pootle,代码行数:101,代码来源:teams.py
示例14: test_language_team_getter
def test_language_team_getter(language0):
team = language_team.get(Language)(language0)
assert isinstance(team, LanguageTeam)
开发者ID:ta2-1,项目名称:pootle,代码行数:3,代码来源:teams.py
示例15: handle_upload_form
def handle_upload_form(request, tp):
"""Process the upload form."""
valid_extensions = tp.project.filetype_tool.valid_extensions
if "po" not in valid_extensions:
return {}
language = tp.language
team = language_team.get(tp.language.__class__)(language)
uploader_list = [(request.user.id, request.user.display_name), ]
if check_permission('administrate', request):
User = get_user_model()
uploader_list = [
(user.id, user.display_name)
for user
in (team.submitters | team.reviewers | team.admins | team.superusers)]
if request.method == "POST" and "file" in request.FILES:
upload_form = UploadForm(
request.POST,
request.FILES,
uploader_list=uploader_list
)
if upload_form.is_valid():
uploader_id = upload_form.cleaned_data["user_id"]
django_file = request.FILES["file"]
uploader = request.user
if uploader_id and uploader_id != uploader.id:
User = get_user_model()
uploader = User.objects.get(
id=upload_form.cleaned_data["user_id"]
)
try:
if is_zipfile(django_file):
with ZipFile(django_file, "r") as zf:
for path in zf.namelist():
if path.endswith("/"):
# is a directory
continue
ext = os.path.splitext(path)[1].strip(".")
if ext not in valid_extensions:
continue
with zf.open(path, "r") as f:
import_file(f, user=uploader)
else:
# is_zipfile consumes the file buffer
django_file.seek(0)
import_file(django_file, user=uploader)
except Exception as e:
upload_form.add_error("file", e)
return {
"upload_form": upload_form,
}
else:
return {
"upload_form": upload_form,
}
# Always return a blank upload form unless the upload form is not valid.
return {
"upload_form": UploadForm(
uploader_list=uploader_list,
initial=dict(user_id=request.user.id)
),
}
开发者ID:ainslied,项目名称:pootle,代码行数:66,代码来源:views.py
注:本文中的pootle.core.delegate.language_team.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论