Filter labels by pattern
authorDmitriy Morozov <dmitriy@mrzv.org>
Tue, 31 Mar 2009 15:33:49 -0700
changeset 18 928560d49795
parent 17 eeafcec1814f
child 19 f929003d4af7
Filter labels by pattern
alexandria.py
--- a/alexandria.py	Wed Oct 15 10:22:29 2008 -0700
+++ b/alexandria.py	Tue Mar 31 15:33:49 2009 -0700
@@ -174,8 +174,14 @@
             t.delete()
     session.commit()
 
+    if len(args) == 0: 
+        pattern = u'*'
+    else:
+        pattern = unicode(args[0])
+    pattern = pattern.replace('*', '%')
+
     print "Labels:"
-    for t in Tag.query.order_by(asc(Tag.name)).all():
+    for t in Tag.query.filter(Tag.name.like(pattern)).order_by(asc(Tag.name)).all():
         if len(t.papers) == 0:                  # clean the database
             t.delete()
             continue