def update_card(cardId): if request.method == 'POST' and request.is_json: CONTENT = request.get_json() if len(CONTENT) is not 0: classCard, _ = Card.get_card_by_id(cardId) attachments = CONTENT.get('attachments') if attachments is not None and attachments['assigned'] is not None: updatedCard = classCard.assign_attachment_file( attachments['assigned']) print("WE GOT SOMETINH", attachments['assigned']) return jsonify(updatedCard) updatedFields = dict( filter(lambda pair: pair[0] is not 'labels', CONTENT.items())) if CONTENT.get('labels') is not None: classCard.add_label(CONTENT.get('labels')) else: updatedCardId = classCard.update_card(updatedFields) _, updatedCardCursor = Card.get_card_by_id(cardId) return jsonify(updatedCardCursor)
def add_comment_to_card(cardId): if request.method == 'POST' and request.is_json: CONTENT = request.get_json() description = CONTENT.get("description") user = User.get_user_by_email(session['email']) userId = user.get("_id") boardId = CONTENT.get("boardId") commentId = Comment(description=description, authorId=userId, forCard=cardId).save() logId = Log(userId=userId, boardId=boardId).for_comment(cardId=cardId, body=description, commentId=commentId) log = Log.get_by_id(logId) cursorComment, _ = Comment.get_by_id(commentId) classCard, _ = Card.get_card_by_id(cardId) classCard.add_comment(cursorComment.get('_id')) User(**user).add_comment(commentId) return jsonify(logo=log, comment=cursorComment)
def add_attachment_to_card(cardId): image_file = request.files['attachment'] contentType = image_file.content_type fileName = image_file.filename classCard, _ = Card.get_card_by_id(cardId) updatedCard, newImageId = classCard.add_attachment(image_file, contentType, fileName) fsClass = FS.get(newImageId) imageStr = Utils.prepareImage(fsClass) imgAssigned = updatedCard['attachments']['assigned'] if imgAssigned == newImageId: assignedImage = True else: assignedImage = False responseSchema = { '_id': updatedCard['_id'], 'forList': updatedCard['forList'], 'boardId': updatedCard['boardId'], 'attachments': { 'file_id': newImageId, 'image': imageStr, 'assigned': assignedImage, 'filename': fsClass.filename, 'uploadDate': fsClass.uploadDate } } return jsonify(responseSchema)
def remove_comment(cardId, commentId): _, classComment = Comment.get_by_id(commentId) result = classComment.delete_comment(commentId) if result: cardClass, _ = Card.get_card_by_id(cardId) cardClass.remove_comment(commentId) return result
def get_comments_for_card(cardId): try: _, _ = Card.get_card_by_id(cardId) except CardError.CardError as error: jsonify(error=error.message) commentsList = Comment.get_comments_for_card(cardId) return jsonify(commentsList)
def delete_attachment_from_card(cardId): if request.method == 'DELETE' and request.is_json: CONTENT = request.get_json() fileId = CONTENT.get('file') classCard, _ = Card.get_card_by_id(cardId) deletedFile = classCard.delete_attachment(fileId) return jsonify(deletedFile)
def remove_checklist(checkListId): classCheckList = Checklist.get_by_id(checkListId) cardId = classCheckList.dict_from_class()['cardId'] classCard, _ = Card.get_card_by_id(cardId) classCard.remove_checklist(checkListId) isRemoved = classCheckList.remove_self() if isRemoved == checkListId: return jsonify(isRemoved) return "We dont remove this one "
def create_checklist(cardId): if request.method == 'POST' and request.is_json: CONTENT = request.get_json() classCard, _ = Card.get_card_by_id(cardId) justCreatedChecklist = classCard.add_checklist({ 'authorId': session['email'], 'cardId': cardId, **CONTENT.get('checklists') }) return jsonify(justCreatedChecklist)
def create_card(listId): if request.method == 'POST' and request.is_json: CONTENT = request.get_json() title = CONTENT.get('title') forList = CONTENT.get('forList') if CONTENT.get( 'forList') is not None else listId _id = CONTENT.get('_id') if CONTENT.get('_id') is not None else None boardId = CONTENT.get('boardId') try: _, classList = List.get_list_by_id(listId) except ListErrors.ListErrors as error: return jsonify(error=error.message) cardId = Card(title=title, forList=forList, _id=_id, boardId=boardId).save() classList.save_card_for_list(listId) _, cursorCard = Card.get_card_by_id(cardId) return jsonify(cursorCard)
def get_attachments_for_card(cardId): _, cursrosCard = Card.get_card_by_id(cardId) cardsWithImages = Card.get_attachment_in_string(cursrosCard) return jsonify(cardsWithImages)