def delete_post(): if session.get('logged_in') is not None: accountDao = AccountDao() ownerMatched = accountDao.remove_account_post(session['logged_in'], request.form['postId']) if not ownerMatched: return redirect(url_for('PetCare.list_posts')) postDao = PostDao() prevImages = postDao.remove_post(request.form['postId']) for img in prevImages: ImageHandler.delete_image(img) return redirect(url_for('PetCare.list_posts'))
def make_post_info(userId, input, prevPost=None): postInfo = input.form.copy() if not Entities.attrNotNull(postInfo, [ 'name', 'species', 'gender', 'age', 'vaccination', 'start_date', 'end_date', 'criteria' ]): return False if not Entities.attrNotZeroLength(postInfo, ['name', 'species', 'vaccination']): return False postInfo['owner_id'] = userId postInfo['start_date'] = int( time.mktime(time.strptime(postInfo['start_date'], '%Y-%m-%d'))) postInfo['end_date'] = int( time.mktime(time.strptime(postInfo['end_date'], '%Y-%m-%d'))) postInfo['post_date'] = int(time.time()) for i in ['image1', 'image2', 'image3' ]: # FIXME: what strategy to be used for uploading pictures if i in input.files and len(input.files[i].filename) > 0: postInfo[i] = ImageHandler.save_image(input.files[i]) if prevPost is not None and i in prevPost: ImageHandler.delete_image(prevPost[i]) return postInfo