本文整理汇总了Python中pootle_project.models.Project类的典型用法代码示例。如果您正苦于以下问题:Python Project类的具体用法?Python Project怎么用?Python Project使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Project类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_root_view_permissions
def test_no_root_view_permissions(po_directory, nobody, default, admin, view,
no_permission_sets, no_projects,
project_foo, project_bar):
"""Tests user-accessible projects when there are no permissions set at
the root.
"""
ALL_PROJECTS = [project_foo.code, project_bar.code]
foo_user = UserFactory.create(username='foo')
bar_user = UserFactory.create(username='bar')
# By setting explicit `view` permissions for `foo_user` in `project_foo`,
# only `foo_user` will be able to access that project
_require_permission_set(foo_user, project_foo.directory, [view])
assert items_equal(Project.accessible_by_user(admin), ALL_PROJECTS)
assert items_equal(
Project.accessible_by_user(foo_user),
[project_foo.code])
assert items_equal(Project.accessible_by_user(bar_user), [])
assert items_equal(Project.accessible_by_user(default), [])
assert items_equal(Project.accessible_by_user(nobody), [])
# Now let's allow showing `project_bar` to all registered users, but keep
# `project_foo` visible only to `foo_user`.
_require_permission_set(default, project_bar.directory, [view])
assert items_equal(Project.accessible_by_user(admin), ALL_PROJECTS)
assert items_equal(Project.accessible_by_user(foo_user), ALL_PROJECTS)
assert items_equal(
Project.accessible_by_user(bar_user),
[project_bar.code])
assert items_equal(Project.accessible_by_user(default), [project_bar.code])
assert items_equal(Project.accessible_by_user(nobody), [])
示例2: create_default_projects
def create_default_projects():
"""Create the default projects that we host.
You might want to add your projects here, although you can also add things
through the web interface later.
"""
from pootle_project.models import Project
en = require_english()
criteria = {
'code': u"tutorial",
'source_language': en,
'fullname': u"Tutorial",
'checkstyle': "standard",
'localfiletype': "po",
'treestyle': "auto",
}
tutorial = Project(**criteria)
tutorial.save()
criteria = {
'active': True,
'title': "Project instructions",
'body': ('<div dir="ltr" lang="en">Tutorial project where users can '
'play with Pootle and learn more about translation and '
'localisation.<br />For more help on localisation, visit the '
'<a href="http://docs.translatehouse.org/projects/'
'localization-guide/en/latest/guide/start.html">localisation '
'guide</a>.</div>'),
'virtual_path': "announcements/projects/"+tutorial.code,
}
ann = Announcement(**criteria)
ann.save()
示例3: create_default_projects
def create_default_projects():
"""Create the default projects that we host.
You might want to add your projects here, although you can also add things
through the web interface later.
"""
from pootle_app.management import require_english
from pootle_project.models import Project
en = require_english()
#pootle = Project(code=u"pootle", source_language=en)
#pootle.fullname = u"Pootle"
#pootle.description = ('<div dir="ltr" lang="en">Interface translations '
# 'for Pootle. <br /> See the <a href="http://'
# 'pootle.locamotion.org">official Pootle server</a> '
# 'for the translations of Pootle.</div>')
#pootle.checkstyle = "standard"
#pootle.localfiletype = "po"
#pootle.treestyle = "auto"
#pootle.save()
tutorial = Project(code=u"tutorial", source_language=en)
tutorial.fullname = u"Tutorial"
tutorial.description = ('<div dir="ltr" lang="en">Tutorial project where '
'users can play with Pootle and learn more about '
'translation and localisation.<br />For more help '
'on localisation, visit the <a href="http://'
'translate.sourceforge.net/wiki/guide/start">'
'localisation guide</a>.</div>')
tutorial.checkstyle = "standard"
tutorial.localfiletype = "po"
tutorial.treestyle = "auto"
tutorial.save()
示例4: import_projects
def import_projects(parsed_data):
# This could prompt the user, asking:
# "Want us to import projects? Say no if you have already
# added the projects to the new Pootle DB in the web UI."
data = parsed_data.__root__._assignments # Is this really the right way?
prefix = 'Pootle.projects.'
# Filter out unrelated keys
keys = [key for key in data if key.startswith(prefix)]
# Clean up 'pootle.fullname' into 'pootle'
projs = set([key[len(prefix):].split('.')[0] for key in keys])
en = require_english()
for proj in map(lambda s: unicode(s, 'utf-8'), projs):
# id, for free
# code:
try:
db_proj = Project.objects.get(code=proj)
logging.log(logging.INFO,
'Already found a project named %s.\n'\
'Data for this project are not imported.',
proj)
continue
except Project.DoesNotExist:
db_proj = Project(code=proj, source_language=en)
# fullname
db_proj.fullname = _get_attribute(data, proj, 'fullname', prefix=prefix)
# description
db_proj.description = _get_attribute(data, proj, 'description',
prefix=prefix)
# checkstyle
db_proj.checkstyle = _get_attribute(data, proj, 'checkerstyle',
unicode_me = False, prefix=prefix)
# localfiletype
db_proj.localfiletype = _get_attribute(data, proj, 'localfiletype',
default='po', prefix=prefix)
# treestyle
db_proj.treestyle = _get_attribute(data, proj, 'treestyle',
unicode_me = False, default='auto', prefix=prefix)
# ignoredfiles
db_proj.ignoredfiles = _get_attribute(data, proj, 'ignoredfiles',
default=u'', prefix=prefix)
logging.info("Creating project %s", db_proj)
db_proj.save()
示例5: wrapped
def wrapped(request, *args, **kwargs):
language_code = kwargs.pop('language_code', None)
project_code = kwargs.pop('project_code', None)
pootle_path = request.GET.get('path', None)
if pootle_path is not None:
language_code, project_code, dir_path, filename = \
split_pootle_path(pootle_path)
kwargs['dir_path'] = dir_path
kwargs['filename'] = filename
if language_code and project_code:
try:
path_obj = TranslationProject.objects.enabled().get(
language__code=language_code,
project__code=project_code,
project__disabled=False
)
except TranslationProject.DoesNotExist:
path_obj = None
if path_obj is None and not request.is_ajax():
# Explicit selection via the UI: redirect either to
# ``/language_code/`` or ``/projects/project_code/``.
user_choice = request.COOKIES.get('user-choice', None)
if user_choice and user_choice in ('language', 'project',):
url = {
'language': reverse('pootle-language-overview',
args=[language_code]),
'project': reverse('pootle-project-overview',
args=[project_code, '', '']),
}
response = redirect(url[user_choice])
response.delete_cookie('user-choice')
return response
raise Http404
elif language_code:
path_obj = get_object_or_404(Language, code=language_code)
elif project_code:
path_obj = get_object_or_404(Project, code=project_code,
disabled=False)
else: # No arguments: all user-accessible projects
user_projects = Project.accessible_by_user(request.user)
user_projects = Project.objects.enabled() \
.filter(code__in=user_projects)
path_obj = ProjectSet(user_projects, '/projects/')
# HACKISH: inject directory so that permissions can be
# queried
directory = Directory.objects.get(pootle_path='/projects/')
setattr(path_obj, 'directory', directory)
request.ctx_obj = path_obj
request.ctx_path = path_obj.pootle_path
request.resource_obj = path_obj
request.pootle_path = path_obj.pootle_path
return func(request, path_obj, *args, **kwargs)
示例6: is_accessible_by
def is_accessible_by(self, user):
"""Returns `True` if the current unit is accessible by `user`."""
if user.is_superuser:
return True
from pootle_project.models import Project
user_projects = Project.accessible_by_user(user)
return self.store.translation_project.project.code in user_projects
示例7: is_accessible_by
def is_accessible_by(self, user):
"""Returns `True` if the current translation project is accessible
by `user`.
"""
if user.is_superuser:
return True
return self.project.code in Project.accessible_by_user(user)
示例8: _require_project
def _require_project(code, name, source_language):
"""Helper to get/create a new project."""
# XXX: should accept more params, but is enough for now
from pootle_project.models import Project
criteria = {
'code': code,
'fullname': name,
'source_language': source_language,
'checkstyle': 'standard',
'localfiletype': 'po',
'treestyle': 'auto',
}
new_project = Project(**criteria)
new_project.save()
return new_project
示例9: test_view_projects_browse
def test_view_projects_browse(client, request_users):
user = request_users["user"]
client.login(
username=user.username,
password=request_users["password"])
response = client.get(reverse("pootle-projects-browse"))
assert response.cookies["pootle-language"].value == "projects"
ctx = response.context
request = response.wsgi_request
user_projects = Project.accessible_by_user(request.user)
user_projects = (
Project.objects.for_user(request.user)
.filter(code__in=user_projects))
obj = ProjectSet(user_projects)
items = [
make_project_list_item(project)
for project in obj.children]
items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))
table_fields = [
'name', 'progress', 'total', 'need-translation',
'suggestions', 'critical', 'last-updated', 'activity']
table = {
'id': 'projects',
'fields': table_fields,
'headings': get_table_headings(table_fields),
'items': items}
if request.user.is_superuser:
url_action_continue = obj.get_translate_url(state='incomplete')
url_action_fixcritical = obj.get_critical_url()
url_action_review = obj.get_translate_url(state='suggestions')
url_action_view_all = obj.get_translate_url(state='all')
else:
(url_action_continue,
url_action_fixcritical,
url_action_review,
url_action_view_all) = [None] * 4
User = get_user_model()
top_scorers = User.top_scorers(limit=10)
assertions = dict(
page="browse",
pootle_path="/projects/",
resource_path="",
resource_path_parts=[],
object=obj,
table=table,
browser_extends="projects/all/base.html",
stats=obj.data_tool.get_stats(user=request.user),
checks=get_qualitycheck_list(obj),
top_scorers=top_scorers,
top_scorers_data=get_top_scorers_data(top_scorers, 10),
translation_states=get_translation_states(obj),
url_action_continue=url_action_continue,
url_action_fixcritical=url_action_fixcritical,
url_action_review=url_action_review,
url_action_view_all=url_action_view_all)
view_context_test(ctx, **assertions)
示例10: _require_project
def _require_project(code, name, source_language, **kwargs):
"""Helper to get/create a new project."""
from pootle_project.models import Project
criteria = {
'code': code,
'fullname': name,
'source_language': source_language,
'checkstyle': 'standard',
'localfiletype': 'po',
'treestyle': 'auto',
}
criteria.update(kwargs)
new_project = Project(**criteria)
new_project.save()
return new_project
示例11: test_view_projects_browse
def test_view_projects_browse(client, request_users):
user = request_users["user"]
client.login(
username=user.username,
password=request_users["password"])
response = client.get(reverse("pootle-projects-browse"))
assert response.cookies["pootle-language"].value == "projects"
ctx = response.context
request = response.wsgi_request
user_projects = Project.accessible_by_user(request.user)
user_projects = (
Project.objects.for_user(request.user)
.filter(code__in=user_projects))
obj = ProjectSet(user_projects)
stats = obj.data_tool.get_stats(user=request.user)
if request.user.is_superuser:
url_action_continue = obj.get_translate_url(state='incomplete')
url_action_fixcritical = obj.get_critical_url()
url_action_review = obj.get_translate_url(state='suggestions')
url_action_view_all = obj.get_translate_url(state='all')
else:
(url_action_continue,
url_action_fixcritical,
url_action_review,
url_action_view_all) = [None] * 4
checks = ChecksDisplay(obj).checks_by_category
stats = StatsDisplay(obj, stats=stats).stats
del stats["children"]
chunk_size = TOP_CONTRIBUTORS_CHUNK_SIZE
score_data = scores.get(ProjectSet)(obj)
def scores_to_json(score):
score["user"] = score["user"].to_dict()
return score
top_scorers = score_data.display(
limit=chunk_size,
formatter=scores_to_json)
top_scorer_data = dict(
items=list(top_scorers),
has_more_items=len(score_data.top_scorers) > chunk_size)
assertions = dict(
page="browse",
pootle_path="/projects/",
resource_path="",
resource_path_parts=[],
object=obj,
browser_extends="projects/all/base.html",
top_scorers=top_scorer_data,
translation_states=get_translation_states(obj),
url_action_continue=url_action_continue,
url_action_fixcritical=url_action_fixcritical,
url_action_review=url_action_review,
url_action_view_all=url_action_view_all,
checks=checks,
stats=stats)
view_context_test(ctx, **assertions)
示例12: create_default_projects
def create_default_projects():
"""Create the default projects that we host.
You might want to add your projects here, although you can also add things
through the web interface later.
"""
from pootle_project.models import Project
en = require_english()
#criteria = {
# 'code': u"pootle",
# 'source_language': en,
# 'fullname': u"Pootle",
# 'description': ('<div dir="ltr" lang="en">Interface translations for '
# 'Pootle.<br />See the <a href="http://'
# 'pootle.locamotion.org">official Pootle server</a> '
# 'for the translations of Pootle.</div>')
# 'checkstyle': "standard",
# 'localfiletype': "po",
# 'treestyle': "auto",
#}
#pootle = Project(**criteria)
#pootle.save()
criteria = {
'code': u"tutorial",
'source_language': en,
'fullname': u"Tutorial",
'description': ('<div dir="ltr" lang="en">Tutorial project where '
'users can play with Pootle and learn more about '
'translation and localisation.<br />For more help on '
'localisation, visit the <a href="http://'
'docs.translatehouse.org/projects/localization-guide/'
'en/latest/guide/start.html">localisation guide</a>.'
'</div>'),
'checkstyle': "standard",
'localfiletype': "po",
'treestyle': "auto",
}
tutorial = Project(**criteria)
tutorial.save()
示例13: test_no_root_hide_permissions
def test_no_root_hide_permissions(po_directory, nobody, default, admin, hide,
view, no_projects, no_permission_sets,
project_foo, project_bar, root):
"""Tests user-accessible projects when there are no `hide` permissions
set at the root.
"""
ALL_PROJECTS = [project_foo.code, project_bar.code]
foo_user = UserFactory.create(username='foo')
bar_user = UserFactory.create(username='bar')
# By default everyone has access to projects
_require_permission_set(default, root, [view])
_require_permission_set(nobody, root, [view])
# At the same time, `project_foo` is inaccessible registered users...
_require_permission_set(default, project_foo.directory,
negative_permissions=[hide])
assert items_equal(Project.accessible_by_user(admin), ALL_PROJECTS)
assert items_equal(Project.accessible_by_user(default), [project_bar.code])
assert items_equal(Project.accessible_by_user(nobody), [project_bar.code])
assert items_equal(
Project.accessible_by_user(foo_user),
[project_bar.code])
assert items_equal(
Project.accessible_by_user(bar_user),
[project_bar.code])
# ...and anonymous users as well
_require_permission_set(nobody, project_foo.directory,
negative_permissions=[hide])
assert items_equal(Project.accessible_by_user(nobody), [project_bar.code])
# Let's make `project_foo` accessible for `foo_user`
_require_permission_set(foo_user, project_foo.directory, [view])
assert items_equal(Project.accessible_by_user(foo_user), ALL_PROJECTS)
# `project_bar` is now inaccessible for anonymous users
_require_permission_set(nobody, project_bar.directory,
negative_permissions=[hide])
assert items_equal(Project.accessible_by_user(nobody), [])
示例14: notusedsource_to_pootle_project
def notusedsource_to_pootle_project(self):
"""
Constructs a Pootle project from the article, if a project doesn't already exist.
"""
logging.debug ( "source_to_pootle_project" )
from pootle_app.models.signals import post_template_update
if self.pootle_project_exists():
raise Exception("Project %s already exists!" % self.get_project_name())
# Fetch the source_language
sl_set = Language.objects.filter(code = self.language)
if len(sl_set) < 1:
raise Exception("Language code %s does not exist!" % self.language)
source_language = sl_set[0]
logging.debug ( "source language" + source_language )
# Construct the project
project = Project()
project.fullname = self.get_project_name()
project.code = self.get_project_code()
project.source_language = source_language
# Save the project
project.save()
logging.debug ( "project saved")
# Export the article to .po and store in the templates "translation project". This will be used to generate translation requests for other languages.
templatesProject = project.get_template_translationproject()
po = self.sentences_to_po()
poFilePath = "%s/article.pot" % (templatesProject.abs_real_path)
oldstats = templatesProject.getquickstats()
# Write the file
with open(poFilePath, 'w') as f:
f.write(po.__str__())
# Force the project to scan for changes.
templatesProject.scan_files()
templatesProject.update(conservative=False)
# Log the changes
newstats = templatesProject.getquickstats()
post_template_update.send(sender=templatesProject, oldstats=oldstats, newstats=newstats)
return project
示例15: projects_index
def projects_index(request, root):
"""Page listing all projects."""
user_accessible_projects = Project.accessible_by_user(request.user)
user_projects = Project.objects.filter(code__in=user_accessible_projects)
items = [make_project_list_item(project) for project in user_projects]
table_fields = ["name"]
ctx = {
"table": {
"id": "projects",
"fields": table_fields,
"headings": get_table_headings(table_fields),
"items": items,
}
}
return render(request, "projects/list.html", ctx)