OLD | NEW |
1 # coding=utf-8 | 1 # coding=utf-8 |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Status management pages.""" | 6 """Status management pages.""" |
7 | 7 |
8 import datetime | 8 import datetime |
9 import json | 9 import json |
10 import re | 10 import re |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 130 |
131 class Status(db.Model): | 131 class Status(db.Model): |
132 """Description for the status table.""" | 132 """Description for the status table.""" |
133 # The username who added this status. | 133 # The username who added this status. |
134 username = db.StringProperty(required=True) | 134 username = db.StringProperty(required=True) |
135 # The date when the status got added. | 135 # The date when the status got added. |
136 date = db.DateTimeProperty(auto_now_add=True) | 136 date = db.DateTimeProperty(auto_now_add=True) |
137 # The message. It can contain html code. | 137 # The message. It can contain html code. |
138 message = db.StringProperty(required=True) | 138 message = db.StringProperty(required=True) |
139 | 139 |
| 140 def __init__(self, *args, **kwargs): |
| 141 # Normalize newlines otherwise the DB store barfs. We don't really want to |
| 142 # make this field handle newlines as none of the places where we output the |
| 143 # content is designed to handle it, nor the clients that consume us. |
| 144 kwargs['message'] = kwargs.get('message', '').replace('\n', ' ') |
| 145 super(Status, self).__init__(*args, **kwargs) |
| 146 |
140 @property | 147 @property |
141 def username_links(self): | 148 def username_links(self): |
142 return LinkableText(self.username) | 149 return LinkableText(self.username) |
143 | 150 |
144 @property | 151 @property |
145 def message_links(self): | 152 def message_links(self): |
146 return LinkableText(self.message) | 153 return LinkableText(self.message) |
147 | 154 |
148 @property | 155 @property |
149 def general_state(self): | 156 def general_state(self): |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 else: | 414 else: |
408 put_status(Status(message=new_message, username=self.user.email())) | 415 put_status(Status(message=new_message, username=self.user.email())) |
409 self.redirect("/") | 416 self.redirect("/") |
410 | 417 |
411 | 418 |
412 def bootstrap(): | 419 def bootstrap(): |
413 # Guarantee that at least one instance exists. | 420 # Guarantee that at least one instance exists. |
414 if db.GqlQuery('SELECT __key__ FROM Status').get() is None: | 421 if db.GqlQuery('SELECT __key__ FROM Status').get() is None: |
415 Status(username='none', message='welcome to status').put() | 422 Status(username='none', message='welcome to status').put() |
416 LinkableText.bootstrap(BasePage.APP_NAME) | 423 LinkableText.bootstrap(BasePage.APP_NAME) |
OLD | NEW |