From 98bd839b488c658b57d038b9a693f84b63338a82 Mon Sep 17 00:00:00 2001 From: Andrei Bocan Date: Thu, 18 Sep 2008 02:47:10 +0300 Subject: [PATCH] Unique tags. Utf no uniq ? The hell is wrong with you people ? =/ --- doeet.py | 22 ++++++++++++++++++++-- index.yaml | 10 +++++++++- templates/index.html | 6 +++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/doeet.py b/doeet.py index 71a0fa0..4d92ef7 100644 --- a/doeet.py +++ b/doeet.py @@ -71,10 +71,18 @@ def post(self): todo.author = users.get_current_user() todo.content = self.request.get('content') - todo.tags = [tag.strip() for tag in self.request.get('tags').split(',')] + todo.tags = self._get_tags(self.request.get('tags')) todo.put() self.redirect('/') + def _get_tags(self, tag_string): + tags = [] + for tag in tag_string.split(','): + tag = tag.strip() + if not tag in tags: + tags.append(tag) + return tags + class GetTodo(webapp.RequestHandler): def get(self, id): todo = Todo.get(id) @@ -97,12 +105,22 @@ def put(self, id): self.response.out.write(todo.toJson()) +class TodosByTag(webapp.RequestHandler): + def get(self, tag): + user = users.get_current_user() + path = os.path.join(os.path.dirname(__file__), 'templates', 'index.html') + + todos = db.Query(Todo).filter('author =', user).filter('tags = ',tag).order('date_done').order('date_added') + self.response.out.write(template.render(path, { 'login_link': users.create_login_url('/'), 'user': user, 'todos': todos })) + + application = webapp.WSGIApplication([ ('/', MainPage), ('/todos', NewTodo), ('/todos/([^/]*)', GetTodo), ('/todos/([^/]*)/done', DoneTodo), - ('/todos/([^/]*)/reopen', ReopenTodo) + ('/todos/([^/]*)/reopen', ReopenTodo), + ('/tags/([^/]*)', TodosByTag) ], debug=True) diff --git a/index.yaml b/index.yaml index b2cac1f..ec3be36 100644 --- a/index.yaml +++ b/index.yaml @@ -16,9 +16,17 @@ indexes: - name: date direction: desc -# Used 2 times in query history. +# Used 12 times in query history. - kind: Todo properties: - name: author - name: date_done - name: date_added + +# Used 3 times in query history. +- kind: Todo + properties: + - name: author + - name: tags + - name: date_done + - name: date_added diff --git a/templates/index.html b/templates/index.html index 085cc2c..70d0cb9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,9 +1,9 @@ Do Eet ! - - - + + +