def upload_raw_excel_translations(self, excel_headers, excel_data, expected_messages=None):
        """
        Prepares bulk app translation excel file and uploads it

        Structure of the xlsx file can be specified as following

        excel_headers:
         (("employee", ("id", "name", "gender")),
          ("building", ("id", "name", "address")))

        excel_data:
         (("employee", (("1", "cory", "m"),
                        ("2", "christian", "m"),
                        ("3", "amelia", "f"))),
          ("building", (("1", "dimagi", "585 mass ave."),
                        ("2", "old dimagi", "529 main st."))))
        """
        if not expected_messages:
            expected_messages = ["App Translations Updated!"]

        file = StringIO()
        export_raw(excel_headers, excel_data, file, format=Format.XLS_2007)

        with tempfile.TemporaryFile(suffix='.xlsx') as f:
            f.write(file.getvalue())
            messages = process_bulk_app_translation_upload(self.app, f)

        self.assertListEqual(
            [m[1] for m in messages], expected_messages
        )
    def upload_raw_excel_translations(self,
                                      excel_headers,
                                      excel_data,
                                      expected_messages=None):
        """
        Prepares bulk app translation excel file and uploads it

        Structure of the xlsx file can be specified as following

        excel_headers:
         (("employee", ("id", "name", "gender")),
          ("building", ("id", "name", "address")))

        excel_data:
         (("employee", (("1", "cory", "m"),
                        ("2", "christian", "m"),
                        ("3", "amelia", "f"))),
          ("building", (("1", "dimagi", "585 mass ave."),
                        ("2", "old dimagi", "529 main st."))))
        """
        if not expected_messages:
            expected_messages = ["App Translations Updated!"]

        file = StringIO()
        export_raw(excel_headers, excel_data, file, format=Format.XLS_2007)

        with tempfile.TemporaryFile(suffix='.xlsx') as f:
            f.write(file.getvalue())
            messages = process_bulk_app_translation_upload(self.app, f)

        self.assertListEqual([m[1] for m in messages], expected_messages)
    def test_upload(self):
        with codecs.open(os.path.join(
                os.path.dirname(__file__), "data",
                "bulk_app_translations.xlsx")) as f:
            messages = process_bulk_app_translation_upload(self.app, f)
            self.assertListEqual(
                [m[1] for m in messages],
                ["App Translations Updated!"]
            )

        form = self.app.get_module(0).get_form(0)

        labels = {}
        for lang in self.app.langs:
            for question in form.get_questions(
                    [lang], include_triggers=True, include_groups=True):
                labels[(question['value'], lang)] = question['label']

        self.assertEqual(labels[("/data/question1", "en")], "in english")
        self.assertEqual(labels[("/data/question1", "fra")], "in french")

        module = self.app.get_module(0)
        self.assertEqual(
            module.case_details.long.columns[1].enum[0].value['fra'],
            'french bar'
        )
        self.assertEqual(
            module.case_details.short.columns[0].header['fra'],
            'Nom'
        )
    def test_no_change_upload(self):
        with codecs.open(os.path.join(
                os.path.dirname(__file__), "data",
                "bulk_app_translations_no_change.xlsx")) as f:
            messages = process_bulk_app_translation_upload(self.app, f)

        self.assertListEqual(
            [m[1] for m in messages], ["App Translations Updated!"]
        )
示例#5
0
def upload_bulk_app_translations(request, domain, app_id):
    app = get_app(domain, app_id)
    msgs = process_bulk_app_translation_upload(app, request.file)
    app.save()
    for msg in msgs:
        # Add the messages to the request object.
        # msg[0] should be a function like django.contrib.messages.error .
        # mes[1] should be a string.
        msg[0](request, msg[1])
    return HttpResponseRedirect(reverse('app_languages', args=[domain,
                                                               app_id]))
示例#6
0
def upload_bulk_app_translations(request, domain, app_id):
    app = get_app(domain, app_id)
    msgs = process_bulk_app_translation_upload(app, request.file)
    app.save()
    for msg in msgs:
        # Add the messages to the request object.
        # msg[0] should be a function like django.contrib.messages.error .
        # mes[1] should be a string.
        msg[0](request, msg[1])
    return HttpResponseRedirect(
        reverse('app_languages', args=[domain, app_id])
    )
    def do_upload(self, name, expected_messages=None):
        """
        Upload the bulk app translation file at file_path + upload.xlsx
        """
        if not expected_messages:
            expected_messages = ["App Translations Updated!"]

        with codecs.open(self.get_path(name, "xlsx")) as f:
            messages = process_bulk_app_translation_upload(self.app, f)

        self.assertListEqual(
            [m[1] for m in messages], expected_messages
        )
    def do_upload(self, name, expected_messages=None):
        """
        Upload the bulk app translation file at file_path + upload.xlsx

        Note: Use upload_raw_excel_translations() instead. It allows easy modifications
        and diffs of xlsx data.

        """
        if not expected_messages:
            expected_messages = ["App Translations Updated!"]

        with codecs.open(self.get_path(name, "xlsx")) as f:
            messages = process_bulk_app_translation_upload(self.app, f)

        self.assertListEqual([m[1] for m in messages], expected_messages)
示例#9
0
    def do_upload(self, name, expected_messages=None):
        """
        Upload the bulk app translation file at file_path + upload.xlsx

        Note: Use upload_raw_excel_translations() instead. It allows easy modifications
        and diffs of xlsx data.

        """
        if not expected_messages:
            expected_messages = ["App Translations Updated!"]

        with codecs.open(self.get_path(name, "xlsx")) as f:
            messages = process_bulk_app_translation_upload(self.app, f)

        self.assertListEqual(
            [m[1] for m in messages], expected_messages
        )
    def do_upload(self, name, expected_messages=None):
        """
        Upload the bulk app translation file at file_path + upload.xlsx

        Note: Use upload_raw_excel_translations() instead. It allows easy modifications
        and diffs of xlsx data.

        ToDo: Refactor tests using do_upload to use upload_raw_excel_translations(), use
        WorkbookJSONReader.work_book_headers_as_tuples(), and
        WorkbookJSONReader.work_book_data_as_tuples(), for making tuples from excel files
        """
        if not expected_messages:
            expected_messages = ["App Translations Updated!"]

        with codecs.open(self.get_path(name, "xlsx")) as f:
            messages = process_bulk_app_translation_upload(self.app, f)

        self.assertListEqual(
            [m[1] for m in messages], expected_messages
        )
    def do_upload(self, name, expected_messages=None):
        """
        Upload the bulk app translation file at file_path + upload.xlsx

        Note: Use upload_raw_excel_translations() instead. It allows easy modifications
        and diffs of xlsx data.

        ToDo: Refactor tests using do_upload to use upload_raw_excel_translations(), use
        WorkbookJSONReader.work_book_headers_as_tuples(), and
        WorkbookJSONReader.work_book_data_as_tuples(), for making tuples from excel files
        """
        if not expected_messages:
            expected_messages = ["App Translations Updated!"]

        with codecs.open(self.get_path(name, "xlsx")) as f:
            messages = process_bulk_app_translation_upload(self.app, f)

        self.assertListEqual(
            [m[1] for m in messages], expected_messages
        )
 def test_removing_form_translations(self):
     app = Application.wrap(self.get_json("app"))
     with codecs.open(self.get_path("modifications", "xlsx")) as f:
         process_bulk_app_translation_upload(app, f)
     form = app.get_module(0).get_form(0)
     self.assertXmlEqual(self.get_xml("expected_form"), form.render_xform())