Exemplo n.º 1
0
 def test_extensions(self):
     for method in registry.available_methods:
         if method == 'POT':
             continue
         self.resource.i18n_method = method
         correct_extensions = registry.extensions_for(method)
         for lang in ('en', 'el'):
             extension_returned = registry.file_extension_for(
                 self.resource, lang
             )
             self.assertIn(extension_returned, correct_extensions)
Exemplo n.º 2
0
 def to_http_for_get(cls, translation, result):
     response = HttpResponse(result,
                             mimetype=registry.mimetypes_for(
                                 translation.resource.i18n_method)[0])
     response['Content-Disposition'] = (
         'attachment; filename*="UTF-8\'\'%s_%s%s"' %
         (urllib.quote(translation.resource.name.encode('UTF-8')),
          translation.language.code,
          registry.file_extension_for(translation.resource,
                                      translation.language)))
     return response
Exemplo n.º 3
0
    def test_po_extensions(self):
        """Test PO/POT extensions.

        If language is None: extension == 'pot'.
        """
        self.resource.i18n_method = 'PO'
        for lang in ('en', 'el', None):
            extension = registry.file_extension_for(self.resource, lang)
            if lang is None:
                self.assertEqual(extension, registry.extensions_for('POT')[0])
            else:
                self.assertEqual(extension, registry.extensions_for('PO')[0])
Exemplo n.º 4
0
 def to_http_for_get(cls, translation, result):
     response = HttpResponse(
         result, mimetype=registry.mimetypes_for(
             translation.resource.i18n_method
         )[0]
     )
     response['Content-Disposition'] = (
         'attachment; filename*="UTF-8\'\'%s_%s%s"' % (
             urllib.quote(translation.resource.name.encode('UTF-8')),
             translation.language.code,
             registry.file_extension_for(
                 translation.resource, translation.language
             )
         )
     )
     return response
Exemplo n.º 5
0
        template = fb.compile_translation(**kwargs)
    except Exception, e:
        messages.error(request, "Error compiling translation file.")
        logger.error("Error compiling '%s' file for '%s': %s" % (language,
            resource, str(e)))
        return HttpResponseRedirect(reverse('resource_detail',
            args=[resource.project.slug, resource.slug]),)

    response = HttpResponse(
        template, mimetype=registry.mimetypes_for(resource.i18n_method)[0]
    )
    _filename = "%(proj)s_%(res)s_%(lang)s%(type)s" % {
        'proj': smart_unicode(resource.project.slug),
        'res': smart_unicode(resource.slug),
        'lang': language.code,
        'type': registry.file_extension_for(resource, language)
    }

    # Prefix filename with mode, case it exists
    if kwargs.has_key('mode'):
        _filename = "%s_" % kwargs.get('mode').label + _filename

    response['Content-Disposition'] = ('attachment; filename=%s' % _filename)
    return response


# Restrict access only for private projects
# DONT allow anonymous access
@login_required
@one_perm_required_or_403(pr_project_private_perm,
    (Project, 'slug__exact', 'project_slug'))
Exemplo n.º 6
0
    except Exception, e:
        messages.error(request, "Error compiling translation file.")
        logger.error("Error compiling '%s' file for '%s': %s" %
                     (language, resource, str(e)))
        return HttpResponseRedirect(
            reverse('resource_detail',
                    args=[resource.project.slug, resource.slug]), )

    response = HttpResponse(template,
                            mimetype=registry.mimetypes_for(
                                resource.i18n_method)[0])
    _filename = "%(proj)s_%(res)s_%(lang)s%(type)s" % {
        'proj': smart_unicode(resource.project.slug),
        'res': smart_unicode(resource.slug),
        'lang': language.code,
        'type': registry.file_extension_for(resource, language)
    }

    # Prefix filename with mode, case it exists
    if kwargs.has_key('mode'):
        _filename = "%s_" % kwargs.get('mode').label + _filename

    response['Content-Disposition'] = ('attachment; filename=%s' % _filename)
    return response


# Restrict access only for private projects
# DONT allow anonymous access
@login_required
@one_perm_required_or_403(pr_project_private_perm,
                          (Project, 'slug__exact', 'project_slug'))