Python django.utils.http.urlquote_plus() Examples

The following are 9 code examples of django.utils.http.urlquote_plus(). 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.utils.http , or try the search function .
Example #1
Source File: templating.py    From open-context-py with GNU General Public License v3.0 6 votes vote down vote up
def make_query_parameter(self,
                             predicate,
                             obj,
                             item_type=False):
        """ makes a query parameter depending on the value
            of the predicate slug
        """
        if 'http://' in predicate or 'https://' in predicate:
            predicate = urlquote_plus(predicate)
        if 'http://' in obj or 'https://' in obj:
            obj = urlquote_plus(obj)
        dc_terms_obj = DCterms()
        if predicate in dc_terms_obj.DC_SLUG_TO_FIELDS:
            # there's a query parameter for this dc-terms metadata
            query = dc_terms_obj.DC_SLUG_TO_FIELDS[predicate]
            query += '=' + obj
        elif item_type == 'predicates':
            query = 'prop=' + obj
        elif item_type == 'types':
            query = 'obj=' + obj
        else:
            query = 'prop=' + predicate + '---' + obj
        return query 
Example #2
Source File: htmltemplating.py    From open-context-py with GNU General Public License v3.0 6 votes vote down vote up
def make_query_parameter(self,
                             predicate,
                             obj,
                             item_type=False):
        """ makes a query parameter depending on the value
            of the predicate slug
        """
        if 'http://' in predicate or 'https://' in predicate:
            predicate = urlquote_plus(predicate)
        if 'http://' in obj or 'https://' in obj:
            obj = urlquote_plus(obj)
        dc_terms_obj = DCterms()
        if predicate in dc_terms_obj.DC_SLUG_TO_FIELDS:
            # there's a query parameter for this dc-terms metadata
            query = dc_terms_obj.DC_SLUG_TO_FIELDS[predicate]
            query += '=' + obj
        elif item_type == 'predicates':
            query = 'prop=' + obj
        elif item_type == 'types':
            query = 'obj=' + obj
        else:
            query = 'prop=' + predicate + '---' + obj
        return query 
Example #3
Source File: listing.py    From pasportaservo with GNU Affero General Public License v3.0 5 votes vote down vote up
def get(self, request, *args, **kwargs):
        def unwhitespace(val):
            return " ".join(val.split())
        if 'ps_q' in request.GET:
            # Keeping Unicode in URL, replacing space with '+'.
            query = uri_to_iri(urlquote_plus(unwhitespace(request.GET['ps_q'])))
            params = {'query': query} if query else None
            return HttpResponseRedirect(reverse_lazy('search', kwargs=params))
        query = kwargs['query'] or ''  # Avoiding query=None
        self.query = unwhitespace(unquote_plus(query))
        # Exclude places whose owner blocked unauthenticated viewing.
        if not request.user.is_authenticated:
            self.queryset = self.queryset.exclude(owner__pref__public_listing=False)
        return super().get(request, *args, **kwargs) 
Example #4
Source File: models.py    From open-context-py with GNU General Public License v3.0 5 votes vote down vote up
def encode_url_context_path(self, context):
        """ encodes a context path for a URL, retains
            the path '/' characters
        """
        if '/' in context:
            context_ex = context.split('/')
        else:
            context_ex = [context]
        quote_context_list = []
        for c_part in context_ex:
            url_c_part = urlquote_plus(c_part)
            quote_context_list.append(url_c_part)
        return '/'.join(quote_context_list) 
Example #5
Source File: base.py    From avos with Apache License 2.0 5 votes vote down vote up
def get_prev_marker(self):
        """Returns the identifier for the first object in the current data set
        for APIs that use marker/limit-based paging.
        """
        return http.urlquote_plus(self.get_object_id(self.data[0])) \
            if self.data else '' 
Example #6
Source File: base.py    From avos with Apache License 2.0 5 votes vote down vote up
def get_marker(self):
        """Returns the identifier for the last object in the current data set
        for APIs that use marker/limit-based paging.
        """
        return http.urlquote_plus(self.get_object_id(self.data[-1])) \
            if self.data else '' 
Example #7
Source File: middleware.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
def __call__(self, request):
        if is_public_path(request.path):
            return self.get_response(request)

        if request.user.is_anonymous:
            return HttpResponseRedirect(
                "/MAAS/?next=%s" % urlquote_plus(request.path)
            )

        return self.get_response(request) 
Example #8
Source File: templating.py    From open-context-py with GNU General Public License v3.0 4 votes vote down vote up
def create_opengraph(self):
        """ creates opengraph metadata to facilitate snippets for
            social media sites
        """
        rp = RootPath()
        base_url = rp.get_baseurl()
        if isinstance(self.project_hero_uri, str):
            self.og_image = self.project_hero_uri
        else:
            if self.observations is not False:
                for obs in self.observations:
                    if obs.media_link_count >0:
                        for link in obs.media_links:
                            self.og_image = link.media[0].thumbnail
                            break
        if self.content is not False:
            # use a preview or a thumbnail image as the og_image
            # also maybe a short description
            if 'preview' in self.content and self.fullimage:
                if isinstance(self.content['preview'], str):
                    self.og_image = self.content['preview']
            elif 'thumbnail' in self.content:
                if isinstance(self.content['thumbnail'], str):
                    self.og_image = self.content['thumbnail']
            else:
                # don't use any image
                pass
            if 'sum_text' in self.content:
                # we have summary text, so use it
                if len(self.content['sum_text']) > 0:
                    self.og_description = self.content['sum_text']
        if not isinstance(self.og_image, str):
            if isinstance(self.item_category_icon, str):
                # we don't have an og_image yet, but we do have a category icon,
                # so use that
                self.og_image = self.item_category_icon
            else:
                # use the default Open Context icon
                rp = RootPath()
                base_url = rp.get_baseurl()
                self.og_image = base_url + self.OPEN_CONTEXT_ICON
            # do this anyway, since small pictures do not work.
            self.og_image = base_url + self.OPEN_CONTEXT_ICON
        if isinstance(self.og_image, str):
            # if the base URL is not in the sting, we need to use a proxy
            if base_url not in self.og_image:
                proxy_url = base_url + '/entities/proxy/'
                proxy_url += urlquote_plus(self.og_image)
                self.og_image = proxy_url
        self.og_title = self.citation.cite_title
        if not isinstance(self.og_description, str):
            self.og_description = ''
            if isinstance(self.item_category_label, str) and self.act_nav == 'subjects':
                self.og_description += self.item_category_label
            if self.act_nav in self.ITEM_TYPE_DESCRIPTIONS:
                if self.og_description == '':
                    self.og_description = 'A'
                self.og_description += ' ' + self.ITEM_TYPE_DESCRIPTIONS[self.act_nav]
            if self.act_nav != 'projects' and isinstance(self.project.label, str):
                self.og_description += '; part of the ' + self.project.label
                self.og_description += ' data publication.' 
Example #9
Source File: htmltemplating.py    From open-context-py with GNU General Public License v3.0 4 votes vote down vote up
def create_opengraph(self):
        """ creates opengraph metadata to facilitate snippets for
            social media sites
        """
        rp = RootPath()
        base_url = rp.get_baseurl()
        if isinstance(self.project_hero_uri, str):
            self.og_image = self.project_hero_uri
        else:
            if self.observations is not False:
                for obs in self.observations:
                    if obs.media_link_count >0:
                        for link in obs.media_links:
                            self.og_image = link.media[0].thumbnail
                            break
        if self.content is not False:
            # use a preview or a thumbnail image as the og_image
            # also maybe a short description
            if 'preview' in self.content and self.fullimage:
                if isinstance(self.content['preview'], str):
                    self.og_image = self.content['preview']
            elif 'thumbnail' in self.content:
                if isinstance(self.content['thumbnail'], str):
                    self.og_image = self.content['thumbnail']
            else:
                # don't use any image
                pass
            if 'sum_text' in self.content:
                # we have summary text, so use it
                if len(self.content['sum_text']) > 0:
                    self.og_description = self.content['sum_text']
        if not isinstance(self.og_image, str):
            if isinstance(self.item_category_icon, str):
                # we don't have an og_image yet, but we do have a category icon,
                # so use that
                self.og_image = self.item_category_icon
            else:
                # use the default Open Context icon
                rp = RootPath()
                base_url = rp.get_baseurl()
                self.og_image = base_url + self.OPEN_CONTEXT_ICON
            # do this anyway, since small pictures do not work.
            self.og_image = base_url + self.OPEN_CONTEXT_ICON
        if isinstance(self.og_image, str):
            # if the base URL is not in the sting, we need to use a proxy
            if base_url not in self.og_image:
                proxy_url = base_url + '/entities/proxy/'
                proxy_url += urlquote_plus(self.og_image)
                self.og_image = proxy_url
        self.og_title = self.citation.cite_title
        if not isinstance(self.og_description, str):
            self.og_description = ''
            if isinstance(self.item_category_label, str) and self.act_nav == 'subjects':
                self.og_description += self.item_category_label
            if self.act_nav in self.ITEM_TYPE_DESCRIPTIONS:
                if self.og_description == '':
                    self.og_description = 'A'
                self.og_description += ' ' + self.ITEM_TYPE_DESCRIPTIONS[self.act_nav]
            if self.act_nav != 'projects' and isinstance(self.project.label, str):
                self.og_description += '; part of the ' + self.project.label
                self.og_description += ' data publication.'