[web2py] Re: urlify - no char mapping
FWIW this mapping helped me once in the past... https://github.com/GoodCloud/django-rewrite/blob/master/libs/slughifi.py -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: urlify - no char mapping
ATM there are no dict mappings available for the function included in web2py. You can use the function directly with IS_SLUG()('whatever_string') in which case you have a tuple returned with (result, error) or directly with IS_SLUG().urlify('whatever_string') which returns only the result as a string. There are only two parameters, maxlen (it truncates the string to n chars) and keep_underscores (by default is false, so every _ gets translated to a - (hypen)) On Sunday, August 18, 2013 12:17:20 PM UTC+2, lesssugar wrote: > > Docs site specifies *IS_SLUG.urlify.__dict__ *and *IS_SLUG.urlify.func_dict. > *However, I'm not sure how to work with dictionary here. > > Can I e.g. do something like this: > > IS_SLUG.urlify(string_to_convert, mapping_dictionary) > > and simply tell the function which set of key-value pairs it should use? > > On Sunday, August 18, 2013 11:23:35 AM UTC+2, Niphlod wrote: >> >> indeed, "our" urlify doesn't work with "ideograms" (sorry, I'm totally no >> expert in oriental languages). >> The original posted solution takes care of "translating" >> >> 派森是好物 >> to >> pai-sen-shi-hao-wu >> >> >> we can add the feature looking at other similar projects, but we need >> someone that has a solid knowledge of oriental (and turkish, polish, >> latvian, polish, czech) to write tests. >> >> On Sunday, August 18, 2013 10:00:32 AM UTC+2, Massimo Di Pierro wrote: >>> >>> Look ate the source code of urlify: >>> https://github.com/web2py/web2py/blob/master/gluon/validators.py#L2525 >>> >>> If you can suggest improvements I will happy to include them. I guess >>> the problem is here: >>> >>> https://github.com/web2py/web2py/blob/master/gluon/validators.py#L2534 >>> >>> Massimo >>> >>> On Friday, 16 August 2013 07:39:50 UTC-5, lesssugar wrote: I'm using the following module to convert my urls: http://pydoc.net/Python/redsolutioncms.django-hex-storage/0.1.1/pinyin.urlify/ I have urlify.py (main function) and maps.py (chars mapping) in my /modules. I test it in one of my views, simply trying to print the urlify-ed value in the console: {{from urlify import urlify}} {{print urlify(u"łźć ęćm")}} I get "aaa-aaa", so basically there's no mapping done and I have no idea why. -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: urlify - no char mapping
Docs site specifies *IS_SLUG.urlify.__dict__ *and *IS_SLUG.urlify.func_dict. *However, I'm not sure how to work with dictionary here. Can I e.g. do something like this: IS_SLUG.urlify(string_to_convert, mapping_dictionary) and simply tell the function which set of key-value pairs it should use? On Sunday, August 18, 2013 11:23:35 AM UTC+2, Niphlod wrote: > > indeed, "our" urlify doesn't work with "ideograms" (sorry, I'm totally no > expert in oriental languages). > The original posted solution takes care of "translating" > > 派森是好物 > to > pai-sen-shi-hao-wu > > > we can add the feature looking at other similar projects, but we need > someone that has a solid knowledge of oriental (and turkish, polish, > latvian, polish, czech) to write tests. > > On Sunday, August 18, 2013 10:00:32 AM UTC+2, Massimo Di Pierro wrote: >> >> Look ate the source code of urlify: >> https://github.com/web2py/web2py/blob/master/gluon/validators.py#L2525 >> >> If you can suggest improvements I will happy to include them. I guess the >> problem is here: >> >> https://github.com/web2py/web2py/blob/master/gluon/validators.py#L2534 >> >> Massimo >> >> On Friday, 16 August 2013 07:39:50 UTC-5, lesssugar wrote: >>> >>> I'm using the following module to convert my urls: >>> >>> >>> http://pydoc.net/Python/redsolutioncms.django-hex-storage/0.1.1/pinyin.urlify/ >>> >>> I have urlify.py (main function) and maps.py (chars mapping) in my >>> /modules. I test it in one of my views, simply trying to print the >>> urlify-ed value in the console: >>> >>> {{from urlify import urlify}} >>> {{print urlify(u"łźć ęćm")}} >>> >>> I get "aaa-aaa", so basically there's no mapping done and I have no idea >>> why. >>> >>> >>> -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: urlify - no char mapping
indeed, "our" urlify doesn't work with "ideograms" (sorry, I'm totally no expert in oriental languages). The original posted solution takes care of "translating" 派森是好物 to pai-sen-shi-hao-wu we can add the feature looking at other similar projects, but we need someone that has a solid knowledge of oriental (and turkish, polish, latvian, polish, czech) to write tests. On Sunday, August 18, 2013 10:00:32 AM UTC+2, Massimo Di Pierro wrote: > > Look ate the source code of urlify: > https://github.com/web2py/web2py/blob/master/gluon/validators.py#L2525 > > If you can suggest improvements I will happy to include them. I guess the > problem is here: > > https://github.com/web2py/web2py/blob/master/gluon/validators.py#L2534 > > Massimo > > On Friday, 16 August 2013 07:39:50 UTC-5, lesssugar wrote: >> >> I'm using the following module to convert my urls: >> >> >> http://pydoc.net/Python/redsolutioncms.django-hex-storage/0.1.1/pinyin.urlify/ >> >> I have urlify.py (main function) and maps.py (chars mapping) in my >> /modules. I test it in one of my views, simply trying to print the >> urlify-ed value in the console: >> >> {{from urlify import urlify}} >> {{print urlify(u"łźć ęćm")}} >> >> I get "aaa-aaa", so basically there's no mapping done and I have no idea >> why. >> >> >> -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: urlify - no char mapping
Look ate the source code of urlify: https://github.com/web2py/web2py/blob/master/gluon/validators.py#L2525 If you can suggest improvements I will happy to include them. I guess the problem is here: https://github.com/web2py/web2py/blob/master/gluon/validators.py#L2534 Massimo On Friday, 16 August 2013 07:39:50 UTC-5, lesssugar wrote: > > I'm using the following module to convert my urls: > > > http://pydoc.net/Python/redsolutioncms.django-hex-storage/0.1.1/pinyin.urlify/ > > I have urlify.py (main function) and maps.py (chars mapping) in my > /modules. I test it in one of my views, simply trying to print the > urlify-ed value in the console: > > {{from urlify import urlify}} > {{print urlify(u"łźć ęćm")}} > > I get "aaa-aaa", so basically there's no mapping done and I have no idea > why. > > > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: urlify - no char mapping
It works great, but I'm not getting "ł" character mapped using IS_SLUG.urlify(string). How do I make sure all special characters (e.g. latin ones) get mapped? Do I need to use a custom mapping dictionary or there's maybe an easier, built-in way? On Saturday, August 17, 2013 12:48:17 AM UTC+2, lesssugar wrote: > > Oh, I wasn't aware that IS_SLUG.urlify() is a part of our great framework > :) I thought urlify is an external Python module. > > Anyway, found docs here: > http://www.web2py.com.ar/examples/global/vars/IS_SLUG/urlify > > Thanks! > > On Saturday, August 17, 2013 12:00:52 AM UTC+2, Massimo Di Pierro wrote: >> >> There is a IS_SLUG.urlify() which is probably better than Django's. >> ;-) >> >> On Friday, 16 August 2013 07:39:50 UTC-5, lesssugar wrote: >>> >>> I'm using the following module to convert my urls: >>> >>> >>> http://pydoc.net/Python/redsolutioncms.django-hex-storage/0.1.1/pinyin.urlify/ >>> >>> I have urlify.py (main function) and maps.py (chars mapping) in my >>> /modules. I test it in one of my views, simply trying to print the >>> urlify-ed value in the console: >>> >>> {{from urlify import urlify}} >>> {{print urlify(u"łźć ęćm")}} >>> >>> I get "aaa-aaa", so basically there's no mapping done and I have no idea >>> why. >>> >>> >>> -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: urlify - no char mapping
Oh, I wasn't aware that IS_SLUG.urlify() is a part of our great framework :) I thought urlify() is an external python module. Anyway, found docs here: http://www.web2py.com.ar/examples/global/vars/IS_SLUG/urlify Thanks! On Saturday, August 17, 2013 12:00:52 AM UTC+2, Massimo Di Pierro wrote: > > There is a IS_SLUG.urlify() which is probably better than Django's. > ;-) > > On Friday, 16 August 2013 07:39:50 UTC-5, lesssugar wrote: >> >> I'm using the following module to convert my urls: >> >> >> http://pydoc.net/Python/redsolutioncms.django-hex-storage/0.1.1/pinyin.urlify/ >> >> I have urlify.py (main function) and maps.py (chars mapping) in my >> /modules. I test it in one of my views, simply trying to print the >> urlify-ed value in the console: >> >> {{from urlify import urlify}} >> {{print urlify(u"łźć ęćm")}} >> >> I get "aaa-aaa", so basically there's no mapping done and I have no idea >> why. >> >> >> -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: urlify - no char mapping
There is a IS_SLUG.urlify() which is probably better than Django's. ;-) On Friday, 16 August 2013 07:39:50 UTC-5, lesssugar wrote: > > I'm using the following module to convert my urls: > > > http://pydoc.net/Python/redsolutioncms.django-hex-storage/0.1.1/pinyin.urlify/ > > I have urlify.py (main function) and maps.py (chars mapping) in my > /modules. I test it in one of my views, simply trying to print the > urlify-ed value in the console: > > {{from urlify import urlify}} > {{print urlify(u"łźć ęćm")}} > > I get "aaa-aaa", so basically there's no mapping done and I have no idea > why. > > > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: urlify
Jonathan sent me a patch, I merged it with the suggestions above and I am uploading IS_SLUG to trunk. Massimo On Jan 24, 1:09 pm, Thadeus Burgess wrote: > I agree with pistacchio. > > agree with you massimo on IS_SLUG for filtering only, if you want to > validate use IS_ALPHANUMERIC. > > -Thadeus > > On Sun, Jan 24, 2010 at 12:39 PM, Jonathan Lundell wrote: > > On Jan 24, 2010, at 9:53 AM, mdipierro wrote: > > >> I do not know about this. What do other people think? > >> I do not have a strong opinion either way. > > > I think that slug is a fairly common term. WordPress uses it, for example. > > > And if we make it a validator (I'm about to submit a patch), it definitely > > can't be IS_URL(). > > >> On Jan 24, 11:34 am, pistacchio wrote: > >>> I'm ok with slugify, but the reason i chose "urlify" is that slug is > >>> not really a mvc term. It comes from the journalistic jargon and it's > >>> been adopted by the original Django developers that were working on a > >>> framework to build a newspaper site on. > > >>> I don't think that "slug", outside the Django community, is a standard > >>> term to name such url-friendly strings. More often they're referred to > >>> as "pretty urls". > > >>> On 24 Gen, 17:55, Jonathan Lundell wrote: > > On Jan 24, 2010, at 8:30 AM, mdipierro wrote: > > > I will take a patch. ;-) > > I'll contribute one. Any objection to changing the name to "slugify", > since it's not really urlifying its input? > > > On Jan 23, 7:03 pm, Jonathan Lundell wrote: > >> urlify needs a comment to say explicitly what its intention is. That's > >> partly because it suppresses quite a few characters that are normally > >> legal in URLs, which is confusing. > > >> Also, > > >>> def urlify(s, max_length=80): > >>> s = s.lower() > >>> # string normalization, eg è => e, ñ => n > >>> s = unicodedata.normalize('NFKD', > >>> s.decode('utf-8')).encode('ASCII', 'ignore') > >>> # strip entities > >>> s = re.sub('&\w+;', '', s) > > >> this should be '&\w+?;' (that is, non-greedy). Otherwise, a string > >> like '&whatever&' will be completely eliminated. > > >>> # strip everything but letters, numbers, dashes and spaces > >>> s = re.sub('[^a-z0-9\-\s]', '', s) > >>> # replace spaces with dashes > >>> s = s.replace(' ', '-') > >>> # strip multiple contiguous dashes > >>> s = re.sub('-{2,}', '-', s) > >>> # strip dashes at the beginning and end of the string > >>> s = s.strip('-') > >>> # ensure the maximum length > >>> s = s[:max_length-1] > >>> return s > > >> (Stylistically, I think it'd be more readable if the comments were > >> appended to the relevant code lines.) > > > -- > > You received this message because you are subscribed to the Google > > Groups "web2py-users" group. > > To post to this group, send email to web...@googlegroups.com. > > To unsubscribe from this group, send email to > > web2py+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/web2py?hl=en. > > >> -- > >> You received this message because you are subscribed to the Google Groups > >> "web2py-users" group. > >> To post to this group, send email to web...@googlegroups.com. > >> To unsubscribe from this group, send email to > >> web2py+unsubscr...@googlegroups.com. > >> For more options, visit this group > >> athttp://groups.google.com/group/web2py?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "web2py-users" group. > > To post to this group, send email to web...@googlegroups.com. > > To unsubscribe from this group, send email to > > web2py+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/web2py?hl=en. > > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
Re: [web2py] Re: urlify
On Jan 24, 2010, at 11:05 AM, mdipierro wrote: > That's a good point. > > I also think the IS_SLUG should not do validation, just filtering. Or > perhaps have an option to The patch I sent is filtering-only, sort of a super IS_LOWER(). The main use for it in a form, I think, is to combine IS_SLUG with IS_NOT_IN_DB, since slugs want to be unique. > > def IS_SLUG(): >def __init__(check=False,error_message=): >self.check=check >self.error_message=error_message >@staticmethod >def slugify(value): >... >def __call__(self,value): >if check and not value==self.sugify(value): > return (value,self.error_message) >return (self.slugify(value),None) > > On Jan 24, 12:39 pm, Jonathan Lundell wrote: >> On Jan 24, 2010, at 9:53 AM, mdipierro wrote: >> >>> I do not know about this. What do other people think? >>> I do not have a strong opinion either way. >> >> I think that slug is a fairly common term. WordPress uses it, for example. >> >> And if we make it a validator (I'm about to submit a patch), it definitely >> can't be IS_URL(). >> >> >> >>> On Jan 24, 11:34 am, pistacchio wrote: I'm ok with slugify, but the reason i chose "urlify" is that slug is not really a mvc term. It comes from the journalistic jargon and it's been adopted by the original Django developers that were working on a framework to build a newspaper site on. >> I don't think that "slug", outside the Django community, is a standard term to name such url-friendly strings. More often they're referred to as "pretty urls". >> On 24 Gen, 17:55, Jonathan Lundell wrote: >> > On Jan 24, 2010, at 8:30 AM, mdipierro wrote: >> >> I will take a patch. ;-) >> > I'll contribute one. Any objection to changing the name to "slugify", > since it's not really urlifying its input? >> >> On Jan 23, 7:03 pm, Jonathan Lundell wrote: >>> urlify needs a comment to say explicitly what its intention is. That's >>> partly because it suppresses quite a few characters that are normally >>> legal in URLs, which is confusing. >> >>> Also, >> def urlify(s, max_length=80): s = s.lower() # string normalization, eg è => e, ñ => n s = unicodedata.normalize('NFKD', s.decode('utf-8')).encode('ASCII', 'ignore') # strip entities s = re.sub('&\w+;', '', s) >> >>> this should be '&\w+?;' (that is, non-greedy). Otherwise, a string like >>> '&whatever&' will be completely eliminated. >> # strip everything but letters, numbers, dashes and spaces s = re.sub('[^a-z0-9\-\s]', '', s) # replace spaces with dashes s = s.replace(' ', '-') # strip multiple contiguous dashes s = re.sub('-{2,}', '-', s) # strip dashes at the beginning and end of the string s = s.strip('-') # ensure the maximum length s = s[:max_length-1] return s >> >>> (Stylistically, I think it'd be more readable if the comments were >>> appended to the relevant code lines.) -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
Re: [web2py] Re: urlify
I agree with pistacchio. agree with you massimo on IS_SLUG for filtering only, if you want to validate use IS_ALPHANUMERIC. -Thadeus On Sun, Jan 24, 2010 at 12:39 PM, Jonathan Lundell wrote: > On Jan 24, 2010, at 9:53 AM, mdipierro wrote: > >> I do not know about this. What do other people think? >> I do not have a strong opinion either way. > > I think that slug is a fairly common term. WordPress uses it, for example. > > And if we make it a validator (I'm about to submit a patch), it definitely > can't be IS_URL(). > >> >> On Jan 24, 11:34 am, pistacchio wrote: >>> I'm ok with slugify, but the reason i chose "urlify" is that slug is >>> not really a mvc term. It comes from the journalistic jargon and it's >>> been adopted by the original Django developers that were working on a >>> framework to build a newspaper site on. >>> >>> I don't think that "slug", outside the Django community, is a standard >>> term to name such url-friendly strings. More often they're referred to >>> as "pretty urls". >>> >>> On 24 Gen, 17:55, Jonathan Lundell wrote: >>> On Jan 24, 2010, at 8:30 AM, mdipierro wrote: >>> > I will take a patch. ;-) >>> I'll contribute one. Any objection to changing the name to "slugify", since it's not really urlifying its input? >>> > On Jan 23, 7:03 pm, Jonathan Lundell wrote: >> urlify needs a comment to say explicitly what its intention is. That's >> partly because it suppresses quite a few characters that are normally >> legal in URLs, which is confusing. >>> >> Also, >>> >>> def urlify(s, max_length=80): >>> s = s.lower() >>> # string normalization, eg è => e, ñ => n >>> s = unicodedata.normalize('NFKD', >>> s.decode('utf-8')).encode('ASCII', 'ignore') >>> # strip entities >>> s = re.sub('&\w+;', '', s) >>> >> this should be '&\w+?;' (that is, non-greedy). Otherwise, a string like >> '&whatever&' will be completely eliminated. >>> >>> # strip everything but letters, numbers, dashes and spaces >>> s = re.sub('[^a-z0-9\-\s]', '', s) >>> # replace spaces with dashes >>> s = s.replace(' ', '-') >>> # strip multiple contiguous dashes >>> s = re.sub('-{2,}', '-', s) >>> # strip dashes at the beginning and end of the string >>> s = s.strip('-') >>> # ensure the maximum length >>> s = s[:max_length-1] >>> return s >>> >> (Stylistically, I think it'd be more readable if the comments were >> appended to the relevant code lines.) >>> > -- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To post to this group, send email to web...@googlegroups.com. > To unsubscribe from this group, send email to > web2py+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/web2py?hl=en. >>> >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "web2py-users" group. >> To post to this group, send email to web...@googlegroups.com. >> To unsubscribe from this group, send email to >> web2py+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/web2py?hl=en. >> > > > -- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To post to this group, send email to web...@googlegroups.com. > To unsubscribe from this group, send email to > web2py+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/web2py?hl=en. > > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: urlify
That's a good point. I also think the IS_SLUG should not do validation, just filtering. Or perhaps have an option to def IS_SLUG(): def __init__(check=False,error_message=): self.check=check self.error_message=error_message @staticmethod def slugify(value): ... def __call__(self,value): if check and not value==self.sugify(value): return (value,self.error_message) return (self.slugify(value),None) On Jan 24, 12:39 pm, Jonathan Lundell wrote: > On Jan 24, 2010, at 9:53 AM, mdipierro wrote: > > > I do not know about this. What do other people think? > > I do not have a strong opinion either way. > > I think that slug is a fairly common term. WordPress uses it, for example. > > And if we make it a validator (I'm about to submit a patch), it definitely > can't be IS_URL(). > > > > > On Jan 24, 11:34 am, pistacchio wrote: > >> I'm ok with slugify, but the reason i chose "urlify" is that slug is > >> not really a mvc term. It comes from the journalistic jargon and it's > >> been adopted by the original Django developers that were working on a > >> framework to build a newspaper site on. > > >> I don't think that "slug", outside the Django community, is a standard > >> term to name such url-friendly strings. More often they're referred to > >> as "pretty urls". > > >> On 24 Gen, 17:55, Jonathan Lundell wrote: > > >>> On Jan 24, 2010, at 8:30 AM, mdipierro wrote: > > I will take a patch. ;-) > > >>> I'll contribute one. Any objection to changing the name to "slugify", > >>> since it's not really urlifying its input? > > On Jan 23, 7:03 pm, Jonathan Lundell wrote: > > urlify needs a comment to say explicitly what its intention is. That's > > partly because it suppresses quite a few characters that are normally > > legal in URLs, which is confusing. > > > Also, > > >> def urlify(s, max_length=80): > >> s = s.lower() > >> # string normalization, eg è => e, ñ => n > >> s = unicodedata.normalize('NFKD', > >> s.decode('utf-8')).encode('ASCII', 'ignore') > >> # strip entities > >> s = re.sub('&\w+;', '', s) > > > this should be '&\w+?;' (that is, non-greedy). Otherwise, a string like > > '&whatever&' will be completely eliminated. > > >> # strip everything but letters, numbers, dashes and spaces > >> s = re.sub('[^a-z0-9\-\s]', '', s) > >> # replace spaces with dashes > >> s = s.replace(' ', '-') > >> # strip multiple contiguous dashes > >> s = re.sub('-{2,}', '-', s) > >> # strip dashes at the beginning and end of the string > >> s = s.strip('-') > >> # ensure the maximum length > >> s = s[:max_length-1] > >> return s > > > (Stylistically, I think it'd be more readable if the comments were > > appended to the relevant code lines.) > > -- > You received this message because you are subscribed to the Google > Groups "web2py-users" group. > To post to this group, send email to web...@googlegroups.com. > To unsubscribe from this group, send email to > web2py+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/web2py?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "web2py-users" group. > > To post to this group, send email to web...@googlegroups.com. > > To unsubscribe from this group, send email to > > web2py+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/web2py?hl=en. > > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
Re: [web2py] Re: urlify
On Jan 24, 2010, at 9:53 AM, mdipierro wrote: > I do not know about this. What do other people think? > I do not have a strong opinion either way. I think that slug is a fairly common term. WordPress uses it, for example. And if we make it a validator (I'm about to submit a patch), it definitely can't be IS_URL(). > > On Jan 24, 11:34 am, pistacchio wrote: >> I'm ok with slugify, but the reason i chose "urlify" is that slug is >> not really a mvc term. It comes from the journalistic jargon and it's >> been adopted by the original Django developers that were working on a >> framework to build a newspaper site on. >> >> I don't think that "slug", outside the Django community, is a standard >> term to name such url-friendly strings. More often they're referred to >> as "pretty urls". >> >> On 24 Gen, 17:55, Jonathan Lundell wrote: >> >>> On Jan 24, 2010, at 8:30 AM, mdipierro wrote: >> I will take a patch. ;-) >> >>> I'll contribute one. Any objection to changing the name to "slugify", since >>> it's not really urlifying its input? >> On Jan 23, 7:03 pm, Jonathan Lundell wrote: > urlify needs a comment to say explicitly what its intention is. That's > partly because it suppresses quite a few characters that are normally > legal in URLs, which is confusing. >> > Also, >> >> def urlify(s, max_length=80): >> s = s.lower() >> # string normalization, eg è => e, ñ => n >> s = unicodedata.normalize('NFKD', s.decode('utf-8')).encode('ASCII', >> 'ignore') >> # strip entities >> s = re.sub('&\w+;', '', s) >> > this should be '&\w+?;' (that is, non-greedy). Otherwise, a string like > '&whatever&' will be completely eliminated. >> >> # strip everything but letters, numbers, dashes and spaces >> s = re.sub('[^a-z0-9\-\s]', '', s) >> # replace spaces with dashes >> s = s.replace(' ', '-') >> # strip multiple contiguous dashes >> s = re.sub('-{2,}', '-', s) >> # strip dashes at the beginning and end of the string >> s = s.strip('-') >> # ensure the maximum length >> s = s[:max_length-1] >> return s >> > (Stylistically, I think it'd be more readable if the comments were > appended to the relevant code lines.) >> -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group athttp://groups.google.com/group/web2py?hl=en. >> >> > > -- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To post to this group, send email to web...@googlegroups.com. > To unsubscribe from this group, send email to > web2py+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/web2py?hl=en. > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: urlify
I do not know about this. What do other people think? I do not have a strong opinion either way. On Jan 24, 11:34 am, pistacchio wrote: > I'm ok with slugify, but the reason i chose "urlify" is that slug is > not really a mvc term. It comes from the journalistic jargon and it's > been adopted by the original Django developers that were working on a > framework to build a newspaper site on. > > I don't think that "slug", outside the Django community, is a standard > term to name such url-friendly strings. More often they're referred to > as "pretty urls". > > On 24 Gen, 17:55, Jonathan Lundell wrote: > > > On Jan 24, 2010, at 8:30 AM, mdipierro wrote: > > > > I will take a patch. ;-) > > > I'll contribute one. Any objection to changing the name to "slugify", since > > it's not really urlifying its input? > > > > On Jan 23, 7:03 pm, Jonathan Lundell wrote: > > >> urlify needs a comment to say explicitly what its intention is. That's > > >> partly because it suppresses quite a few characters that are normally > > >> legal in URLs, which is confusing. > > > >> Also, > > > >>> def urlify(s, max_length=80): > > >>> s = s.lower() > > >>> # string normalization, eg è => e, ñ => n > > >>> s = unicodedata.normalize('NFKD', > > >>> s.decode('utf-8')).encode('ASCII', 'ignore') > > >>> # strip entities > > >>> s = re.sub('&\w+;', '', s) > > > >> this should be '&\w+?;' (that is, non-greedy). Otherwise, a string like > > >> '&whatever&' will be completely eliminated. > > > >>> # strip everything but letters, numbers, dashes and spaces > > >>> s = re.sub('[^a-z0-9\-\s]', '', s) > > >>> # replace spaces with dashes > > >>> s = s.replace(' ', '-') > > >>> # strip multiple contiguous dashes > > >>> s = re.sub('-{2,}', '-', s) > > >>> # strip dashes at the beginning and end of the string > > >>> s = s.strip('-') > > >>> # ensure the maximum length > > >>> s = s[:max_length-1] > > >>> return s > > > >> (Stylistically, I think it'd be more readable if the comments were > > >> appended to the relevant code lines.) > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "web2py-users" group. > > > To post to this group, send email to web...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > web2py+unsubscr...@googlegroups.com. > > > For more options, visit this group > > > athttp://groups.google.com/group/web2py?hl=en. > > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: urlify
I'm ok with slugify, but the reason i chose "urlify" is that slug is not really a mvc term. It comes from the journalistic jargon and it's been adopted by the original Django developers that were working on a framework to build a newspaper site on. I don't think that "slug", outside the Django community, is a standard term to name such url-friendly strings. More often they're referred to as "pretty urls". On 24 Gen, 17:55, Jonathan Lundell wrote: > On Jan 24, 2010, at 8:30 AM, mdipierro wrote: > > > I will take a patch. ;-) > > I'll contribute one. Any objection to changing the name to "slugify", since > it's not really urlifying its input? > > > > On Jan 23, 7:03 pm, Jonathan Lundell wrote: > >> urlify needs a comment to say explicitly what its intention is. That's > >> partly because it suppresses quite a few characters that are normally > >> legal in URLs, which is confusing. > > >> Also, > > >>> def urlify(s, max_length=80): > >>> s = s.lower() > >>> # string normalization, eg è => e, ñ => n > >>> s = unicodedata.normalize('NFKD', s.decode('utf-8')).encode('ASCII', > >>> 'ignore') > >>> # strip entities > >>> s = re.sub('&\w+;', '', s) > > >> this should be '&\w+?;' (that is, non-greedy). Otherwise, a string like > >> '&whatever&' will be completely eliminated. > > >>> # strip everything but letters, numbers, dashes and spaces > >>> s = re.sub('[^a-z0-9\-\s]', '', s) > >>> # replace spaces with dashes > >>> s = s.replace(' ', '-') > >>> # strip multiple contiguous dashes > >>> s = re.sub('-{2,}', '-', s) > >>> # strip dashes at the beginning and end of the string > >>> s = s.strip('-') > >>> # ensure the maximum length > >>> s = s[:max_length-1] > >>> return s > > >> (Stylistically, I think it'd be more readable if the comments were > >> appended to the relevant code lines.) > > > -- > > You received this message because you are subscribed to the Google Groups > > "web2py-users" group. > > To post to this group, send email to web...@googlegroups.com. > > To unsubscribe from this group, send email to > > web2py+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/web2py?hl=en. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
Re: [web2py] Re: urlify
On Jan 24, 2010, at 9:14 AM, mdipierro wrote: > Since you are at it. We may want to consider a IS_SLUG validator and > make the function a staticmethod of IS_SLUG (instead of a function in > contrib) so it can be called without any import from contrib. OK. > > On Jan 24, 11:12 am, mdipierro wrote: >> No objection. It is not in stable it. >> >> On Jan 24, 10:55 am, Jonathan Lundell wrote: >> >>> On Jan 24, 2010, at 8:30 AM, mdipierro wrote: >> I will take a patch. ;-) >> >>> I'll contribute one. Any objection to changing the name to "slugify", since >>> it's not really urlifying its input? >> On Jan 23, 7:03 pm, Jonathan Lundell wrote: > urlify needs a comment to say explicitly what its intention is. That's > partly because it suppresses quite a few characters that are normally > legal in URLs, which is confusing. >> > Also, >> >> def urlify(s, max_length=80): >> s = s.lower() >> # string normalization, eg è => e, ñ => n >> s = unicodedata.normalize('NFKD', s.decode('utf-8')).encode('ASCII', >> 'ignore') >> # strip entities >> s = re.sub('&\w+;', '', s) >> > this should be '&\w+?;' (that is, non-greedy). Otherwise, a string like > '&whatever&' will be completely eliminated. >> >> # strip everything but letters, numbers, dashes and spaces >> s = re.sub('[^a-z0-9\-\s]', '', s) >> # replace spaces with dashes >> s = s.replace(' ', '-') >> # strip multiple contiguous dashes >> s = re.sub('-{2,}', '-', s) >> # strip dashes at the beginning and end of the string >> s = s.strip('-') >> # ensure the maximum length >> s = s[:max_length-1] >> return s >> > (Stylistically, I think it'd be more readable if the comments were > appended to the relevant code lines.) >> -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group athttp://groups.google.com/group/web2py?hl=en. >> >> > > -- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To post to this group, send email to web...@googlegroups.com. > To unsubscribe from this group, send email to > web2py+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/web2py?hl=en. > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: urlify
Since you are at it. We may want to consider a IS_SLUG validator and make the function a staticmethod of IS_SLUG (instead of a function in contrib) so it can be called without any import from contrib. On Jan 24, 11:12 am, mdipierro wrote: > No objection. It is not in stable it. > > On Jan 24, 10:55 am, Jonathan Lundell wrote: > > > On Jan 24, 2010, at 8:30 AM, mdipierro wrote: > > > > I will take a patch. ;-) > > > I'll contribute one. Any objection to changing the name to "slugify", since > > it's not really urlifying its input? > > > > On Jan 23, 7:03 pm, Jonathan Lundell wrote: > > >> urlify needs a comment to say explicitly what its intention is. That's > > >> partly because it suppresses quite a few characters that are normally > > >> legal in URLs, which is confusing. > > > >> Also, > > > >>> def urlify(s, max_length=80): > > >>> s = s.lower() > > >>> # string normalization, eg è => e, ñ => n > > >>> s = unicodedata.normalize('NFKD', > > >>> s.decode('utf-8')).encode('ASCII', 'ignore') > > >>> # strip entities > > >>> s = re.sub('&\w+;', '', s) > > > >> this should be '&\w+?;' (that is, non-greedy). Otherwise, a string like > > >> '&whatever&' will be completely eliminated. > > > >>> # strip everything but letters, numbers, dashes and spaces > > >>> s = re.sub('[^a-z0-9\-\s]', '', s) > > >>> # replace spaces with dashes > > >>> s = s.replace(' ', '-') > > >>> # strip multiple contiguous dashes > > >>> s = re.sub('-{2,}', '-', s) > > >>> # strip dashes at the beginning and end of the string > > >>> s = s.strip('-') > > >>> # ensure the maximum length > > >>> s = s[:max_length-1] > > >>> return s > > > >> (Stylistically, I think it'd be more readable if the comments were > > >> appended to the relevant code lines.) > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "web2py-users" group. > > > To post to this group, send email to web...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > web2py+unsubscr...@googlegroups.com. > > > For more options, visit this group > > > athttp://groups.google.com/group/web2py?hl=en. > > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: urlify
No objection. It is not in stable it. On Jan 24, 10:55 am, Jonathan Lundell wrote: > On Jan 24, 2010, at 8:30 AM, mdipierro wrote: > > > I will take a patch. ;-) > > I'll contribute one. Any objection to changing the name to "slugify", since > it's not really urlifying its input? > > > > > > > > > On Jan 23, 7:03 pm, Jonathan Lundell wrote: > >> urlify needs a comment to say explicitly what its intention is. That's > >> partly because it suppresses quite a few characters that are normally > >> legal in URLs, which is confusing. > > >> Also, > > >>> def urlify(s, max_length=80): > >>> s = s.lower() > >>> # string normalization, eg è => e, ñ => n > >>> s = unicodedata.normalize('NFKD', s.decode('utf-8')).encode('ASCII', > >>> 'ignore') > >>> # strip entities > >>> s = re.sub('&\w+;', '', s) > > >> this should be '&\w+?;' (that is, non-greedy). Otherwise, a string like > >> '&whatever&' will be completely eliminated. > > >>> # strip everything but letters, numbers, dashes and spaces > >>> s = re.sub('[^a-z0-9\-\s]', '', s) > >>> # replace spaces with dashes > >>> s = s.replace(' ', '-') > >>> # strip multiple contiguous dashes > >>> s = re.sub('-{2,}', '-', s) > >>> # strip dashes at the beginning and end of the string > >>> s = s.strip('-') > >>> # ensure the maximum length > >>> s = s[:max_length-1] > >>> return s > > >> (Stylistically, I think it'd be more readable if the comments were > >> appended to the relevant code lines.) > > > -- > > You received this message because you are subscribed to the Google Groups > > "web2py-users" group. > > To post to this group, send email to web...@googlegroups.com. > > To unsubscribe from this group, send email to > > web2py+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/web2py?hl=en. > > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
Re: [web2py] Re: urlify
On Jan 24, 2010, at 8:30 AM, mdipierro wrote: > I will take a patch. ;-) I'll contribute one. Any objection to changing the name to "slugify", since it's not really urlifying its input? > > On Jan 23, 7:03 pm, Jonathan Lundell wrote: >> urlify needs a comment to say explicitly what its intention is. That's >> partly because it suppresses quite a few characters that are normally legal >> in URLs, which is confusing. >> >> Also, >> >>> def urlify(s, max_length=80): >>> s = s.lower() >>> # string normalization, eg è => e, ñ => n >>> s = unicodedata.normalize('NFKD', s.decode('utf-8')).encode('ASCII', >>> 'ignore') >>> # strip entities >>> s = re.sub('&\w+;', '', s) >> >> this should be '&\w+?;' (that is, non-greedy). Otherwise, a string like >> '&whatever&' will be completely eliminated. >> >>> # strip everything but letters, numbers, dashes and spaces >>> s = re.sub('[^a-z0-9\-\s]', '', s) >>> # replace spaces with dashes >>> s = s.replace(' ', '-') >>> # strip multiple contiguous dashes >>> s = re.sub('-{2,}', '-', s) >>> # strip dashes at the beginning and end of the string >>> s = s.strip('-') >>> # ensure the maximum length >>> s = s[:max_length-1] >>> return s >> >> (Stylistically, I think it'd be more readable if the comments were appended >> to the relevant code lines.) > > -- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To post to this group, send email to web...@googlegroups.com. > To unsubscribe from this group, send email to > web2py+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/web2py?hl=en. > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: urlify
I will take a patch. ;-) On Jan 23, 7:03 pm, Jonathan Lundell wrote: > urlify needs a comment to say explicitly what its intention is. That's partly > because it suppresses quite a few characters that are normally legal in URLs, > which is confusing. > > Also, > > > def urlify(s, max_length=80): > > s = s.lower() > > # string normalization, eg è => e, ñ => n > > s = unicodedata.normalize('NFKD', s.decode('utf-8')).encode('ASCII', > > 'ignore') > > # strip entities > > s = re.sub('&\w+;', '', s) > > this should be '&\w+?;' (that is, non-greedy). Otherwise, a string like > '&whatever&' will be completely eliminated. > > > # strip everything but letters, numbers, dashes and spaces > > s = re.sub('[^a-z0-9\-\s]', '', s) > > # replace spaces with dashes > > s = s.replace(' ', '-') > > # strip multiple contiguous dashes > > s = re.sub('-{2,}', '-', s) > > # strip dashes at the beginning and end of the string > > s = s.strip('-') > > # ensure the maximum length > > s = s[:max_length-1] > > return s > > (Stylistically, I think it'd be more readable if the comments were appended > to the relevant code lines.) -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.