Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit 81b45b2

Browse files
committed
enabled the patterns app
1 parent 2cf8b88 commit 81b45b2

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

patterns/__init__.py

Whitespace-only changes.

patterns/admin.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
# vim: ai ts=4 sts=4 et sw=4
3+
4+
from django.contrib import admin
5+
from patterns.models import *
6+
7+
class PatternAdmin(admin.ModelAdmin):
8+
list_display = ['name', 'regex']
9+
10+
admin.site.register(Pattern, PatternAdmin)

patterns/models.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
# vim: ai ts=4 sts=4 et sw=4
3+
4+
5+
from django.db import models
6+
7+
8+
class Pattern(models.Model):
9+
name = models.CharField(max_length=160)
10+
regex = models.CharField(max_length=160)
11+
12+
@staticmethod
13+
def join(patterns):
14+
'''Joins a set of passed in patterns, assumed to be the result of a
15+
ManyToMany field foreign key from some other object'''
16+
# fix any patterns we just or-ed together so they are the kind of or we want
17+
# e.g., (\w+)|(\d+) => (\w+|\d+)
18+
# TODO figure out how to handle non-captured matches
19+
# e.g., (?:\w+)|(\d+) => (?:\w+)|(\d+) and then zip up tokens correctly
20+
regex = '|'.join(patterns.values_list('regex', flat=True))
21+
return regex.replace(')|(', '|')
22+
23+
def __unicode__(self):
24+
return "%s %s" % (self.name, self.regex)

unicefng/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
# External apps
185185
"django_tables2",
186186
"selectable",
187+
"patterns",
187188
"locations",
188189
# RapidSMS
189190
"rapidsms",

0 commit comments

Comments
 (0)