def action(self): self.notify_checklist_incomplete = 'Ran' logging.debug(self.last_actor) hook = Webhook.get(model_id=self.card_data['idBoard']) card = TrelloCard.get(idCard=self.card_data['id']) logging.debug(hook.user) unarchived = unarchive_card(self.card_data['id'], hook.user) if unarchived == True: if len(self.card_data['idMembers']) == 0: trello_user = TrelloUserInfo.get(trello_id=card.idMemberCreator) send_email('*****@*****.**', """ Hello, A card has been archived that has an incomplete checklist. It has been unarchived. Please take a moment to look into this matter. %s Thanks! The Nebri Support Team This email should have been sent to %s. """ % (self.card_data['shortUrl'], trello_user.username), "An Incomplete Card has been Archived") else: for member in self.card_data['idMembers']: trello_user = TrelloUserInfo.get(trello_id=member) send_email('*****@*****.**', """ Hello, A card has been archived that has an incomplete checklist. It has been unarchived. Please take a moment to look into this matter. %s Thanks! The Nebri Support Team This email should have been sent to %s. """ % (self.card_data['shortUrl'], trello_user.username), "An Incomplete Card has been Archived") else: send_email('*****@*****.**', """ An error occurred... %s """ % unarchived, "An Error Occurred during Archiving")
def action(self): self.handle_unapproved_archived = 'Ran' hook = Webhook.get(model_id=self.card_data['idBoard']) try: card = TrelloCard.get(idCard=self.card_data['id'], user=self.default_user) except Process.DoesNotExist: return unarchived = unarchive_card(self.card_data['id'], hook.user) if unarchived == True: trello_user = TrelloUserInfo.get(trello_id=card.idMemberCreator) send_email('*****@*****.**', """ Hello, A card has been archived which was not approved by a board admin. It has been unarchived. Please take a moment to look into this matter. %s Thanks! The Nebri Support Team Team This email should have been sent to %s. """ % (self.card_data['shortUrl'], trello_user.username), "An Unapproved Card has been Archived") else: send_email('*****@*****.**', """ An error occurred... %s """ % unarchived, "An Error Occurred during Archiving")
def callback(request): logging.debug('webhook received!') logging.debug('what in the world') try: webhook = Webhook.get(model_id=request.GET['id']) except Exception as e: logging.info('ERROR: %s' % (str(e))) user = request.GET['user'] client = get_client(user) logging.debug(client) comment_data = None card_json = None if request.BODY == '': # this is a test webhook for setup. return ok. return '200 OK' if 'card' in request.BODY['action']['data']: logging.debug('update or create card!') card_json = client.fetch_json('cards/%s?checklists=all&' % request.BODY['action']['data']['card']['id']) try: card, new = card_json_to_model(card_json, user) logging.debug(card.idMemberCreator) if card.idMemberCreator is None or card.idMemberCreator is False: card_creator = get_card_creator(card.idCard, client) card.idMemberCreator = card_creator card.save() except Exception as e: logging.debug(str(e)) comment_data = client.fetch_json('cards/%s?actions=commentCard' % request.BODY['action']['data']['card']['id']) logging.debug(comment_data) board_admins = [admin.get('username') for admin in client.fetch_json('boards/%s/members/admins' % request.BODY['action']['data']['board']['id']) if admin.get('username')] logging.debug(board_admins) p = Process.objects.create() p.hook_data = request.BODY p.card_data = card_json p.comment_data = comment_data p.board_admins = board_admins p.handle_trello_webhook = True p.default_user = user p.save() logging.debug(p) return '200 OK'