This repository was archived by the owner on Aug 29, 2023. It is now read-only.
File tree 4 files changed +35
-0
lines changed
4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change 184
184
# External apps
185
185
"django_tables2" ,
186
186
"selectable" ,
187
+ "patterns" ,
187
188
"locations" ,
188
189
# RapidSMS
189
190
"rapidsms" ,
You can’t perform that action at this time.
0 commit comments