Python django.views.i18n.JavaScriptCatalog.as_view() Examples

The following are 30 code examples of django.views.i18n.JavaScriptCatalog.as_view(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.views.i18n.JavaScriptCatalog , or try the search function .
Example #1
Source File: sites.py    From python with Apache License 2.0 6 votes vote down vote up
def password_change(self, request, extra_context=None):
        """
        Handles the "change password" task -- both form display and validation.
        """
        from django.contrib.admin.forms import AdminPasswordChangeForm
        from django.contrib.auth.views import PasswordChangeView
        url = reverse('admin:password_change_done', current_app=self.name)
        defaults = {
            'form_class': AdminPasswordChangeForm,
            'success_url': url,
            'extra_context': dict(self.each_context(request), **(extra_context or {})),
        }
        if self.password_change_template is not None:
            defaults['template_name'] = self.password_change_template
        request.current_app = self.name
        return PasswordChangeView.as_view(**defaults)(request) 
Example #2
Source File: sites.py    From bioforum with MIT License 6 votes vote down vote up
def password_change(self, request, extra_context=None):
        """
        Handle the "change password" task -- both form display and validation.
        """
        from django.contrib.admin.forms import AdminPasswordChangeForm
        from django.contrib.auth.views import PasswordChangeView
        url = reverse('admin:password_change_done', current_app=self.name)
        defaults = {
            'form_class': AdminPasswordChangeForm,
            'success_url': url,
            'extra_context': dict(self.each_context(request), **(extra_context or {})),
        }
        if self.password_change_template is not None:
            defaults['template_name'] = self.password_change_template
        request.current_app = self.name
        return PasswordChangeView.as_view(**defaults)(request) 
Example #3
Source File: sites.py    From Hands-On-Application-Development-with-PyCharm with MIT License 6 votes vote down vote up
def logout(self, request, extra_context=None):
        """
        Log out the user for the given HttpRequest.

        This should *not* assume the user is already logged in.
        """
        from django.contrib.auth.views import LogoutView
        defaults = {
            'extra_context': {
                **self.each_context(request),
                # Since the user isn't logged out at this point, the value of
                # has_permission must be overridden.
                'has_permission': False,
                **(extra_context or {})
            },
        }
        if self.logout_template is not None:
            defaults['template_name'] = self.logout_template
        request.current_app = self.name
        return LogoutView.as_view(**defaults)(request) 
Example #4
Source File: sites.py    From python with Apache License 2.0 6 votes vote down vote up
def logout(self, request, extra_context=None):
        """
        Logs out the user for the given HttpRequest.

        This should *not* assume the user is already logged in.
        """
        from django.contrib.auth.views import LogoutView
        defaults = {
            'extra_context': dict(
                self.each_context(request),
                # Since the user isn't logged out at this point, the value of
                # has_permission must be overridden.
                has_permission=False,
                **(extra_context or {})
            ),
        }
        if self.logout_template is not None:
            defaults['template_name'] = self.logout_template
        request.current_app = self.name
        return LogoutView.as_view(**defaults)(request) 
Example #5
Source File: sites.py    From Hands-On-Application-Development-with-PyCharm with MIT License 6 votes vote down vote up
def password_change(self, request, extra_context=None):
        """
        Handle the "change password" task -- both form display and validation.
        """
        from django.contrib.admin.forms import AdminPasswordChangeForm
        from django.contrib.auth.views import PasswordChangeView
        url = reverse('admin:password_change_done', current_app=self.name)
        defaults = {
            'form_class': AdminPasswordChangeForm,
            'success_url': url,
            'extra_context': {**self.each_context(request), **(extra_context or {})},
        }
        if self.password_change_template is not None:
            defaults['template_name'] = self.password_change_template
        request.current_app = self.name
        return PasswordChangeView.as_view(**defaults)(request) 
Example #6
Source File: sites.py    From python2017 with MIT License 6 votes vote down vote up
def logout(self, request, extra_context=None):
        """
        Logs out the user for the given HttpRequest.

        This should *not* assume the user is already logged in.
        """
        from django.contrib.auth.views import LogoutView
        defaults = {
            'extra_context': dict(
                self.each_context(request),
                # Since the user isn't logged out at this point, the value of
                # has_permission must be overridden.
                has_permission=False,
                **(extra_context or {})
            ),
        }
        if self.logout_template is not None:
            defaults['template_name'] = self.logout_template
        request.current_app = self.name
        return LogoutView.as_view(**defaults)(request) 
Example #7
Source File: sites.py    From python2017 with MIT License 6 votes vote down vote up
def password_change(self, request, extra_context=None):
        """
        Handles the "change password" task -- both form display and validation.
        """
        from django.contrib.admin.forms import AdminPasswordChangeForm
        from django.contrib.auth.views import PasswordChangeView
        url = reverse('admin:password_change_done', current_app=self.name)
        defaults = {
            'form_class': AdminPasswordChangeForm,
            'success_url': url,
            'extra_context': dict(self.each_context(request), **(extra_context or {})),
        }
        if self.password_change_template is not None:
            defaults['template_name'] = self.password_change_template
        request.current_app = self.name
        return PasswordChangeView.as_view(**defaults)(request) 
Example #8
Source File: sites.py    From python2017 with MIT License 5 votes vote down vote up
def password_change_done(self, request, extra_context=None):
        """
        Displays the "success" page after a password change.
        """
        from django.contrib.auth.views import PasswordChangeDoneView
        defaults = {
            'extra_context': dict(self.each_context(request), **(extra_context or {})),
        }
        if self.password_change_done_template is not None:
            defaults['template_name'] = self.password_change_done_template
        request.current_app = self.name
        return PasswordChangeDoneView.as_view(**defaults)(request) 
Example #9
Source File: sites.py    From python with Apache License 2.0 5 votes vote down vote up
def i18n_javascript(self, request, extra_context=None):
        """
        Displays the i18n JavaScript that the Django admin requires.

        `extra_context` is unused but present for consistency with the other
        admin views.
        """
        return JavaScriptCatalog.as_view(packages=['django.contrib.admin'])(request) 
Example #10
Source File: sites.py    From python with Apache License 2.0 5 votes vote down vote up
def login(self, request, extra_context=None):
        """
        Displays the login form for the given HttpRequest.
        """
        if request.method == 'GET' and self.has_permission(request):
            # Already logged-in, redirect to admin index
            index_path = reverse('admin:index', current_app=self.name)
            return HttpResponseRedirect(index_path)

        from django.contrib.auth.views import LoginView
        # Since this module gets imported in the application's root package,
        # it cannot import models from other applications at the module level,
        # and django.contrib.admin.forms eventually imports User.
        from django.contrib.admin.forms import AdminAuthenticationForm
        context = dict(
            self.each_context(request),
            title=_('Log in'),
            app_path=request.get_full_path(),
            username=request.user.get_username(),
        )
        if (REDIRECT_FIELD_NAME not in request.GET and
                REDIRECT_FIELD_NAME not in request.POST):
            context[REDIRECT_FIELD_NAME] = reverse('admin:index', current_app=self.name)
        context.update(extra_context or {})

        defaults = {
            'extra_context': context,
            'authentication_form': self.login_form or AdminAuthenticationForm,
            'template_name': self.login_template or 'admin/login.html',
        }
        request.current_app = self.name
        return LoginView.as_view(**defaults)(request) 
Example #11
Source File: sites.py    From Mxonline3 with Apache License 2.0 5 votes vote down vote up
def create_admin_view(self, admin_view_class):
        return self.get_view_class(admin_view_class).as_view() 
Example #12
Source File: sites.py    From Mxonline3 with Apache License 2.0 5 votes vote down vote up
def create_model_admin_view(self, admin_view_class, model, option_class):
        return self.get_view_class(admin_view_class, option_class).as_view() 
Example #13
Source File: sites.py    From Mxonline3 with Apache License 2.0 5 votes vote down vote up
def i18n_javascript(self, request):
        from django.views.i18n import JavaScriptCatalog
        """
        Displays the i18n JavaScript that the Django admin requires.

        This takes into account the USE_I18N setting. If it's set to False, the
        generated JavaScript will be leaner and faster.
        """
        return JavaScriptCatalog.as_view(packages=['django.contrib.admin'])(request)


# This global object represents the default admin site, for the common case.
# You can instantiate AdminSite in your own code to create a custom admin site. 
Example #14
Source File: sites.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def login(self, request, extra_context=None):
        """
        Display the login form for the given HttpRequest.
        """
        if request.method == 'GET' and self.has_permission(request):
            # Already logged-in, redirect to admin index
            index_path = reverse('admin:index', current_app=self.name)
            return HttpResponseRedirect(index_path)

        from django.contrib.auth.views import LoginView
        # Since this module gets imported in the application's root package,
        # it cannot import models from other applications at the module level,
        # and django.contrib.admin.forms eventually imports User.
        from django.contrib.admin.forms import AdminAuthenticationForm
        context = {
            **self.each_context(request),
            'title': _('Log in'),
            'app_path': request.get_full_path(),
            'username': request.user.get_username(),
        }
        if (REDIRECT_FIELD_NAME not in request.GET and
                REDIRECT_FIELD_NAME not in request.POST):
            context[REDIRECT_FIELD_NAME] = reverse('admin:index', current_app=self.name)
        context.update(extra_context or {})

        defaults = {
            'extra_context': context,
            'authentication_form': self.login_form or AdminAuthenticationForm,
            'template_name': self.login_template or 'admin/login.html',
        }
        request.current_app = self.name
        return LoginView.as_view(**defaults)(request) 
Example #15
Source File: sites.py    From python2017 with MIT License 5 votes vote down vote up
def i18n_javascript(self, request, extra_context=None):
        """
        Displays the i18n JavaScript that the Django admin requires.

        `extra_context` is unused but present for consistency with the other
        admin views.
        """
        return JavaScriptCatalog.as_view(packages=['django.contrib.admin'])(request) 
Example #16
Source File: sites.py    From python2017 with MIT License 5 votes vote down vote up
def login(self, request, extra_context=None):
        """
        Displays the login form for the given HttpRequest.
        """
        if request.method == 'GET' and self.has_permission(request):
            # Already logged-in, redirect to admin index
            index_path = reverse('admin:index', current_app=self.name)
            return HttpResponseRedirect(index_path)

        from django.contrib.auth.views import LoginView
        # Since this module gets imported in the application's root package,
        # it cannot import models from other applications at the module level,
        # and django.contrib.admin.forms eventually imports User.
        from django.contrib.admin.forms import AdminAuthenticationForm
        context = dict(
            self.each_context(request),
            title=_('Log in'),
            app_path=request.get_full_path(),
            username=request.user.get_username(),
        )
        if (REDIRECT_FIELD_NAME not in request.GET and
                REDIRECT_FIELD_NAME not in request.POST):
            context[REDIRECT_FIELD_NAME] = reverse('admin:index', current_app=self.name)
        context.update(extra_context or {})

        defaults = {
            'extra_context': context,
            'authentication_form': self.login_form or AdminAuthenticationForm,
            'template_name': self.login_template or 'admin/login.html',
        }
        request.current_app = self.name
        return LoginView.as_view(**defaults)(request) 
Example #17
Source File: sites.py    From online with GNU Affero General Public License v3.0 5 votes vote down vote up
def create_admin_view(self, admin_view_class):
        return self.get_view_class(admin_view_class).as_view() 
Example #18
Source File: sites.py    From online with GNU Affero General Public License v3.0 5 votes vote down vote up
def create_model_admin_view(self, admin_view_class, model, option_class):
        return self.get_view_class(admin_view_class, option_class).as_view() 
Example #19
Source File: sites.py    From online with GNU Affero General Public License v3.0 5 votes vote down vote up
def i18n_javascript(self, request):
        from django.views.i18n import JavaScriptCatalog
        """
        Displays the i18n JavaScript that the Django admin requires.

        This takes into account the USE_I18N setting. If it's set to False, the
        generated JavaScript will be leaner and faster.
        """
        return JavaScriptCatalog.as_view(packages=['django.contrib.admin'])(request)

# This global object represents the default admin site, for the common case.
# You can instantiate AdminSite in your own code to create a custom admin site. 
Example #20
Source File: sites.py    From Dailyfresh-B2C with Apache License 2.0 5 votes vote down vote up
def create_admin_view(self, admin_view_class):
        return self.get_view_class(admin_view_class).as_view() 
Example #21
Source File: sites.py    From Dailyfresh-B2C with Apache License 2.0 5 votes vote down vote up
def create_model_admin_view(self, admin_view_class, model, option_class):
        return self.get_view_class(admin_view_class, option_class).as_view() 
Example #22
Source File: sites.py    From Dailyfresh-B2C with Apache License 2.0 5 votes vote down vote up
def i18n_javascript(self, request):
        from django.views.i18n import JavaScriptCatalog
        """
        Displays the i18n JavaScript that the Django admin requires.

        This takes into account the USE_I18N setting. If it's set to False, the
        generated JavaScript will be leaner and faster.
        """
        return JavaScriptCatalog.as_view(packages=['django.contrib.admin'])(request)

# This global object represents the default admin site, for the common case.
# You can instantiate AdminSite in your own code to create a custom admin site. 
Example #23
Source File: test_i18n.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_i18n_unknown_package_error(self):
        view = JavaScriptCatalog.as_view()
        request = RequestFactory().get('/')
        msg = 'Invalid package(s) provided to JavaScriptCatalog: unknown_package'
        with self.assertRaisesMessage(ValueError, msg):
            view(request, packages='unknown_package')
        msg += ',unknown_package2'
        with self.assertRaisesMessage(ValueError, msg):
            view(request, packages='unknown_package+unknown_package2') 
Example #24
Source File: test_i18n.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_i18n_unknown_package_error(self):
        view = JavaScriptCatalog.as_view()
        request = RequestFactory().get('/')
        msg = 'Invalid package(s) provided to JavaScriptCatalog: unknown_package'
        with self.assertRaisesMessage(ValueError, msg):
            view(request, packages='unknown_package')
        msg += ',unknown_package2'
        with self.assertRaisesMessage(ValueError, msg):
            view(request, packages='unknown_package+unknown_package2') 
Example #25
Source File: sites.py    From myblog with GNU Affero General Public License v3.0 5 votes vote down vote up
def i18n_javascript(self, request):
        from django.views.i18n import JavaScriptCatalog
        """
        Displays the i18n JavaScript that the Django admin requires.

        This takes into account the USE_I18N setting. If it's set to False, the
        generated JavaScript will be leaner and faster.
        """
        return JavaScriptCatalog.as_view(packages=['django.contrib.admin'])(request)

# This global object represents the default admin site, for the common case.
# You can instantiate AdminSite in your own code to create a custom admin site. 
Example #26
Source File: sites.py    From bioforum with MIT License 5 votes vote down vote up
def password_change_done(self, request, extra_context=None):
        """
        Display the "success" page after a password change.
        """
        from django.contrib.auth.views import PasswordChangeDoneView
        defaults = {
            'extra_context': dict(self.each_context(request), **(extra_context or {})),
        }
        if self.password_change_done_template is not None:
            defaults['template_name'] = self.password_change_done_template
        request.current_app = self.name
        return PasswordChangeDoneView.as_view(**defaults)(request) 
Example #27
Source File: sites.py    From bioforum with MIT License 5 votes vote down vote up
def i18n_javascript(self, request, extra_context=None):
        """
        Display the i18n JavaScript that the Django admin requires.

        `extra_context` is unused but present for consistency with the other
        admin views.
        """
        return JavaScriptCatalog.as_view(packages=['django.contrib.admin'])(request) 
Example #28
Source File: sites.py    From bioforum with MIT License 5 votes vote down vote up
def logout(self, request, extra_context=None):
        """
        Log out the user for the given HttpRequest.

        This should *not* assume the user is already logged in.
        """
        from django.contrib.auth.views import LogoutView
        defaults = {
            'extra_context': dict(
                self.each_context(request),
                # Since the user isn't logged out at this point, the value of
                # has_permission must be overridden.
                has_permission=False,
                **(extra_context or {})
            ),
        }
        if self.logout_template is not None:
            defaults['template_name'] = self.logout_template
        request.current_app = self.name
        return LogoutView.as_view(**defaults)(request) 
Example #29
Source File: sites.py    From bioforum with MIT License 5 votes vote down vote up
def login(self, request, extra_context=None):
        """
        Display the login form for the given HttpRequest.
        """
        if request.method == 'GET' and self.has_permission(request):
            # Already logged-in, redirect to admin index
            index_path = reverse('admin:index', current_app=self.name)
            return HttpResponseRedirect(index_path)

        from django.contrib.auth.views import LoginView
        # Since this module gets imported in the application's root package,
        # it cannot import models from other applications at the module level,
        # and django.contrib.admin.forms eventually imports User.
        from django.contrib.admin.forms import AdminAuthenticationForm
        context = dict(
            self.each_context(request),
            title=_('Log in'),
            app_path=request.get_full_path(),
            username=request.user.get_username(),
        )
        if (REDIRECT_FIELD_NAME not in request.GET and
                REDIRECT_FIELD_NAME not in request.POST):
            context[REDIRECT_FIELD_NAME] = reverse('admin:index', current_app=self.name)
        context.update(extra_context or {})

        defaults = {
            'extra_context': context,
            'authentication_form': self.login_form or AdminAuthenticationForm,
            'template_name': self.login_template or 'admin/login.html',
        }
        request.current_app = self.name
        return LoginView.as_view(**defaults)(request) 
Example #30
Source File: sites.py    From weibo-analysis-system with MIT License 5 votes vote down vote up
def create_admin_view(self, admin_view_class):
        return self.get_view_class(admin_view_class).as_view()