Example #1
0
def change_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    if not can_edit_subproject(request.user, obj.project):
        raise Http404()

    if request.method == 'POST':
        settings_forms = [
            form(request.POST, instance=obj) for form in SUBPROJECT_SETTINGS
        ]
        if all([form.is_valid() for form in settings_forms]):
            for form in settings_forms:
                form.save()
            messages.success(request, _('Settings saved'))
            return redirect(
                'settings', project=obj.project.slug, subproject=obj.slug
            )
        else:
            messages.error(
                request,
                _('Invalid settings, please check the form for errors!')
            )
    else:
        settings_forms = [form(instance=obj) for form in SUBPROJECT_SETTINGS]

    return render(
        request,
        'subproject-settings.html',
        {
            'project': obj.project,
            'object': obj,
            'settings_forms': settings_forms,
        }
    )
Example #2
0
def change_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    if not can_edit_subproject(request.user, obj.project):
        raise Http404()

    if request.method == 'POST':
        form = SubprojectSettingsForm(request.POST, instance=obj)
        if form.is_valid():
            form.save()
            messages.success(request, _('Settings saved'))
            return redirect(
                'settings', project=obj.project.slug, subproject=obj.slug
            )
        else:
            messages.error(
                request,
                _('Invalid settings, please check the form for errors!')
            )
    else:
        form = SubprojectSettingsForm(instance=obj)

    return render(
        request,
        'subproject-settings.html',
        {
            'project': obj.project,
            'object': obj,
            'form': form,
        }
    )
Example #3
0
def show_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    last_changes = Change.objects.for_component(obj)[:10]

    if (request.method == 'POST'
            and can_edit_subproject(request.user, obj.project)):
        settings_form = SubprojectSettingsForm(request.POST, instance=obj)
        if settings_form.is_valid():
            settings_form.save()
            messages.success(request, _('Settings saved'))
            return redirect(obj)
        else:
            messages.error(
                request,
                _('Invalid settings, please check the form for errors!'))
    else:
        settings_form = SubprojectSettingsForm(instance=obj)

    try:
        sample = obj.translation_set.all()[0]
        source_words = sample.total_words
        total_strings = sample.total
    except IndexError:
        source_words = 0
        total_strings = 0

    if can_translate(request.user, project=obj.project):
        replace_form = ReplaceForm()
    else:
        replace_form = None

    return render(
        request, 'subproject.html', {
            'object':
            obj,
            'project':
            obj.project,
            'translations':
            sort_objects(obj.translation_set.enabled()),
            'show_language':
            1,
            'reports_form':
            ReportsForm(),
            'last_changes':
            last_changes,
            'last_changes_url':
            urlencode({
                'subproject': obj.slug,
                'project': obj.project.slug
            }),
            'settings_form':
            settings_form,
            'unit_count':
            Unit.objects.filter(translation__subproject=obj).count(),
            'words_count':
            obj.get_total_words(),
            'language_count':
            Language.objects.filter(
                translation__subproject=obj).distinct().count(),
            'strings_count':
            total_strings,
            'source_words_count':
            source_words,
            'replace_form':
            replace_form,
            'search_form':
            SearchForm(),
        })
Example #4
0
 def get_queryset(self):
     component = self.get_component()
     if not can_edit_subproject(self.request.user, component.project):
         raise PermissionDenied('Can not edit component')
     self.kwargs['component'] = component
     return Addon.objects.filter(component=component)
Example #5
0
def show_subproject(request, project, subproject):
    obj = get_subproject(request, project, subproject)

    last_changes = Change.objects.for_component(obj)[:10]

    if (request.method == 'POST' and
            can_edit_subproject(request.user, obj.project)):
        settings_form = SubprojectSettingsForm(request.POST, instance=obj)
        if settings_form.is_valid():
            settings_form.save()
            messages.success(request, _('Settings saved'))
            return redirect(obj)
        else:
            messages.error(
                request,
                _('Invalid settings, please check the form for errors!')
            )
    else:
        settings_form = SubprojectSettingsForm(instance=obj)

    try:
        sample = obj.translation_set.all()[0]
        source_words = sample.total_words
        total_strings = sample.total
    except IndexError:
        source_words = 0
        total_strings = 0

    if can_translate(request.user, project=obj.project):
        replace_form = ReplaceForm()
    else:
        replace_form = None

    return render(
        request,
        'subproject.html',
        {
            'allow_index': True,
            'object': obj,
            'project': obj.project,
            'translations': sort_objects(obj.translation_set.enabled()),
            'show_language': 1,
            'reports_form': ReportsForm(),
            'last_changes': last_changes,
            'last_changes_url': urlencode(
                {'subproject': obj.slug, 'project': obj.project.slug}
            ),
            'settings_form': settings_form,
            'unit_count': Unit.objects.filter(
                translation__subproject=obj
            ).count(),
            'words_count': obj.get_total_words(),
            'language_count': Language.objects.filter(
                translation__subproject=obj
            ).distinct().count(),
            'strings_count': total_strings,
            'source_words_count': source_words,
            'replace_form': replace_form,
            'search_form': SearchForm(),
        }
    )