def post(self): template_values = UserAuth(self.request.uri).userTemplateVals() if template_values['user'] == '' or template_values['user'] is None: template = JINJA_ENVIRONMENT.get_template('templates/main.html') self.response.write(template.render(template_values)) else: action = self.request.get('button') if action.lower() == 'submit': first_name = self.request.get('first_name') last_name = self.request.get('last_name') user_profile = self.request.get('user_profile') userModel = UserModel() user_key = ndb.Key(UserModel, template_values['username']) userModel.key = user_key get_user = user_key.get() get_user.first_name = first_name get_user.last_name = last_name if len(user_profile) > 280: user_model = UserModel() user_key = ndb.Key(UserModel, template_values['username']) user_model.key = user_key get_user = user_key.get() template_values['userInfo'] = get_user template_values[ 'err_msg'] = 'Profile content can not be more than 280 characters' template = JINJA_ENVIRONMENT.get_template( 'templates/profile-edit.html') self.response.write(template.render(template_values)) else: get_user.user_profile = user_profile get_user.put() self.redirect('/profile')
def get(self): template_values = UserAuth(self.request.uri).userTemplateVals() if template_values['user'] == '' or template_values['user'] is None: template = JINJA_ENVIRONMENT.get_template('templates/main.html') self.response.write(template.render(template_values)) else: if template_values['username'] == '' or template_values['username'] is None: self.redirect('/register') else: self.redirect('/home')
def get(self): template_values = UserAuth(self.request.uri).userTemplateVals() if template_values['user'] == '' or template_values['user'] is None: template = JINJA_ENVIRONMENT.get_template('templates/main.html') self.response.write(template.render(template_values)) else: if template_values['username'] == '' or template_values['username'] is None: self.redirect('/register') else: template_values['tweets'] = self.getTweets(template_values['username']) template_values['upload_url'] = blobstore.create_upload_url('/upload') template = JINJA_ENVIRONMENT.get_template('templates/home.html') self.response.write(template.render(template_values))
def get(self): template_values = UserAuth(self.request.uri).userTemplateVals() if template_values['user'] == '' or template_values['user'] is None: template = JINJA_ENVIRONMENT.get_template('templates/main.html') self.response.write(template.render(template_values)) else: if template_values['username'] == '' or template_values['username'] is None: self.redirect('/register') else: tweet_id = int(self.request.get('id')) tweet_model = ndb.Key(TweetsModel, tweet_id) template_values['tweetData'] = tweet_model.get() template = JINJA_ENVIRONMENT.get_template('templates/tweet-edit.html') self.response.write(template.render(template_values))
def get(self): template_values = UserAuth(self.request.uri).userTemplateVals() if template_values['user'] == '' or template_values['user'] is None: template = JINJA_ENVIRONMENT.get_template('templates/main.html') self.response.write(template.render(template_values)) else: if template_values[ 'username'] == '' or template_values['username'] is None: self.redirect('/register') else: user_model = UserModel() user_key = ndb.Key(UserModel, template_values['username']) user_model.key = user_key get_user = user_key.get() template_values['userInfo'] = get_user template = JINJA_ENVIRONMENT.get_template( 'templates/profile-edit.html') self.response.write(template.render(template_values))
def post(self): template_values = UserAuth(self.request.uri).userTemplateVals() if template_values['user'] == '' or template_values['user'] is None: template = JINJA_ENVIRONMENT.get_template('templates/main.html') self.response.write(template.render(template_values)) else: action = self.request.get('button') if action.lower() == 'submit': err_msg = '' user_name = self.request.get('userName') first_name = self.request.get('first_name') last_name = self.request.get('last_name') user_profile = self.request.get('user_profile') if user_name == '' or user_name is None: err_msg = 'Username is required.' else: if template_values['username'] == '' or template_values[ 'username'] is None: userModel = UserModel() user_email = "%s" % (template_values['user']) user_key = ndb.Key(UserModel, user_name) userModel.key = user_key get_user = user_key.get() if get_user is None: userModel.email = user_email userModel.user_name = user_name userModel.first_name = first_name userModel.last_name = last_name if len(user_profile) > 280: err_msg = 'Profile content can not be more than 280 characters' else: userModel.user_profile = user_profile userModel.put() self.redirect('/') else: err_msg = 'This username is already existed.' else: err_msg = 'You can not change the user name.' template_values['err_msg'] = err_msg template = JINJA_ENVIRONMENT.get_template( 'templates/register.html') self.response.write(template.render(template_values))
def post(self): template_values = UserAuth(self.request.uri).userTemplateVals() if template_values['user'] == '' or template_values['user'] is None: template = JINJA_ENVIRONMENT.get_template('templates/main.html') self.response.write(template.render(template_values)) else: action = self.request.get('button') print(action) if action.lower() == 'submit': tweets_content = self.request.get('tweet_content') if len(tweets_content) > 280: err_msg = 'Content can not be more than 280 characters.' else: tweet_id = int(self.request.get('id')) tweet_key = ndb.Key(TweetsModel, tweet_id) get_tweet = tweet_key.get() get_tweet.tweet_content = tweets_content get_tweet.updated_date = datetime.now() get_tweet.put() self.redirect('/home')
def post(self): template_values = UserAuth(self.request.uri).userTemplateVals() if template_values['user'] == '' or template_values['user'] is None: template = JINJA_ENVIRONMENT.get_template('templates/main.html') self.response.write(template.render(template_values)) else: action = self.request.get('button') tweets_content = self.request.get('tweet_content') if action.lower() == 'tweet': tweets_content = self.request.get('tweet_content') if len(tweets_content) > 280: template_values['tweets_content'] = tweets_content template_values['tweets'] = self.getTweets(template_values['username']) template_values['err_msg'] = 'Content can not be more than 280 characters.' template = JINJA_ENVIRONMENT.get_template('templates/home.html') self.response.write(template.render(template_values)) else: tweets_model = TweetsModel() tweets_model.user_name = template_values['username'] tweets_model.tweet_content = tweets_content img_url = '' if len(self.get_uploads()) > 0: upload = self.get_uploads()[0] blobinfo = blobstore.BlobInfo(upload.key()) filename = blobinfo.filename tweets_model.tweet_image = upload.key() img_url = get_serving_url(upload.key()) tweets_model.tweet_image_url = get_serving_url(upload.key()) tweets_model.put() document = search.Document( fields = [ search.TextField('tweets_content', tweets_content), search.TextField('username', template_values['username']), search.TextField('image_url', img_url) ] ) index = search.Index('tweets') index.put(document) self.redirect('/home')
def post(self): template_values = UserAuth(self.request.uri).userTemplateVals() if template_values['user'] == '' or template_values['user'] is None: template = JINJA_ENVIRONMENT.get_template('templates/main.html') self.response.write(template.render(template_values)) else: action = self.request.get('button') if action.lower() == 'search': err_msg = '' content = self.request.get('content') if len(content) > 0: index = search.Index('tweets') query_string = "tweets_content: " + content query_options = search.QueryOptions(limit=50) query = search.Query(query_string=query_string, options=query_options) template_values['tweets'] = index.search(query) else: template_values['err_msg'] = 'Search Content is required.' print(template_values) template = JINJA_ENVIRONMENT.get_template( 'templates/search-content.html') self.response.write(template.render(template_values))
def post(self): template_values = UserAuth(self.request.uri).userTemplateVals() if template_values['user'] == '' or template_values['user'] is None: template = JINJA_ENVIRONMENT.get_template('templates/main.html') self.response.write(template.render(template_values)) else: action = self.request.get('button') if action.lower() == 'search': err_msg = '' user_name = self.request.get('userName') if len(user_name) > 0: template_values['search'] = user_name user_key = ndb.Key(UserModel, user_name) get_user = user_key.get() follow_info_key = ndb.Key(FollowInfoModel, user_name) get_follow_info = follow_info_key.get() tweet_model_query = TweetsModel.query( TweetsModel.user_name == user_name).order( -TweetsModel.updated_date) page_size = 50 template_values['tweets'] = tweet_model_query.fetch( page_size) if get_follow_info == '' or get_follow_info is None: template_values['following'] = False else: if template_values[ 'username'] in get_follow_info.followed_by: template_values['following'] = True else: template_values['following'] = False if get_user == '' or get_user is None: err_msg = 'User Not Found.' else: template_values['userInfo'] = get_user else: err_msg = 'Username is required.' template_values['err_msg'] = err_msg template = JINJA_ENVIRONMENT.get_template( 'templates/search-user.html') self.response.write(template.render(template_values)) elif action.lower() == 'follow': current_user = template_values['username'] search_user = self.request.get('userName') follow_to_info_key = ndb.Key(FollowInfoModel, current_user) get_follow_to_info = follow_to_info_key.get() follow_to_model = FollowInfoModel() follow_to_model.key = follow_to_info_key if get_follow_to_info == '' or get_follow_to_info is None: follow_to_model.followed_to = [search_user] follow_to_model.put() else: get_follow_to_info.followed_to.append( search_user ) if search_user not in get_follow_to_info.followed_to else get_follow_to_info.followed_to get_follow_to_info.put() follow_by_info_key = ndb.Key(FollowInfoModel, search_user) get_follow_by_info = follow_by_info_key.get() follow_by_model = FollowInfoModel() follow_by_model.key = follow_by_info_key if get_follow_by_info == '' or get_follow_by_info is None: follow_by_model.followed_by = [current_user] follow_by_model.put() else: get_follow_by_info.followed_by.append( current_user ) if current_user not in get_follow_by_info.followed_by else get_follow_by_info.followed_by get_follow_by_info.put() self.redirect('/home') elif action.lower() == 'unfollow': current_user = template_values['username'] search_user = self.request.get('userName') follow_to_info_key = ndb.Key(FollowInfoModel, current_user) get_followed_to = follow_to_info_key.get() get_followed_to.followed_to.remove(search_user) get_followed_to.put() follow_by_info_key = ndb.Key(FollowInfoModel, search_user) get_followed_by = follow_by_info_key.get() get_followed_by.followed_by.remove(current_user) get_followed_by.put() self.redirect('/home')