def add_post(user, title, quote, user_anonymous, provider, url, image): if quote is not None: if len(quote) > 500: quote = quote[:500] if title is not None: if len(title) > 75: title = title[:75] if url is not None: uri = url.strip() parsed_uri = urlparse(uri) if uri and (not parsed_uri.scheme or not parsed_uri.netloc): return False else: if len(title) != 0 and title is not None: quote_id = modals.add_quote(title1=title, user_id=user, user_anon=user_anonymous, provider=provider, quote1=quote, url1=url) if quote_id is not None: modals.set_vote(long(quote_id), user, 1, provider=provider) return True else: return False else: return False else: if len(title) != 0 and title is not None: quote_id = modals.add_quote(title1=title, user_id=user, provider=provider, quote1=quote, url1=url, user_anon=user_anonymous) if quote_id is not None: modals.set_vote(long(quote_id), user, 1, provider=provider) return True else: return False else: return False
def post(self): if self.logged_in: user = self.current_user title = self.request.get('title') if str(self.request.get('anon')) == "on": anon = False else: anon = True text = self.request.get('quote').strip() if len(text) > 500: text = text[:500] if len(title) > 75: title = title[:75] uri = self.request.get('url').strip() parsed_uri = urlparse(uri) if uri and (not parsed_uri.scheme or not parsed_uri.netloc): template_values = { 'user': user, 'title': title, 'text': text, 'uri': uri, 'error_msg': 'The supplied link is not a valid absolute URI' } self.render('add_quote_error.html', template_values) else: image = self.get_uploads('image') type = image[0].content_type if image and type.startswith('image/') and len(title) != 0: blob_info = image[0] image = blob_info.key() quote_id = modals.add_quote(title1=title, user_id=user, user_anon=anon, provider=user.provider, quote1=text, url1=uri, image=image) if quote_id is not None: modals.set_vote(long(quote_id), user, 1, provider=user.provider) self.redirect('/') else: template_values = { 'user': user, 'title': title, 'text': text, 'uri': uri, 'error_msg': 'An error occured while adding this quote, please try again.' } self.render('add_quote_error.html', template_values) else: blob_info = image[0] image = blob_info.key() blobstore.delete(image) self.redirect('/') else: self.response.set_status(403, 'Forbidden') return
def post(self): user = users.get_current_user() title = self.request.get('title') text = self.request.get('quote').strip() if len(text) > 500: text = text[:500] if len(title) > 75: title = title[:75] uri = self.request.get('url').strip() parsed_uri = urlparse(uri) if uri and (not parsed_uri.scheme or not parsed_uri.netloc): template_values = { 'loggedin': user, 'title': title, 'text': text, 'uri': uri, 'error_msg': 'The supplied link is not a valid absolute URI' } template = jinja_environment.get_template('templates/add_quote_error.html') self.response.out.write(template.render(template_values)) else: image = self.get_uploads('image') type = image[0].content_type if image and type.startswith('image/') and len(title) != 0: blob_info = image[0] image = blob_info.key() quote_id = modals.add_quote(title, user, text, url1=uri, image=image) if quote_id is not None: modals.set_vote(long(quote_id), user, 1) self.redirect('/') else: template_values = { 'loggedin': user, 'title': title, 'text': text, 'uri': uri, 'error_msg': 'An error occured while adding this quote, please try again.' } template = jinja_environment.get_template('templates/add_quote_error.html') self.response.out.write(template.render(template_values)) else: blob_info = image[0] image = blob_info.key() blobstore.delete(image) self.redirect('/')
def post(self): user = users.get_current_user() title = self.request.get('title') text = self.request.get('quote').strip() if len(text) > 500: text = text[:500] if len(title) > 75: title = title[:75] uri = self.request.get('url').strip() parsed_uri = urlparse(uri) if uri and (not parsed_uri.scheme or not parsed_uri.netloc): template_values = { 'loggedin': user, 'title': title, 'text': text, 'uri': uri, 'error_msg': 'The supplied link is not a valid absolute URI' } template = jinja_environment.get_template('templates/add_quote_error.html') self.response.out.write(template.render(template_values)) else: if len(title) != 0 and title is not None: quote_id = modals.add_quote(title, user, text, url1=uri) if quote_id is not None: modals.set_vote(long(quote_id), user, 1) self.redirect('/') else: template_values = { 'loggedin': user, 'title': title, 'text': text, 'uri': uri, 'error_msg': 'An error occured while adding this quote, please try again.' } template = jinja_environment.get_template('templates/add_quote_error.html') self.response.out.write(template.render(template_values)) else: template_values = { 'loggedin': user, 'title': title, 'text': text, 'uri': uri, 'error_msg': 'An error occured while adding this quote, please try again. you forgot to enter title.' } template = jinja_environment.get_template('templates/add_quote_error.html') self.response.out.write(template.render(template_values))