django.utils.six.moves.urllib_parse.urlencode

Here are the examples of the python api django.utils.six.moves.urllib_parse.urlencode taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

8 Examples 7

Example 1

Project: browsercompat
Source File: helpers.py
View license
@library.global_function
@contextfunction
def add_filter_to_current_url(context, name, value):
    """Add a filter to the current URL."""
    query_parts = []
    added = False
    for qs_name, qs_value in context['request'].GET.items():
        if qs_name == name:
            added = True
            query_parts.append((name, value))
        else:
            query_parts.append((qs_name, qs_value))
    if not added:
        query_parts.append((name, value))
    return context['request'].path + '?' + urlencode(query_parts)

Example 2

Project: browsercompat
Source File: helpers.py
View license
@library.global_function
@contextfunction
def drop_filter_from_current_url(context, name):
    """Drop a filter from the current URL."""
    query_parts = []
    for qs_name, qs_value in context['request'].GET.items():
        if qs_name != name:
            query_parts.append((qs_name, qs_value))
    path = context['request'].path
    if query_parts:
        return path + '?' + urlencode(query_parts)
    else:
        return path

Example 3

Project: browsercompat
Source File: helpers.py
View license
@library.global_function
@contextfunction
def add_filter_to_current_url(context, name, value):
    """Add a filter to the current URL."""
    query_parts = []
    added = False
    for qs_name, qs_value in context['request'].GET.items():
        if qs_name == name:
            added = True
            query_parts.append((name, value))
        else:
            query_parts.append((qs_name, qs_value))
    if not added:
        query_parts.append((name, value))
    return context['request'].path + '?' + urlencode(query_parts)

Example 4

Project: browsercompat
Source File: helpers.py
View license
@library.global_function
@contextfunction
def drop_filter_from_current_url(context, name):
    """Drop a filter from the current URL."""
    query_parts = []
    for qs_name, qs_value in context['request'].GET.items():
        if qs_name != name:
            query_parts.append((qs_name, qs_value))
    path = context['request'].path
    if query_parts:
        return path + '?' + urlencode(query_parts)
    else:
        return path

Example 5

Project: django-cas-ng
Source File: middleware.py
View license
    def process_view(self, request, view_func, view_args, view_kwargs):
        """Forwards unauthenticated requests to the admin page to the CAS
        login URL, as well as calls to django.contrib.auth.views.login and
        logout.
        """

        if view_func == login:
            return cas_login(request, *view_args, **view_kwargs)
        elif view_func == logout:
            return cas_logout(request, *view_args, **view_kwargs)

        if view_func in (cas_login, cas_logout):
            return None

        if settings.CAS_ADMIN_PREFIX:
            if not request.path.startswith(settings.CAS_ADMIN_PREFIX):
                return None
        elif not view_func.__module__.startswith('django.contrib.admin.'):
            return None

        if request.user.is_authenticated():
            if request.user.is_staff:
                return None
            else:
                raise PermissionDenied(_('You do not have staff privileges.'))
        params = urllib_parse.urlencode({REDIRECT_FIELD_NAME: request.get_full_path()})
        return HttpResponseRedirect(reverse(cas_login) + '?' + params)

Example 6

Project: django-cas-ng
Source File: middleware.py
View license
    def process_view(self, request, view_func, view_args, view_kwargs):
        """Forwards unauthenticated requests to the admin page to the CAS
        login URL, as well as calls to django.contrib.auth.views.login and
        logout.
        """

        if view_func == login:
            return cas_login(request, *view_args, **view_kwargs)
        elif view_func == logout:
            return cas_logout(request, *view_args, **view_kwargs)

        if view_func in (cas_login, cas_logout):
            return None

        if settings.CAS_ADMIN_PREFIX:
            if not request.path.startswith(settings.CAS_ADMIN_PREFIX):
                return None
        elif not view_func.__module__.startswith('django.contrib.admin.'):
            return None

        if request.user.is_authenticated():
            if request.user.is_staff:
                return None
            else:
                raise PermissionDenied(_('You do not have staff privileges.'))
        params = urllib_parse.urlencode({REDIRECT_FIELD_NAME: request.get_full_path()})
        return HttpResponseRedirect(reverse(cas_login) + '?' + params)

Example 7

View license
    def handle(self, **options):
        self.mime_type_magic = magic.Magic(mime=True)
        self.gb_parties = PartySet.objects.get(slug='gb')
        self.ni_parties = PartySet.objects.get(slug='ni')
        start = 0
        per_page = 50
        url = 'http://pefonline.electoralcommission.org.uk/api/search/Registrations'
        params = {
            'rows': per_page,
            'et': ["pp", "ppm"],
            'register': ["gb", "ni"],
            'regStatus': ["registered", "deregistered", "lapsed"],
        }
        with transaction.atomic():
            total = None
            while total is None or start <= total:
                params['start'] = start
                resp = requests.get(url + '?' + urlencode(params, doseq=True)).json()
                if total is None:
                    total = resp['Total']
                self.parse_data(resp['Result'])
                start += per_page

Example 8

View license
    def handle(self, **options):
        self.mime_type_magic = magic.Magic(mime=True)
        self.gb_parties = PartySet.objects.get(slug='gb')
        self.ni_parties = PartySet.objects.get(slug='ni')
        start = 0
        per_page = 50
        url = 'http://pefonline.electoralcommission.org.uk/api/search/Registrations'
        params = {
            'rows': per_page,
            'et': ["pp", "ppm"],
            'register': ["gb", "ni"],
            'regStatus': ["registered", "deregistered", "lapsed"],
        }
        with transaction.atomic():
            total = None
            while total is None or start <= total:
                params['start'] = start
                resp = requests.get(url + '?' + urlencode(params, doseq=True)).json()
                if total is None:
                    total = resp['Total']
                self.parse_data(resp['Result'])
                start += per_page