diff --git a/action/service.py b/action/service.py index 329b10c..aacc2d3 100644 --- a/action/service.py +++ b/action/service.py @@ -7,11 +7,6 @@ import models import settings import urllib - -try: - import json -except ImportError: - import simplejson as json class Article(Action): def _captcha_validation(self, challenge, response): @@ -37,10 +32,7 @@ def post(self, category_name): @login_required def put(self): - unqouted = urllib.unquote_plus(self.request.body).decode('utf8') - if unqouted[-1:] != '}': - unqouted = unqouted[:-1] - params = json.loads(unqouted) + params = self.get_json_payload() article_id = int(params['id']) article = models.Article.get_by_id(article_id) if article.author.user != users.get_current_user(): @@ -83,6 +75,9 @@ def get(self, article_id): self.article = models.Article.get_by_id(article_id) if not self.is_ajax and not self.is_crawler: + if not self.article: + self.response.set_status(404) + return self.redirect('/#!/%s/%d' % (urllib.quote(self.article.category.name.encode('utf8')), article_id)) if self.article: diff --git a/action/user.py b/action/user.py index e782125..8b3242d 100644 --- a/action/user.py +++ b/action/user.py @@ -2,10 +2,6 @@ from lib.controller import Action from lib.decorators import login_required from models import User, UserNicknameHistory -try: - import json -except ImportError: - import simplejson as json class Index(Action): def get(self, user_id=None): @@ -19,7 +15,7 @@ def get(self, user_id=None): @login_required def put(self): - params = json.loads(self.request.body) + params = self.get_json_payload() me = User.get_current() self.user = me if me.nickname == params['nickname']: diff --git a/bootstrap.pyc b/bootstrap.pyc deleted file mode 100644 index bafb2a1..0000000 Binary files a/bootstrap.pyc and /dev/null differ diff --git a/lib/controller.py b/lib/controller.py index baed67e..77ebd68 100644 --- a/lib/controller.py +++ b/lib/controller.py @@ -295,7 +295,13 @@ def _get_context(self): self.__context['request'] = self.request self.__context['response'] = self.response self.__context['app'] = app_identity - return self.__context + return self.__context + + def get_json_payload(self): + unqouted = urllib.unquote_plus(self.request.body).decode('utf8') + if unqouted[-1:] != '}': + unqouted = unqouted[:-1] + return json.loads(unqouted) class Result(object): DEFAULT = '' diff --git a/models.py b/models.py index 443846b..4489653 100644 --- a/models.py +++ b/models.py @@ -29,7 +29,7 @@ class User(db.Model): email_hash = db.StringProperty() def nickname_exists(self, nickname): - return User.gql('WHERE user != :1 AND nickname = :2', self, nickname).get() != None + return User.gql('WHERE user != :1 AND nickname = :2', self.user, nickname).get() != None def change_nickname(self, nickname): db.run_in_transaction_options(xg_on, UserNicknameHistory(user=self, nickname=bleach.clean(self.nickname)).put) diff --git a/models.pyc b/models.pyc deleted file mode 100644 index 0d5760f..0000000 Binary files a/models.pyc and /dev/null differ diff --git a/settings.pyc b/settings.pyc deleted file mode 100644 index b271ef8..0000000 Binary files a/settings.pyc and /dev/null differ diff --git a/static/js/service.js b/static/js/service.js index 58a3965..14f0681 100644 --- a/static/js/service.js +++ b/static/js/service.js @@ -1053,7 +1053,7 @@ var initializeModels = function() { $.ajax({ type: "PUT", url: "/user/me", - data: JSON.stringify(json), + data: encodeURIComponent(JSON.stringify(json)), cache: false, success: function(data) { self.changed(data.user); diff --git a/templates/about.html b/templates/about.html index d09f596..af30928 100644 --- a/templates/about.html +++ b/templates/about.html @@ -24,9 +24,8 @@