示例#1
0
    def test_admin_change_form_language_tabs_urls(self):
        with translation.override('en'):
            with self.login_user_context(username='******', password='******'):
                get_url = reverse('admin:app_normal_change',
                                  args=(self.normal_id[1], ))
                test_urls = [
                    '%s?%s' % (get_url, '_changelist_filters=q%3Dsearchparam'),
                    '%s?%s' %
                    (get_url,
                     '_changelist_filters=q%3Dsearchparam&language=fr'),
                ]

                for test_url in test_urls:
                    response = self.client.get(test_url)
                    self.assertEqual(response.status_code, 200)
                    tabs = response.context['language_tabs']

                    expected_querydict = QueryDict(urlparse(test_url).query,
                                                   mutable=True)

                    for actual_tab_url, name, key, status in tabs:
                        expected_querydict['language'] = key
                        actual_querydict = QueryDict(
                            urlparse(actual_tab_url).query)
                        self.assertEqual(expected_querydict, actual_querydict)
示例#2
0
    def render_change_form(self, request, context, add=False, change=False,
                           form_url='', obj=None):
        lang_code = self._language(request)
        lang = get_language_name(lang_code)
        available_languages = self.get_available_languages(obj)

        context.update({
            'title': '%s (%s)' % (context['title'], lang),
            'current_is_translated': lang_code in available_languages,
            'allow_deletion': len(available_languages) > 1,
            'language_tabs': self.get_language_tabs(request, available_languages),
            'base_template': self.get_change_form_base_template(),
        })

        # Ensure form action url carries over tab language
        qs_language = request.GET.get('language')
        if qs_language:
            form_url = urlparse(form_url or request.get_full_path())
            query = QueryDict(form_url.query, mutable=True)
            if 'language' not in query:
                query['language'] = qs_language
            form_url = form_url._replace(query=query.urlencode()).geturl()

        return super(TranslatableAdmin, self).render_change_form(request,
                                                                  context,
                                                                  add, change,
                                                                  form_url, obj)
示例#3
0
    def render_change_form(self, request, context, add=False, change=False,
                           form_url='', obj=None):
        lang_code = self._language(request)
        lang = get_language_name(lang_code)
        available_languages = self.get_available_languages(obj)
        context.update({
            'title': '%s (%s)' % (context['title'], lang),
            'current_is_translated': lang_code in available_languages,
            'allow_deletion': len(available_languages) > 1,
            'language_tabs': self.get_language_tabs(request, available_languages),
            'base_template': self.get_change_form_base_template(),
        })

        # Ensure form action url carries over tab language
        qs_language = request.GET.get('language')
        if qs_language:
            form_url = urlparse(form_url or request.get_full_path())
            query = QueryDict(form_url.query, mutable=True)
            if 'language' not in query:
                query['language'] = qs_language
            form_url = form_url._replace(query=query.urlencode()).geturl()

        return super(TranslatableAdmin, self).render_change_form(request,
                                                                  context,
                                                                  add, change,
                                                                  form_url, obj)
示例#4
0
    def render_change_form(self, request, context, add=False, change=False, form_url="", obj=None):
        lang_code = self._language(request)
        lang = get_language_name(lang_code)
        available_languages = self.get_available_languages(obj)

        context.update(
            {
                "title": "%s (%s)" % (context["title"], lang),
                "current_is_translated": lang_code in available_languages,
                "allow_deletion": len(available_languages) > 1,
                "language_tabs": self.get_language_tabs(request, available_languages),
                "base_template": self.get_change_form_base_template(),
            }
        )

        # Ensure form action url carries over tab language
        qs_language = request.GET.get("language")
        if qs_language:
            form_url = urlparse(form_url or request.get_full_path())
            query = QueryDict(form_url.query, mutable=True)
            if "language" not in query:
                query["language"] = qs_language
            form_url = form_url._replace(query=query.urlencode()).geturl()

        return super(TranslatableAdmin, self).render_change_form(request, context, add, change, form_url, obj)
示例#5
0
    def test_admin_change_form_language_tabs_urls(self):
        with translation.override('en'):
            with self.login_user_context('admin'):
                get_url = reverse('admin:app_normal_change', args=(self.normal_id[1],))
                test_urls = [
                    '%s?%s' % (get_url, '_changelist_filters=q%3Dsearchparam'),
                    '%s?%s' % (get_url, '_changelist_filters=q%3Dsearchparam&language=fr'),
                ]

                for test_url in test_urls:
                    response = self.client.get(test_url)
                    self.assertEqual(response.status_code, 200)
                    tabs = response.context['language_tabs']

                    expected_querydict = QueryDict(urlparse(test_url).query, mutable=True)

                    for actual_tab_url, name, key, status in tabs:
                        expected_querydict['language'] = key
                        actual_querydict = QueryDict(urlparse(actual_tab_url).query)
                        self.assertEqual(expected_querydict, actual_querydict)
示例#6
0
def parse_database(url):
    url = urlparse(url)
    return {
        'ENGINE': ENGINES[url.scheme],
        'NAME': url.path.strip('/'),
        'HOST': url.hostname,
        'PORT': url.port,
        'USER': url.username,
        'PASSWORD': url.password,
        'CHARSET': 'utf8',
        'COLLATION': 'utf8_general_ci',
    }
示例#7
0
文件: admin.py 项目: Kunpors/dr.pors-
    def test_admin_change_form_language_tabs(self):
        with self.settings(LANGUAGES=(('en', 'English'), ('fr', 'French'),
                                      ('ja', 'Japanese'))):
            with translation.override('en'):
                with self.login_user_context('admin'):
                    url = reverse('admin:app_normal_change',
                                  args=(self.normal_id[1], ))
                    test_data = (
                        {},
                        {
                            '_changelist_filters': 'q=searchparam'
                        },
                        {
                            '_changelist_filters': 'q=searchparam',
                            'language': 'fr'
                        },
                    )

                    for data in test_data:
                        response = self.client.get(url, data=data)
                        self.assertEqual(response.status_code, 200)
                        tabs = response.context['language_tabs']

                        for actual_tab_url, name, key, status, del_url in tabs:
                            self.assertEqual(
                                QueryDict(
                                    urlparse(actual_tab_url).query).dict(),
                                dict(data, language=key))
                            self.assertEqual(url,
                                             urlparse(actual_tab_url).path)
                            self.assertEqual(
                                status, 'current' if key == data.get(
                                    'language', 'en') else 'available'
                                if key in self.translations else 'empty')
                            expected_del_url = reverse(
                                'admin:app_normal_delete_translation',
                                args=(self.normal_id[1], key))
                            self.assertEqual(
                                del_url, expected_del_url
                                if key in self.translations else None)
示例#8
0
 def test_admin_change_form_action_url(self):
     with translation.override('en'):
         with self.login_user_context('admin'):
             url = reverse('admin:app_normal_change', args=(self.normal_id[1],))
             tests = (
                 '',
                 'language=fr',
                 '_changelist_filters=q%3Dparam&language=fr',
             )
             for query_string in tests:
                 expected_dict = QueryDict(query_string)
                 full_url = '%s?%s' % (url, query_string) if query_string else url
                 response = self.client.get(full_url)
                 form_url = urlparse(response.context['form_url'])
                 self.assertEqual(expected_dict, QueryDict(form_url.query),
                                  'query_string=%r' % query_string)