Commits

Blue committed 552f838

Most minor update, plus a start of real search functionality.

Comments (0)

Files changed (2)

+from django import forms
+from django.utils.translation import ugettext_lazy as _
+import settings
+from models import Post
+
+
+category_choices = [(k, v.capitalize()) for k, v in settings.CATEGORY_MAPPING.iteritems()]
+category_choices.sort()
+category_choices.append(('uncat',  _('Uncategorized')))
+category_choices.append(('invalid', _('Invalid')))
+category_choices.insert(0, ('all', _('All')))
+
+
+class SearchForm(forms.Form):
+    query = forms.CharField()
+    category = forms.ChoiceField(choices=category_choices, initial=99)
+
+    def search(self):
+        assert self.is_valid()
+        data = self.cleaned_data
+        # query
+        posts = Post.objects.filter(title__contains=data['query'])
+        # category
+        cat = data['category']
+        if cat != 'all':
+            if cat == 'uncat':
+                posts = posts.filter(category__isnull=True)
+            elif cat == 'invalid':
+                posts = posts.exclude(category__in=spotnet.settings.CATEGORY_MAPPING.keys())
+            else:
+                posts = posts.filter(category=cat)
+        # done!
+        return posts

spotnet/management/commands/update_spotnet.py

                 conn.update_group(args[0], self.logger_function, start, stop, overwrite)
             else:
                 raise CommandError("Invalid number of arguments")
-            print 'Finished'
+            self.stdout.write('Finished')
         except KeyboardInterrupt:
-            print '\nStopped'
+            self.stdout.write('\nStopped')
         finally:
             conn.disconnect()