Re: [Django] #28805: Provide a new database function for RegexpReplace

2017-11-16 Thread Django
#28805: Provide a new database function for RegexpReplace
-+-
 Reporter:  Joey Wilhelm |Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Joey Wilhelm):

 Yeah, I was debating the thought of creating some sort of `django-
 postgres-regex` package, for this and related functions. But if I could
 contribute it to core, why not, ya know?

 The implementation relatively easy; I based it off, I believe, Substr.

 {{{#!python
 from django.db.models import Func, Value


 class RegexpReplace(Func):
 function = 'REGEXP_REPLACE'

 def __init__(self, expression, pattern, replacement, **extra):
 if not hasattr(pattern, 'resolve_expression'):
 if not isinstance(pattern, str):
 raise TypeError("'pattern' must be a string")
 pattern = Value(pattern)
 if not hasattr(replacement, 'resolve_expression'):
 if not isinstance(replacement, str):
 raise TypeError("'replacement' must be a string")
 replacement = Value(replacement)
 expressions = [expression, pattern, replacement]
 super().__init__(*expressions, **extra)
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.a376fab4a68e84574be2491468c424be%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28805: Provide a new database function for RegexpReplace

2017-11-16 Thread Django
#28805: Provide a new database function for RegexpReplace
-+-
 Reporter:  Joey Wilhelm |Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Matthew Schinckel):

 Oh, it is worth pointing out that this is something that should be easy to
 package up in a reusable manner, since it (probably) won't require any
 changes, just the addition of a new class.

 That class could then be imported from anywhere.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.7266ecc7eee5c8d938bbed4a87e90c74%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28805: Provide a new database function for RegexpReplace

2017-11-16 Thread Django
#28805: Provide a new database function for RegexpReplace
-+-
 Reporter:  Joey Wilhelm |Owner:  nobody
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Matthew Schinckel):

 Personally, I'd create it in the {{{django.contrib.postgres}}} section:
 there are already other functions in there that you should be able to look
 at how they are written.

 The other alternative is to put it in
 {{{django.db.models.functions.text}}}, but I'm not sure how to flag that
 it only works on specific backends there.

 You might want to bring this up on the django-developers list, as that
 sometimes gets a bit more notice.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.eb20ef89c5eb3ba1e085f3bdda79b2ad%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


[Django] #28805: Provide a new database function for RegexpReplace

2017-11-16 Thread Django
#28805: Provide a new database function for RegexpReplace
-+-
   Reporter:  Joey   |  Owner:  nobody
  Wilhelm|
   Type:  New| Status:  new
  feature|
  Component:  Database   |Version:  master
  layer (models, ORM)|
   Severity:  Normal |   Keywords:
   Triage Stage: |  Has patch:  0
  Unreviewed |
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+-
 I've created a database function in my own project to utilize
 `REGEXP_REPLACE`, and wanted to contribute it upstream. At a quick glance,
 it appears that this is only available on PostgreSQL and Oracle. So my
 main question would be, which route would be preferable for inclusion?
 Should this be added to the PostgreSQL-specific code and let Oracle
 languish, or would this require the addition of a new feature flag on
 database backends?

 With the former implementation, I have code ready to go. The latter, I
 would definitely want some guidance.

 This is of course all assuming that this feature is desired.

 Here is an example usage:


 {{{#!python
 MyModel.objects.annotate(no_letters=RegexpReplace(F('name'), r'[A-Za-z]+',
 ''))
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/054.26165c576b602ebce864eedbb09ccb43%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.