def language_index(request, language_code): language = get_object_or_404(Language, code=language_code) request.permissions = get_matching_permissions(get_profile(request.user), language.directory) if not check_permission("view", request): raise PermissionDenied projects = language.translationproject_set.order_by('project__fullname') projectcount = len(projects) items = (make_project_item(translate_project) for translate_project in projects.iterator()) totals = language.getquickstats() average = nice_percentage(totals['translatedsourcewords'] * 100.0 / max(totals['totalsourcewords'], 1)) topstats = gentopstats_language(language) templatevars = { 'language': { 'code': language.code, 'name': tr_lang(language.fullname), 'stats': ungettext('%(projects)d project, %(average)d%% translated', '%(projects)d projects, %(average)d%% translated', projectcount, {"projects": projectcount, "average": average}), }, 'feed_path': '%s/' % language.code, 'projects': items, 'statsheadings': get_stats_headings(), 'topstats': topstats, 'instancetitle': pagelayout.get_title(), } return render_to_response("language/language_index.html", templatevars, context_instance=RequestContext(request))
def GET(self, template_vars, request, translation_project, directory): user_profile = get_profile(request.user) tp_dir = translation_project.directory project = translation_project.project language = translation_project.language is_terminology = project.is_terminology description = translation_project.description directory_stats = get_raw_stats(directory) directory_summary = get_directory_summary(directory, directory_stats) template_vars.update({ 'translation_project': translation_project, 'description': description, 'project': project, 'language': language, 'directory': directory, 'children': get_children(request, translation_project, directory), 'dir_summary': directory_summary, 'stats': directory_stats, 'stats_headings': get_stats_headings(), 'topstats': gentopstats_translation_project(translation_project), 'feed_path': directory.pootle_path[1:], }) if check_permission('administrate', request): from pootle_translationproject.forms import DescriptionForm template_vars['form'] = DescriptionForm(instance=translation_project) return template_vars
def project_language_index(request, project_code): """page listing all languages added to project""" project = get_object_or_404(Project, code=project_code) request.permissions = get_matching_permissions(get_profile(request.user), project.directory) if not check_permission('view', request): raise PermissionDenied translation_projects = project.translationproject_set.all() items = [make_language_item(request, translation_project) for translation_project in translation_projects.iterator()] items.sort(lambda x, y: locale.strcoll(x['title'], y['title'])) languagecount = len(translation_projects) totals = add_percentages(project.getquickstats()) average = totals['translatedpercentage'] topstats = gentopstats_project(project) templatevars = { 'project': { 'code': project.code, 'name': project.fullname, 'stats': ungettext('%(languages)d language, %(average)d%% translated', '%(languages)d languages, %(average)d%% translated', languagecount, {"languages": languagecount, "average": average}), }, 'description': project.description, 'adminlink': _('Admin'), 'languages': items, 'instancetitle': pagelayout.get_title(), 'topstats': topstats, 'statsheadings': get_stats_headings(), 'translationlegend': {'translated': _('Translations are complete'), 'fuzzy': _('Translations need to be checked (they are marked fuzzy)'), 'untranslated': _('Untranslated')}, } return render_to_response('project/project.html', templatevars, context_instance=RequestContext(request))
def language_index(request, language_code): language = get_object_or_404(Language, code=language_code) request.permissions = get_matching_permissions(get_profile(request.user), language.directory) if not check_permission("view", request): raise PermissionDenied projects = language.translationproject_set.order_by('project__fullname') projectcount = len(projects) items = (make_project_item(translate_project) for translate_project in projects.iterator()) totals = language.getquickstats() average = nice_percentage(totals['translatedsourcewords'] * 100.0 / max(totals['totalsourcewords'], 1)) topstats = gentopstats_language(language) templatevars = { 'language': { 'code': language.code, 'name': tr_lang(language.fullname), 'description': language.description, 'stats': ungettext('%(projects)d project, %(average)d%% translated', '%(projects)d projects, %(average)d%% translated', projectcount, {"projects": projectcount, "average": average}), }, 'feed_path': '%s/' % language.code, 'description': language.description, 'projects': items, 'statsheadings': get_stats_headings(), 'topstats': topstats, } if check_permission('administrate', request): from pootle_language.forms import DescriptionForm templatevars['form'] = DescriptionForm(instance=language) return render_to_response("language/language_index.html", templatevars, context_instance=RequestContext(request))
def GET(self, template_vars, request, translation_project, directory): template_vars = super(ProjectIndexView, self).GET(template_vars, request) request.permissions = get_matching_permissions( get_profile(request.user), translation_project.directory) state = dispatch.ProjectIndexState(request.GET) project = translation_project.project language = translation_project.language template_vars.update({ 'translation_project': translation_project, 'project': project, 'language': language, 'directory': directory, 'children': get_children(request, translation_project, directory), 'navitems': [navbar_dict.make_directory_navbar_dict(request, directory)], 'stats_headings': get_stats_headings(), 'editing': state.editing, 'topstats': gentopstats_translation_project(translation_project), 'feed_path': directory.pootle_path[1:], }) return template_vars
def GET(self, template_vars, request, translation_project, directory, store=None): can_edit = check_permission('administrate', request) project = translation_project.project language = translation_project.language path_obj = store or directory path_stats = get_raw_stats(path_obj, include_suggestions=True) path_summary = get_path_summary(path_obj, path_stats) actions = action_groups(request, path_obj, path_stats=path_stats) template_vars.update({ 'translation_project': translation_project, 'project': project, 'language': language, 'directory': directory, 'path_summary': path_summary, 'stats': path_stats, 'stats_headings': get_stats_headings(), 'topstats': gentopstats_translation_project(translation_project), 'feed_path': directory.pootle_path[1:], 'action_groups': actions, 'can_edit': can_edit, }) if store is not None: template_vars.update({'store': store}) else: template_vars.update({ 'children': get_children(request, translation_project, directory) }) if can_edit: from pootle_translationproject.forms import DescriptionForm template_vars['form'] = DescriptionForm( instance=translation_project) return template_vars
def project_language_index(request, project_code): """page listing all languages added to project""" project = get_object_or_404(Project, code=project_code) request.permissions = get_matching_permissions(get_profile(request.user), project.directory) if not check_permission('view', request): raise PermissionDenied can_edit = check_permission('administrate', request) translation_projects = project.translationproject_set.all() items = [make_language_item(request, translation_project) \ for translation_project in translation_projects.iterator()] items.sort(lambda x, y: locale.strcoll(x['title'], y['title'])) languagecount = len(translation_projects) project_stats = get_raw_stats(project) average = project_stats['translated']['percentage'] topstats = gentopstats_project(project) templatevars = { 'project': { 'code': project.code, 'name': project.fullname, 'description_html': project.description_html, 'summary': ungettext('%(languages)d language, %(average)d%% translated', '%(languages)d languages, %(average)d%% translated', languagecount, { "languages": languagecount, "average": average }), }, 'languages': items, 'topstats': topstats, 'statsheadings': get_stats_headings(), 'can_edit': can_edit, } if can_edit: from pootle_project.forms import DescriptionForm templatevars['form'] = DescriptionForm(instance=project) return render_to_response('project/project.html', templatevars, context_instance=RequestContext(request))
def GET(self, template_vars, request, translation_project, directory, store=None): user_profile = get_profile(request.user) tp_dir = translation_project.directory can_edit = check_permission('administrate', request) project = translation_project.project language = translation_project.language is_terminology = project.is_terminology path_obj = store or directory # Build URL for getting more summary information for the current path url_args = [language.code, project.code, directory.path] if store: url_args.append(store.name) url_path_summary_more = reverse('tp.path_summary_more', args=url_args) path_stats = get_raw_stats(path_obj, include_suggestions=True) path_summary = get_path_summary(path_obj, path_stats) template_vars.update({ 'translation_project': translation_project, 'project': project, 'language': language, 'directory': directory, 'path_summary': path_summary, 'url_path_summary_more': url_path_summary_more, 'stats': path_stats, 'stats_headings': get_stats_headings(), 'topstats': gentopstats_translation_project(translation_project), 'feed_path': directory.pootle_path[1:], 'action_groups': action_groups(request, path_obj), 'can_edit': can_edit, }) if store is not None: template_vars.update({ 'store': store }) else: template_vars.update({ 'children': get_children(request, translation_project, directory) }) if can_edit: from pootle_translationproject.forms import DescriptionForm template_vars['form'] = DescriptionForm(instance=translation_project) return template_vars
def project_language_index(request, project_code): """page listing all languages added to project""" project = get_object_or_404(Project, code=project_code) request.permissions = get_matching_permissions(get_profile(request.user), project.directory) if not check_permission('view', request): raise PermissionDenied translation_projects = project.translationproject_set.all() items = [ make_language_item(request, translation_project) for translation_project in translation_projects.iterator() ] items.sort(lambda x, y: locale.strcoll(x['title'], y['title'])) languagecount = len(translation_projects) totals = add_percentages(project.getquickstats()) average = totals['translatedpercentage'] topstats = gentopstats_project(project) templatevars = { 'project': { 'code': project.code, 'name': project.fullname, 'stats': ungettext('%(languages)d language, %(average)d%% translated', '%(languages)d languages, %(average)d%% translated', languagecount, { "languages": languagecount, "average": average }), }, 'description': project.description, 'adminlink': _('Admin'), 'languages': items, 'instancetitle': pagelayout.get_title(), 'topstats': topstats, 'statsheadings': get_stats_headings(), 'translationlegend': { 'translated': _('Translations are complete'), 'fuzzy': _('Translations need to be checked (they are marked fuzzy)'), 'untranslated': _('Untranslated') }, } return render_to_response('project/project.html', templatevars, context_instance=RequestContext(request))
def project_language_index(request, project_code): """page listing all languages added to project""" project = get_object_or_404(Project, code=project_code) request.permissions = get_matching_permissions(get_profile(request.user), project.directory) if not check_permission('view', request): raise PermissionDenied # Check for form post (MT request) if request.method == "POST": # TODO: This is not the correct way to handle one of many forms. How do I do it better? # TODO: This is not save against injection attacks. # translation_request_form = TranslationRequestForm(None, request.POST) # Get the project translator = MachineTranslator.objects.get(pk = request.POST['translator']) translation_project = TranslationProject.objects.get( pk = request.POST['translation_project']) translator.create_translation_request(translation_project) return HttpResponseRedirect("?translator=%s&project=%s" % (translator, translation_project)) translation_projects = project.translationproject_set.all() items = [make_language_item(request, project.source_language, translation_project) for translation_project in translation_projects.iterator()] items.sort(lambda x, y: locale.strcoll(x['title'], y['title'])) languagecount = len(translation_projects) totals = add_percentages(project.getquickstats()) average = totals['translatedpercentage'] topstats = gentopstats_project(project) templatevars = { 'project': { 'code': project.code, 'name': project.fullname, 'stats': ungettext('%(languages)d language, %(average)d%% translated', '%(languages)d languages, %(average)d%% translated', languagecount, {"languages": languagecount, "average": average}), }, 'description': project.description, 'adminlink': _('Admin'), 'languages': items, 'templates_code': Language.objects.get_by_natural_key('templates').code, 'instancetitle': pagelayout.get_title(), 'topstats': topstats, 'statsheadings': get_stats_headings(), 'translationlegend': {'translated': _('Translations are complete'), 'fuzzy': _('Translations need to be checked (they are marked fuzzy)'), 'untranslated': _('Untranslated')}, } return render_to_response('project/project.html', templatevars, context_instance=RequestContext(request))
def project_language_index(request, project_code): """page listing all languages added to project""" project = get_object_or_404(Project, code=project_code) request.permissions = get_matching_permissions( get_profile(request.user), project.directory ) if not check_permission('view', request): raise PermissionDenied can_edit = check_permission('administrate', request) translation_projects = project.translationproject_set.all() items = [make_language_item(request, translation_project) \ for translation_project in translation_projects.iterator()] items.sort(lambda x, y: locale.strcoll(x['title'], y['title'])) languagecount = len(translation_projects) project_stats = get_raw_stats(project) average = project_stats['translated']['percentage'] topstats = gentopstats_project(project) templatevars = { 'project': { 'code': project.code, 'name': project.fullname, 'description_html': project.description_html, 'summary': ungettext('%(languages)d language, %(average)d%% translated', '%(languages)d languages, %(average)d%% translated', languagecount, {"languages": languagecount, "average": average}), }, 'languages': items, 'topstats': topstats, 'statsheadings': get_stats_headings(), 'can_edit': can_edit, } if can_edit: from pootle_project.forms import DescriptionForm templatevars['form'] = DescriptionForm(instance=project) return render_to_response('project/project.html', templatevars, context_instance=RequestContext(request))
def GET(self, template_vars, request, translation_project, directory): template_vars = super(ProjectIndexView, self).GET(template_vars, request) request.permissions = get_matching_permissions( get_profile(request.user), translation_project.directory) state = dispatch.ProjectIndexState(request.GET) project = translation_project.project language = translation_project.language is_terminology = project.is_terminology description = translation_project.description directory_stats = get_raw_directory_stats(directory) directory_summary = get_directory_summary(directory, directory_stats) template_vars.update({ 'translation_project': translation_project, 'description': description, 'project': project, 'language': language, 'directory': directory, 'children': get_children(request, translation_project, directory), 'dir_summary': directory_summary, 'stats_headings': get_stats_headings(), 'topstats': gentopstats_translation_project(translation_project), 'feed_path': directory.pootle_path[1:], }) if check_permission('administrate', request): from pootle_translationproject.forms import DescriptionForm template_vars['form'] = DescriptionForm( instance=translation_project) return template_vars
def GET(self, template_vars, request, translation_project, directory, store=None): can_edit = check_permission('administrate', request) project = translation_project.project language = translation_project.language path_obj = store or directory path_stats = get_raw_stats(path_obj, include_suggestions=True) path_summary = get_path_summary(path_obj, path_stats) actions = action_groups(request, path_obj, path_stats=path_stats) template_vars.update({ 'translation_project': translation_project, 'project': project, 'language': language, 'directory': directory, 'path_summary': path_summary, 'stats': path_stats, 'stats_headings': get_stats_headings(), 'topstats': gentopstats_translation_project(translation_project), 'feed_path': directory.pootle_path[1:], 'action_groups': actions, 'can_edit': can_edit, }) if store is not None: template_vars.update({ 'store': store }) else: template_vars.update({ 'children': get_children(request, translation_project, directory) }) if can_edit: from pootle_translationproject.forms import DescriptionForm template_vars['form'] = DescriptionForm(instance=translation_project) return template_vars
def GET(self, template_vars, request, translation_project, directory): template_vars = super(ProjectIndexView, self).GET(template_vars, request) request.permissions = get_matching_permissions(get_profile(request.user), translation_project.directory) state = dispatch.ProjectIndexState(request.GET) project = translation_project.project language = translation_project.language template_vars.update({ 'translation_project': translation_project, 'project': project, 'language': language, 'directory': directory, 'children': get_children(request, translation_project, directory), 'navitems': [navbar_dict.make_directory_navbar_dict(request, directory)], 'stats_headings': get_stats_headings(), 'editing': state.editing, 'topstats': gentopstats_translation_project(translation_project), 'feed_path': directory.pootle_path[1:], }) return template_vars
def project_language_index(request, project_code): """page listing all languages added to project with the possibility to add new ones""" import logging current_project = get_object_or_404(Project, code=project_code) request.permissions = get_matching_permissions(get_profile(request.user), current_project.directory) #TODO: maybe find a clever way to check permission if not check_permission('view', request): raise PermissionDenied #load the current project class TranslationProjectForm(forms.ModelForm): #since the user has already selected the project he wants to add the languages to #we hide the field of the project reference project = forms.ModelChoiceField(queryset=Project.objects.filter(pk=current_project.pk), initial=current_project.pk, widget=forms.HiddenInput) #form will be based on/extend the TranslationProject object class Meta: model = TranslationProject if request.method == 'POST': # If the form has been submitted... form = TranslationProjectForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass #proceed with filling in the form values exactly as in the model logging.debug("Saving form") translation_project = form.save() #generate the empty .po translation file for the new language #based on the template translation_project.update_from_templates() translation_project.getcompletestats() translation_project.getquickstats() openproject = translation_project.project current_project = translation_project.project return HttpResponseRedirect( openproject._get_pootle_path() ) # Redirect after POST else: form = TranslationProjectForm() # An unbound form logging.debug("Unbound form") logging.debug("%s, %s, ", current_project.code, current_project.fullname ) translation_projects = current_project.translationproject_set.all() items = [make_language_item(request, translation_project) for translation_project in translation_projects.iterator()] items.sort(lambda x, y: locale.strcoll(x['title'], y['title'])) languagecount = len(translation_projects) totals = add_percentages(current_project.getquickstats()) average = totals['translatedpercentage'] topstats = gentopstats_project(current_project) templatevars = { 'form' : form, 'project': { 'code': current_project.code, 'name': current_project.fullname, 'stats': ungettext('%(languages)d language, %(average)d%% translated', '%(languages)d languages, %(average)d%% translated', languagecount, {"languages": languagecount, "average": average}) }, 'description': current_project.description, 'adminlink': _('Admin'), 'languages': items, 'instancetitle': pagelayout.get_title(), 'topstats': topstats, 'statsheadings': get_stats_headings(), 'translationlegend': {'translated': _('Translations are complete'), 'fuzzy': _('Translations need to be checked (they are marked fuzzy)' ), 'untranslated': _('Untranslated')}, } return render_to_response( 'project/project_edit.html', templatevars, context_instance=RequestContext(request) )
def project_language_index(request, project_code): """page listing all languages added to project""" project = get_object_or_404(Project, code=project_code) request.permissions = get_matching_permissions(get_profile(request.user), project.directory) if not check_permission('view', request): raise PermissionDenied # Check for form post (MT request) if request.method == "POST": # TODO: This is not the correct way to handle one of many forms. How do I do it better? # TODO: This is not save against injection attacks. # translation_request_form = TranslationRequestForm(None, request.POST) # Get the project translator = MachineTranslator.objects.get( pk=request.POST['translator']) translation_project = TranslationProject.objects.get( pk=request.POST['translation_project']) translator.create_translation_request(translation_project) return HttpResponseRedirect("?translator=%s&project=%s" % (translator, translation_project)) translation_projects = project.translationproject_set.all() items = [ make_language_item(request, project.source_language, translation_project) for translation_project in translation_projects.iterator() ] items.sort(lambda x, y: locale.strcoll(x['title'], y['title'])) languagecount = len(translation_projects) totals = add_percentages(project.getquickstats()) average = totals['translatedpercentage'] topstats = gentopstats_project(project) templatevars = { 'project': { 'code': project.code, 'name': project.fullname, 'stats': ungettext('%(languages)d language, %(average)d%% translated', '%(languages)d languages, %(average)d%% translated', languagecount, { "languages": languagecount, "average": average }), }, 'description': project.description, 'adminlink': _('Admin'), 'languages': items, 'templates_code': Language.objects.get_by_natural_key('templates').code, 'instancetitle': pagelayout.get_title(), 'topstats': topstats, 'statsheadings': get_stats_headings(), 'translationlegend': { 'translated': _('Translations are complete'), 'fuzzy': _('Translations need to be checked (they are marked fuzzy)'), 'untranslated': _('Untranslated') }, } return render_to_response('project/project.html', templatevars, context_instance=RequestContext(request))