def create(): """ Create a post. """ random_token = None if app.config['USE_RANDOM_TOKEN']: # Check if client defined a random token, if not generate one if 'post[random_token]' in request.form: random_token = request.form['post[random_token]'] else: random_token = helpers.generate_token( app.config['RANDOM_TOKEN_LENGTH']) # Create burn after date based off client paramters or generate one today = datetime.today() if 'post[seconds_until_burn]' in request.form: burn_after = timedelta(seconds=int(request.form['post[seconds_until_burn]'])) + \ today else: burn_after = timedelta(seconds=app.config['POST_LIFETIME_MAX']) + \ today # Set the privly application, use "PlainPost" as default privly_application = "PlainPost" if 'post[privly_application]' in request.form: privly_application = request.form['post[privly_application]'] # Set the content of the post content, structured = (None, None) if 'post[content]' in request.form: content = request.form['post[content]'] if 'post[structured_content]' in request.form: structured = request.form['post[structured_content]'] # Create the Post post = Post( random_id=helpers.generate_token(app.config['RANDOM_ID_LENGTH']), random_token=random_token, content=content, structured_content=structured, burn_after=burn_after, privly_application=privly_application, public=True, user=user ) post.save() # Create JSON response response = helpers.jsonify(status='created', location=post, _status=201) response.headers['X-Privly-Url'] = helpers.privly_URL(post) return response
def get_posts(): """ Get all a user's posts """ posts = [] for post in user.posts: # Get the JSON for the post data = post.__json__() # Add the privly_URL to the post JSON data['privly_URL'] = helpers.privly_URL(post) posts.append(data) return helpers.jsonify(posts)
def get_posts(): """ Get all a user's posts """ posts = [] for post in user.posts: # Get the JSON for the post data = post.__json__() # Add the privly_URL to the post JSON data['privly_URL'] = helpers.privly_URL(post) posts.append(data) return helpers.jsonify(posts)
def create(): """ Create a post. """ random_token = None if app.config['USE_RANDOM_TOKEN']: # Check if client defined a random token, if not generate one if 'post[random_token]' in request.form: random_token = request.form['post[random_token]'] else: random_token = helpers.generate_token( app.config['RANDOM_TOKEN_LENGTH']) # Create burn after date based off client paramters or generate one today = datetime.today() if 'post[seconds_until_burn]' in request.form: burn_after = timedelta(seconds=int(request.form['post[seconds_until_burn]'])) + \ today else: burn_after = timedelta(seconds=app.config['POST_LIFETIME_MAX']) + \ today # Set the privly application, use "PlainPost" as default privly_application = "PlainPost" if 'post[privly_application]' in request.form: privly_application = request.form['post[privly_application]'] # Set the content of the post content, structured = (None, None) if 'post[content]' in request.form: content = request.form['post[content]'] if 'post[structured_content]' in request.form: structured = request.form['post[structured_content]'] # Create the Post post = Post(random_id=helpers.generate_token( app.config['RANDOM_ID_LENGTH']), random_token=random_token, content=content, structured_content=structured, burn_after=burn_after, privly_application=privly_application, public=True, user=user) post.save() # Create JSON response response = helpers.jsonify(status='created', location=post, _status=201) response.headers['X-Privly-Url'] = helpers.privly_URL(post) return response